| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 credentials_json = json.load(credentials_file) | 77 credentials_json = json.load(credentials_file) |
| 78 if credentials_json.get('type', None): | 78 if credentials_json.get('type', None): |
| 79 credentials = GoogleCredentials.from_stream(credentials_file_path) | 79 credentials = GoogleCredentials.from_stream(credentials_file_path) |
| 80 credentials = credentials.create_scoped(self._SCOPES) | 80 credentials = credentials.create_scoped(self._SCOPES) |
| 81 return credentials | 81 return credentials |
| 82 return Storage(credentials_file_path).get() | 82 return Storage(credentials_file_path).get() |
| 83 | 83 |
| 84 def send(self, metric_pb): | 84 def send(self, metric_pb): |
| 85 raise NotImplementedError() | 85 raise NotImplementedError() |
| 86 | 86 |
| 87 |
| 87 class HttpsMonitor(Monitor): | 88 class HttpsMonitor(Monitor): |
| 88 | 89 |
| 89 _SCOPES = [ | 90 _SCOPES = [ |
| 90 'https://www.googleapis.com/auth/prodxmon' | 91 'https://www.googleapis.com/auth/prodxmon' |
| 91 ] | 92 ] |
| 92 | 93 |
| 93 def __init__(self, endpoint, credentials_file_path, http=None): | 94 def __init__(self, endpoint, credentials_file_path, http=None): |
| 94 self._endpoint = endpoint | 95 self._endpoint = endpoint |
| 95 credentials = self._load_credentials(credentials_file_path) | 96 credentials = self._load_credentials(credentials_file_path) |
| 96 if http is None: | 97 if http is None: |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 logging.info('Flushing monitoring metrics:\n%s', text) | 235 logging.info('Flushing monitoring metrics:\n%s', text) |
| 235 if self._fh is not None: | 236 if self._fh is not None: |
| 236 self._fh.write(text + '\n\n') | 237 self._fh.write(text + '\n\n') |
| 237 self._fh.flush() | 238 self._fh.flush() |
| 238 | 239 |
| 239 | 240 |
| 240 class NullMonitor(Monitor): | 241 class NullMonitor(Monitor): |
| 241 """Class that doesn't send metrics anywhere.""" | 242 """Class that doesn't send metrics anywhere.""" |
| 242 def send(self, metric_pb): | 243 def send(self, metric_pb): |
| 243 pass | 244 pass |
| OLD | NEW |