Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: infra_libs/ts_mon/common/metrics.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: add noncululativedistribution metric to ts_mon imports Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « infra_libs/ts_mon/common/http_metrics.py ('k') | infra_libs/ts_mon/common/standard_metrics.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Classes representing individual metrics that can be sent.""" 5 """Classes representing individual metrics that can be sent."""
6 6
7 7
8 import copy 8 import copy
9 import threading 9 import threading
10 import time 10 import time
11 11
12 from monacq.proto import metrics_pb2 12 try:
13 13 from infra_libs.ts_mon import interface
14 from infra_libs.ts_mon import distribution 14 from infra_libs.ts_mon.common import distribution
15 from infra_libs.ts_mon import errors 15 from infra_libs.ts_mon.common import errors
16 from infra_libs.ts_mon import interface 16 from monacq.proto import metrics_pb2
17 except ImportError: # pragma: no cover
18 import interface
19 from common import distribution
20 from common import errors
21 from monacq.proto import metrics_pb2
17 22
18 23
19 MICROSECONDS_PER_SECOND = 1000000 24 MICROSECONDS_PER_SECOND = 1000000
20 25
21 26
22 class Metric(object): 27 class Metric(object):
23 """Abstract base class for a metric. 28 """Abstract base class for a metric.
24 29
25 A Metric is an attribute that may be monitored across many targets. Examples 30 A Metric is an attribute that may be monitored across many targets. Examples
26 include disk usage or the number of requests a server has received. A single 31 include disk usage or the number of requests a server has received. A single
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 self._target = target 67 self._target = target
63 fields = fields or {} 68 fields = fields or {}
64 if len(fields) > 7: 69 if len(fields) > 7:
65 raise errors.MonitoringTooManyFieldsError(self._name, fields) 70 raise errors.MonitoringTooManyFieldsError(self._name, fields)
66 self._fields = fields 71 self._fields = fields
67 self._normalized_fields = self._normalize_fields(self._fields) 72 self._normalized_fields = self._normalize_fields(self._fields)
68 self._thread_lock = threading.Lock() 73 self._thread_lock = threading.Lock()
69 74
70 interface.register(self) 75 interface.register(self)
71 76
77
78 def __eq__(self, other):
79 name = self._name == other._name
80 target = self._target == other._target
81 field = self._fields == other._fields
82 instance_type = type(self) == type(other)
83 return name and target and field and instance_type
84
72 def unregister(self): 85 def unregister(self):
73 interface.unregister(self) 86 interface.unregister(self)
74 87
75 def serialize_to(self, collection_pb, default_target=None, loop_action=None): 88 def serialize_to(self, collection_pb, default_target=None, loop_action=None):
76 """Generate metrics_pb2.MetricsData messages for this metric. 89 """Generate metrics_pb2.MetricsData messages for this metric.
77 90
78 Args: 91 Args:
79 collection_pb (metrics_pb2.MetricsCollection): protocol buffer into which 92 collection_pb (metrics_pb2.MetricsCollection): protocol buffer into which
80 to add the current metric values. 93 to add the current metric values.
81 default_target (Target): a Target to use if self._target is not set. 94 default_target (Target): a Target to use if self._target is not set.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 438
426 def __init__( 439 def __init__(
427 self, name, bucketer=None, target=None, fields=None, time_fn=time.time): 440 self, name, bucketer=None, target=None, fields=None, time_fn=time.time):
428 super(NonCumulativeDistributionMetric, self).__init__( 441 super(NonCumulativeDistributionMetric, self).__init__(
429 name, 442 name,
430 is_cumulative=False, 443 is_cumulative=False,
431 bucketer=bucketer, 444 bucketer=bucketer,
432 target=target, 445 target=target,
433 fields=fields, 446 fields=fields,
434 time_fn=time_fn) 447 time_fn=time_fn)
OLDNEW
« no previous file with comments | « infra_libs/ts_mon/common/http_metrics.py ('k') | infra_libs/ts_mon/common/standard_metrics.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698