OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
agable
2015/08/12 22:18:08
This file (appengine module, really) is the meat o
| |
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 import gae_ts_mon | |
12 import ts_alerts | |
13 | |
14 from google.appengine.api import app_identity | |
15 from google.appengine.api import modules | |
16 | |
17 | |
18 access_count = gae_ts_mon.CounterMetric('gae/access/count') | |
19 | |
20 | |
21 class InitializeMonitoringHandler(webapp2.RequestHandler): | |
22 | |
23 def get(self): | |
24 service = app_identity.get_application_id() | |
25 version = modules.get_current_version_name() | |
26 instance_id = int(modules.get_current_instance_id()) | |
27 endpoint = 'pubsub://chrome-infra-mon-pubsub/monacq' | |
28 gae_ts_mon.initialize(job_name=version, instance=instance_id, | |
29 service_name=service, endpoint=endpoint) | |
30 self.response.set_status(200, 'Initialized instance of ts_mon.') | |
31 | |
32 | |
33 class MonitoringHandler(webapp2.RequestHandler): | |
34 | |
35 ''' Called by cron jobs every 5 minutes to update metrics. ''' | |
36 def get(self, key=None): | |
37 if key: | |
38 url = app_identity.get_default_version_hostname() | |
39 access_count.increment(fields={'url_path': url + '/' + key, | |
40 'request_path': key, | |
41 'request_type': 'GET'}) | |
agable
2015/08/12 22:18:08
The request type should be supplied by whoever cal
| |
42 return | |
43 gae_ts_mon.flush() | |
44 self.response.write('Sheriff-o-matic metrics updated.') | |
45 return | |
46 | |
47 def post(self): | |
agable
2015/08/12 22:18:08
This appears to be unreachable / dead code. Sucks
| |
48 key = self.request.body['endpoint'] | |
49 if key not in self.ACCESS_COUNT.keys(): | |
50 self.response.write('Unknown key %s', key) | |
51 self.abort(400) | |
52 return | |
53 self.ACCESS_COUNT[key] += 1 | |
54 self.response.write('Post success: ' + key) | |
55 | |
56 | |
57 app = webapp2.WSGIApplication([ | |
58 ('/_ah/start', InitializeMonitoringHandler), | |
59 ('/monitoring', MonitoringHandler), | |
60 ('/monitoring/(.*)', MonitoringHandler) | |
61 ], debug=True) | |
62 | |
agable
2015/08/12 22:18:08
nit: no empty line
| |
OLD | NEW |