Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 the monitoring interface for tasks or devices. | 5 """Classes representing the monitoring interface for tasks or devices. |
| 6 | 6 |
| 7 Usage: | 7 Usage: |
| 8 import argparse | 8 import argparse |
| 9 from infra_libs import ts_mon | 9 from infra_libs import ts_mon |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 """ | 32 """ |
| 33 | 33 |
| 34 import logging | 34 import logging |
| 35 import os | 35 import os |
| 36 import random | 36 import random |
| 37 import threading | 37 import threading |
| 38 import time | 38 import time |
| 39 | 39 |
| 40 from monacq.proto import metrics_pb2 | 40 from monacq.proto import metrics_pb2 |
| 41 | 41 |
| 42 from infra_libs.ts_mon import errors | 42 from infra_libs.ts_mon.common import errors |
| 43 | 43 |
| 44 # The maximum number of MetricsData messages to include in each HTTP request. | 44 # The maximum number of MetricsData messages to include in each HTTP request. |
| 45 # MetricsCollections larger than this will be split into multiple requests. | 45 # MetricsCollections larger than this will be split into multiple requests. |
| 46 METRICS_DATA_LENGTH_LIMIT = 5000 | 46 METRICS_DATA_LENGTH_LIMIT = 5000 |
| 47 | 47 |
| 48 | 48 |
| 49 class State(object): | 49 class State(object): |
| 50 """Package-level state is stored here so that it is easily accessible. | 50 """Package-level state is stored here so that it is easily accessible. |
| 51 | 51 |
| 52 Configuration is kept in this one object at the global level so that all | 52 Configuration is kept in this one object at the global level so that all |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 109 |
| 110 | 110 |
| 111 def register(metric): | 111 def register(metric): |
| 112 """Adds the metric to the list of metrics sent by flush(). | 112 """Adds the metric to the list of metrics sent by flush(). |
| 113 | 113 |
| 114 This is called automatically by Metric's constructor - you don't need to call | 114 This is called automatically by Metric's constructor - you don't need to call |
| 115 it manually. | 115 it manually. |
| 116 """ | 116 """ |
| 117 # If someone is registering the same metric object twice, that's okay, but | 117 # If someone is registering the same metric object twice, that's okay, but |
| 118 # registering two different metric objects with the same metric name is not. | 118 # registering two different metric objects with the same metric name is not. |
| 119 if metric in state.metrics: | 119 for m in state.metrics: |
| 120 return | 120 if metric == m: |
| 121 return | |
|
agable
2015/08/19 01:14:42
I don't think this does what we want: This means t
| |
| 121 if any([metric._name == m._name for m in state.metrics]): | 122 if any([metric._name == m._name for m in state.metrics]): |
| 122 raise errors.MonitoringDuplicateRegistrationError(metric._name) | 123 raise errors.MonitoringDuplicateRegistrationError(metric._name) |
| 123 | 124 |
| 124 state.metrics.add(metric) | 125 state.metrics.add(metric) |
| 125 | 126 |
| 126 | 127 |
| 127 def unregister(metric): | 128 def unregister(metric): |
| 128 """Removes the metric from the list of metrics sent by flush().""" | 129 """Removes the metric from the list of metrics sent by flush().""" |
| 129 state.metrics.remove(metric) | 130 state.metrics.remove(metric) |
| 130 | 131 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 'Last monitoring flush took %f seconds (longer than ' | 177 'Last monitoring flush took %f seconds (longer than ' |
| 177 '--ts-mon-flush-interval-secs = %f seconds)', | 178 '--ts-mon-flush-interval-secs = %f seconds)', |
| 178 flush_duration, self.interval_secs) | 179 flush_duration, self.interval_secs) |
| 179 next_timeout = 0 | 180 next_timeout = 0 |
| 180 | 181 |
| 181 def stop(self): | 182 def stop(self): |
| 182 """Stops the background thread and performs a final flush.""" | 183 """Stops the background thread and performs a final flush.""" |
| 183 | 184 |
| 184 self.stop_event.set() | 185 self.stop_event.set() |
| 185 self.join() | 186 self.join() |
| OLD | NEW |