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 from common.http_metrics import ( |
| 13 access_count, durations, request_bytes, response_bytes, response_status) |
| 14 import config |
| 15 import interface |
| 16 |
| 17 from google.appengine.api import app_identity |
| 18 from google.appengine.api import modules |
| 19 |
| 20 import os |
| 21 import sys |
| 22 |
| 23 |
| 24 MONACQ_ENDPOINT = 'pubsub://chrome-infra-mon-pubsub/monacq' |
| 25 |
| 26 |
| 27 class InitializeMonitoringHandler(webapp2.RequestHandler): |
| 28 |
| 29 def get(self): |
| 30 service = app_identity.get_application_id() |
| 31 version = modules.get_current_version_name() |
| 32 instance_id = hash(modules.get_current_instance_id()) % 10 |
| 33 endpoint = MONACQ_ENDPOINT |
| 34 config.initialize(job_name=version, instance=instance_id, |
| 35 service_name=service, endpoint=endpoint) |
| 36 self.response.set_status(200, 'Initialized instance of ts_mon.') |
| 37 |
| 38 |
| 39 class MonitoringHandler(webapp2.RequestHandler): |
| 40 |
| 41 ''' Called by cron jobs every 5 minutes to update metrics. ''' |
| 42 def get(self, key=None): |
| 43 interface.flush() |
| 44 logging.info('Metrics updated.') |
| 45 return |
| 46 |
| 47 |
| 48 app = webapp2.WSGIApplication([ |
| 49 ('/_ah/start', InitializeMonitoringHandler), |
| 50 ('/monitoring', MonitoringHandler), |
| 51 ('/monitoring/(.*)', MonitoringHandler) |
| 52 ], debug=True) |
OLD | NEW |