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

Side by Side Diff: infra_libs/ts_mon/monitors.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: take out deleted utils methods 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
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 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 25 matching lines...) Expand all
36 import json 36 import json
37 import logging 37 import logging
38 import os 38 import os
39 39
40 from monacq import acquisition_api 40 from monacq import acquisition_api
41 from monacq.proto import metrics_pb2 41 from monacq.proto import metrics_pb2
42 42
43 from infra_libs import logs 43 from infra_libs import logs
44 import infra_libs 44 import infra_libs
45 45
46 import httplib2
47 from apiclient import discovery 46 from apiclient import discovery
48 from oauth2client.client import GoogleCredentials 47 from oauth2client.client import GoogleCredentials
49 from oauth2client.file import Storage 48 from oauth2client.file import Storage
50 from oauth2client.gce import AppAssertionCredentials 49 from oauth2client.gce import AppAssertionCredentials
50 import httplib2
51 51
52 # Special string that can be passed through as the credentials path to use the 52 # Special string that can be passed through as the credentials path to use the
53 # default GCE service account. 53 # default GCE service account.
54 GCE_CREDENTIALS = ':gce' 54 GCE_CREDENTIALS = ':gce'
55 55
56 56
57 def _logging_callback(resp, content): # pragma: no cover 57 def _logging_callback(resp, content): # pragma: no cover
58 logging.debug(repr(resp)) 58 logging.debug(repr(resp))
59 logging.debug(content) 59 logging.debug(content)
60 60
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 self._api = api 115 self._api = api
116 116
117 def send(self, metric_pb): 117 def send(self, metric_pb):
118 """Send a metric proto to the monitoring api. 118 """Send a metric proto to the monitoring api.
119 119
120 Args: 120 Args:
121 metric_pb (MetricsData or MetricsCollection): the metric protobuf to send 121 metric_pb (MetricsData or MetricsCollection): the metric protobuf to send
122 """ 122 """
123 try: 123 try:
124 self._api.Send(self._wrap_proto(metric_pb)) 124 self._api.Send(self._wrap_proto(metric_pb))
125 except acquisition_api.AcquisitionApiRequestException as e: 125 except acquisition_api.AcquisitionApiRequestException as e: # pylint: disabl e=undefined-variable
Sergey Berezin 2015/08/18 00:40:38 nit: any way to stay within 80 char limit? Maybe t
jshu 2015/08/18 01:15:55 don't think we actually need that comment
126 logging.error('Failed to send the metrics: %s', e) 126 logging.error('Failed to send the metrics: %s', e)
127 127
128 128
129 class PubSubMonitor(Monitor): 129 class PubSubMonitor(Monitor):
130 """Class which publishes metrics to a Cloud Pub/Sub topic.""" 130 """Class which publishes metrics to a Cloud Pub/Sub topic."""
131 131
132 _SCOPES = [ 132 _SCOPES = [
133 'https://www.googleapis.com/auth/pubsub', 133 'https://www.googleapis.com/auth/pubsub',
134 ] 134 ]
135 135
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 logs.add_handler(self._logger, handler=filehandler, level=logging.INFO) 194 logs.add_handler(self._logger, handler=filehandler, level=logging.INFO)
195 195
196 def send(self, metric_pb): 196 def send(self, metric_pb):
197 self._logger.info('\n' + str(self._wrap_proto(metric_pb))) 197 self._logger.info('\n' + str(self._wrap_proto(metric_pb)))
198 198
199 199
200 class NullMonitor(Monitor): 200 class NullMonitor(Monitor):
201 """Class that doesn't send metrics anywhere.""" 201 """Class that doesn't send metrics anywhere."""
202 def send(self, metric_pb): 202 def send(self, metric_pb):
203 pass 203 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698