| 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 | 7 |
| 8 import base64 | 8 import base64 |
| 9 import httplib2 | 9 import httplib2 |
| 10 import json | 10 import json |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 def encodeToJson(self, metric_pb): | 97 def encodeToJson(self, metric_pb): |
| 98 return json.dumps({ 'resource': pb_to_popo.convert(metric_pb) }) | 98 return json.dumps({ 'resource': pb_to_popo.convert(metric_pb) }) |
| 99 | 99 |
| 100 def send(self, metric_pb): | 100 def send(self, metric_pb): |
| 101 body = self.encodeToJson(self._wrap_proto(metric_pb)) | 101 body = self.encodeToJson(self._wrap_proto(metric_pb)) |
| 102 | 102 |
| 103 try: | 103 try: |
| 104 resp, content = self._http.request(self._endpoint, method='POST', | 104 resp, content = self._http.request(self._endpoint, method='POST', |
| 105 body=body) | 105 body=body) |
| 106 if resp.status != 200: | 106 if resp.status != 200: |
| 107 logging.warning('HttpsMonitor.send received status %d: %s', resp, | 107 logging.warning('HttpsMonitor.send received status %d: %s', resp.status, |
| 108 content) | 108 content) |
| 109 except (ValueError, errors.Error, | 109 except (ValueError, errors.Error, |
| 110 socket.timeout, socket.error, socket.herror, socket.gaierror, | 110 socket.timeout, socket.error, socket.herror, socket.gaierror, |
| 111 httplib2.HttpLib2Error): | 111 httplib2.HttpLib2Error): |
| 112 logging.warning('HttpsMonitor.send failed: %s\n', | 112 logging.warning('HttpsMonitor.send failed: %s\n', |
| 113 traceback.format_exc()) | 113 traceback.format_exc()) |
| 114 | 114 |
| 115 | 115 |
| 116 class PubSubMonitor(Monitor): | 116 class PubSubMonitor(Monitor): |
| 117 """Class which publishes metrics to a Cloud Pub/Sub topic.""" | 117 """Class which publishes metrics to a Cloud Pub/Sub topic.""" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 logging.info('Flushing monitoring metrics:\n%s', text) | 220 logging.info('Flushing monitoring metrics:\n%s', text) |
| 221 if self._fh is not None: | 221 if self._fh is not None: |
| 222 self._fh.write(text + '\n\n') | 222 self._fh.write(text + '\n\n') |
| 223 self._fh.flush() | 223 self._fh.flush() |
| 224 | 224 |
| 225 | 225 |
| 226 class NullMonitor(Monitor): | 226 class NullMonitor(Monitor): |
| 227 """Class that doesn't send metrics anywhere.""" | 227 """Class that doesn't send metrics anywhere.""" |
| 228 def send(self, metric_pb): | 228 def send(self, metric_pb): |
| 229 pass | 229 pass |
| OLD | NEW |