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

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

Issue 2573343002: Roll infra_libs and its dependencies to 066f135 (Closed)
Patch Set: Created 4 years 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
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 import copy 7 import copy
8 8
9 from infra_libs.ts_mon.protos.current import metrics_pb2 9 from infra_libs.ts_mon.protos.current import metrics_pb2
10 from infra_libs.ts_mon.protos.new import metrics_pb2 as new_metrics_pb2 10 from infra_libs.ts_mon.protos.new import metrics_pb2 as new_metrics_pb2
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 data_set.annotations.unit = self._map_units_to_string(self._units) 112 data_set.annotations.unit = self._map_units_to_string(self._units)
113 113
114 if self.is_cumulative(): 114 if self.is_cumulative():
115 data_set.stream_kind = new_metrics_pb2.CUMULATIVE 115 data_set.stream_kind = new_metrics_pb2.CUMULATIVE
116 else: 116 else:
117 data_set.stream_kind = new_metrics_pb2.GAUGE 117 data_set.stream_kind = new_metrics_pb2.GAUGE
118 118
119 self._populate_value_type(data_set) 119 self._populate_value_type(data_set)
120 self._populate_field_descriptors(data_set, fields) 120 self._populate_field_descriptors(data_set, fields)
121 121
122 def _populate_data(self, data_set, start_time, end_time, fields, value): 122 def _populate_data(self, data, start_time, end_time, fields, value):
123 """Add a new metrics_pb2.MetricsData to data_set 123 """Populate a new metrics_pb2.MetricsData.
124 124
125 Args: 125 Args:
126 data_set (new_metrics_pb2.MetricsDataSet): protocol buffer into 126 data_ (new_metrics_pb2.MetricsData): protocol buffer into
127 which to add the current metric values. 127 which to populate the current metric values.
128 start_time (int): timestamp in microseconds since UNIX epoch. 128 start_time (int): timestamp in microseconds since UNIX epoch.
129 """ 129 """
130 data = data_set.data.add()
131 data.start_timestamp.seconds = int(start_time) 130 data.start_timestamp.seconds = int(start_time)
132 data.end_timestamp.seconds = int(end_time) 131 data.end_timestamp.seconds = int(end_time)
133 132
134 self._populate_fields_new(data, fields) 133 self._populate_fields_new(data, fields)
135 self._populate_value_new(data, value) 134 self._populate_value_new(data, value)
136 135
137 def serialize_to(self, collection_pb, start_time, fields, value, target): 136 def serialize_to(self, metric_pb, start_time, fields, value, target):
138 """Generate metrics_pb2.MetricsData messages for this metric. 137 """Generate metrics_pb2.MetricsData messages for this metric.
139 138
140 Args: 139 Args:
141 collection_pb (metrics_pb2.MetricsCollection): protocol buffer into which 140 metric_pb (metrics_pb2.MetricsData): protocol buffer into which
142 to add the current metric values. 141 to serialize the current metric values.
143 start_time (int): timestamp in microseconds since UNIX epoch. 142 start_time (int): timestamp in microseconds since UNIX epoch.
144 target (Target): a Target to use. 143 target (Target): a Target to use.
145 """ 144 """
146 145
147 metric_pb = collection_pb.data.add()
148 metric_pb.metric_name_prefix = interface.state.metric_name_prefix 146 metric_pb.metric_name_prefix = interface.state.metric_name_prefix
149 metric_pb.name = self._name 147 metric_pb.name = self._name
150 if self._description is not None: 148 if self._description is not None:
151 metric_pb.description = self._description 149 metric_pb.description = self._description
152 if self._units is not None: 150 if self._units is not None:
153 metric_pb.units = self._units 151 metric_pb.units = self._units
154 152
155 self._populate_value(metric_pb, value, start_time) 153 self._populate_value(metric_pb, value, start_time)
156 self._populate_fields(metric_pb, fields) 154 self._populate_fields(metric_pb, fields)
157 155
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if value.bucketer.width == 0: 542 if value.bucketer.width == 0:
545 pb.exponential_buckets.growth_factor = value.bucketer.growth_factor 543 pb.exponential_buckets.growth_factor = value.bucketer.growth_factor
546 pb.exponential_buckets.scale = 1.0 544 pb.exponential_buckets.scale = 1.0
547 pb.exponential_buckets.num_finite_buckets = ( 545 pb.exponential_buckets.num_finite_buckets = (
548 value.bucketer.num_finite_buckets) 546 value.bucketer.num_finite_buckets)
549 else: 547 else:
550 pb.linear_buckets.width = value.bucketer.width 548 pb.linear_buckets.width = value.bucketer.width
551 pb.linear_buckets.offset = 0.0 549 pb.linear_buckets.offset = 0.0
552 pb.linear_buckets.num_finite_buckets = value.bucketer.num_finite_buckets 550 pb.linear_buckets.num_finite_buckets = value.bucketer.num_finite_buckets
553 551
554 # Copy the distribution bucket values. Only include the finite buckets, not 552 # Copy the distribution bucket values. Include the overflow buckets on
555 # the overflow buckets on each end. 553 # either end.
556 pb.bucket_count.extend( 554 pb.bucket_count.extend(
557 value.buckets.get(i, 0) for i in 555 value.buckets.get(i, 0) for i in
558 xrange(0, value.bucketer.total_buckets)) 556 xrange(0, value.bucketer.total_buckets))
559 557
560 pb.count = value.count 558 pb.count = value.count
561 pb.mean = float(value.sum) / max(value.count, 1) 559 pb.mean = float(value.sum) / max(value.count, 1)
562 560
563 def _populate_value_type(self, data_set_pb): 561 def _populate_value_type(self, data_set_pb):
564 data_set_pb.value_type = new_metrics_pb2.DISTRIBUTION 562 data_set_pb.value_type = new_metrics_pb2.DISTRIBUTION
565 563
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 MetricsDataUnits.KILOBYTES: 'kBy', 668 MetricsDataUnits.KILOBYTES: 'kBy',
671 MetricsDataUnits.MEGABYTES: 'MBy', 669 MetricsDataUnits.MEGABYTES: 'MBy',
672 MetricsDataUnits.GIGABYTES: 'GBy', 670 MetricsDataUnits.GIGABYTES: 'GBy',
673 MetricsDataUnits.KIBIBYTES: 'kiBy', 671 MetricsDataUnits.KIBIBYTES: 'kiBy',
674 MetricsDataUnits.MEBIBYTES: 'MiBy', 672 MetricsDataUnits.MEBIBYTES: 'MiBy',
675 MetricsDataUnits.GIBIBYTES: 'GiBy', 673 MetricsDataUnits.GIBIBYTES: 'GiBy',
676 MetricsDataUnits.AMPS: 'A', 674 MetricsDataUnits.AMPS: 'A',
677 MetricsDataUnits.MILLIAMPS : 'mA', 675 MetricsDataUnits.MILLIAMPS : 'mA',
678 MetricsDataUnits.DEGREES_CELSIUS: 'Cel' 676 MetricsDataUnits.DEGREES_CELSIUS: 'Cel'
679 } 677 }
OLDNEW
« no previous file with comments | « client/third_party/infra_libs/ts_mon/common/metric_store.py ('k') | client/third_party/infra_libs/ts_mon/common/monitors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698