OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Send system monitoring data to the timeseries monitoring API.""" | |
7 | |
8 import logging | |
9 import webapp2 | |
10 | |
11 from common.metrics import * | |
12 import config | |
13 import interface | |
14 | |
15 from google.appengine.api import app_identity | |
16 from google.appengine.api import modules | |
17 | |
18 import os | |
19 import sys | |
20 | |
21 | |
22 access_count = CounterMetric('gae/access/count') | |
23 request_bytes = CumulativeDistributionMetric('http/request_bytes') | |
24 response_bytes = CumulativeDistributionMetric('http/response_bytes') | |
25 durations = CumulativeDistributionMetric('http/durations') | |
26 response_status = CounterMetric('http/response_status') | |
27 | |
28 | |
29 class InitializeMonitoringHandler(webapp2.RequestHandler): | |
30 | |
31 def get(self): | |
32 service = app_identity.get_application_id() | |
33 version = modules.get_current_version_name() | |
34 instance_id = int(modules.get_current_instance_id()) | |
35 endpoint = 'pubsub://chrome-infra-mon-pubsub/monacq' | |
Sergey Berezin
2015/08/18 00:40:38
nit: in general, it's a bad idea to hard-code endp
| |
36 config.initialize(job_name=version, instance=instance_id, | |
37 service_name=service, endpoint=endpoint) | |
38 self.response.set_status(200, 'Initialized instance of ts_mon.') | |
39 | |
40 | |
41 class MonitoringHandler(webapp2.RequestHandler): | |
42 | |
43 ''' Called by cron jobs every 5 minutes to update metrics. ''' | |
44 def get(self, key=None): | |
45 interface.flush() | |
46 self.response.write('Metrics updated.') | |
Sergey Berezin
2015/08/18 00:40:38
nit: change it to logging.info(). Response will li
| |
47 return | |
48 | |
49 | |
50 app = webapp2.WSGIApplication([ | |
51 ('/_ah/start', InitializeMonitoringHandler), | |
52 ('/monitoring', MonitoringHandler), | |
53 ('/monitoring/(.*)', MonitoringHandler) | |
54 ], debug=True) | |
OLD | NEW |