31 Report a general metric to the Mycroft servers 34 name (str): Name of metric. Must use only letters and hyphens 35 data (dict): JSON dictionary to report. Must be valid JSON 40 except requests.RequestException
as e:
41 LOG.error(
'Metric couldn\'t be uploaded, due to a network error ({})' 47 Create standardized message for reporting timing. 49 ident (str): identifier of user interaction 50 system (str): system the that's generated the report 51 timing (stopwatch): Stopwatch object with recorded timing 52 additional_data (dict): dictionary with related data 54 additional_data = additional_data
or {}
55 report = copy(additional_data)
57 report[
'system'] = system
58 report[
'start_time'] = timing.timestamp
59 report[
'time'] = timing.time
66 Simple time measuring class. 74 Start a time measurement 79 cur_time = time.time()
82 return cur_time - start_time
86 Stop a running time measurement. returns the measured time 88 cur_time = time.time()
90 self.
time = cur_time - start_time
95 Start stopwatch when entering with-block. 101 Stop stopwatch when exiting with-block. 106 cur_time = time.time()
115 MetricsAggregator is not threadsafe, and multiple clients writing the 116 same metric "concurrently" may result in data loss. 124 self.
attr(
"version", CORE_VERSION_STR)
127 cur = self._counters.get(name, 0)
131 cur = self._timers.get(name)
145 self.
attr(
"version", CORE_VERSION_STR)
159 count = (len(payload[
'counters']) + len(payload[
'timers']) +
160 len(payload[
'levels']))
165 publisher.publish(payload)
167 threading.Thread(target=publish).start()
172 conf = Configuration().
get()[
'server']
173 self.
url = url
or conf[
'url']
177 if 'session_id' not in events:
178 session_id = SessionManager.get().session_id
179 events[
'session_id'] = session_id
183 headers={
'Content-Type':
'application/json'},
184 data=json.dumps(events), verify=
False)
def report_timing(ident, system, timing, additional_data=None)
def __exit__(self, tpe, value, tb)
def level(self, name, value)
def is_paired(ignore_errors=True)
def __init__(self, url=None, enabled=False)
def report_metric(name, data)
def publish(self, events)
def timer(self, name, value)
def attr(self, name, value)
def increment(self, name, value=1)
def get(phrase, lang=None, context=None)