예제 #1
0
 def run(self):
     self.start_async()
     while self.state.running:
         try:
             time.sleep(1)
             if self._config_hash != hash(str(Configuration().get())):
                 LOG.debug('Config has changed, reloading...')
                 self.reload()
         except KeyboardInterrupt as e:
             LOG.error(e)
             self.stop()
             raise  # Re-raise KeyboardInterrupt
예제 #2
0
def report_metric(name, data):
    """
    Report a general metric to the OwO servers

    Args:
        name (str): Name of metric. Must use only letters and hyphens
        data (dict): JSON dictionary to report. Must be valid JSON
    """
    try:
        if is_paired() and Configuration().get()['opt_in']:
            DeviceApi().report_metric(name, data)
    except requests.RequestException as e:
        LOG.error(
            'Metric couldn\'t be uploaded, due to a network error ({})'.format(
                e))
예제 #3
0
 def __init__(self, url=None, enabled=False):
     conf = Configuration().get()['server']
     self.url = url or conf['url']
     self.enabled = enabled or conf['metrics']