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

Unified Diff: appengine_module/gae_ts_mon/monitoring.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 side-by-side diff with in-line comments
Download patch
Index: appengine_module/gae_ts_mon/monitoring.py
diff --git a/appengine_module/gae_ts_mon/monitoring.py b/appengine_module/gae_ts_mon/monitoring.py
new file mode 100644
index 0000000000000000000000000000000000000000..d84bcc1e80dc03a60d1f731db9d1c14cf91183dc
--- /dev/null
+++ b/appengine_module/gae_ts_mon/monitoring.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Send system monitoring data to the timeseries monitoring API."""
+
+import logging
+import webapp2
+
+from common.metrics import *
+import config
+import interface
+
+from google.appengine.api import app_identity
+from google.appengine.api import modules
+
+import os
+import sys
+
+
+access_count = CounterMetric('gae/access/count')
+request_bytes = CumulativeDistributionMetric('http/request_bytes')
+response_bytes = CumulativeDistributionMetric('http/response_bytes')
+durations = CumulativeDistributionMetric('http/durations')
+response_status = CounterMetric('http/response_status')
+
+
+class InitializeMonitoringHandler(webapp2.RequestHandler):
+
+ def get(self):
+ service = app_identity.get_application_id()
+ version = modules.get_current_version_name()
+ instance_id = int(modules.get_current_instance_id())
+ 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
+ config.initialize(job_name=version, instance=instance_id,
+ service_name=service, endpoint=endpoint)
+ self.response.set_status(200, 'Initialized instance of ts_mon.')
+
+
+class MonitoringHandler(webapp2.RequestHandler):
+
+ ''' Called by cron jobs every 5 minutes to update metrics. '''
+ def get(self, key=None):
+ interface.flush()
+ self.response.write('Metrics updated.')
Sergey Berezin 2015/08/18 00:40:38 nit: change it to logging.info(). Response will li
+ return
+
+
+app = webapp2.WSGIApplication([
+ ('/_ah/start', InitializeMonitoringHandler),
+ ('/monitoring', MonitoringHandler),
+ ('/monitoring/(.*)', MonitoringHandler)
+], debug=True)

Powered by Google App Engine
This is Rietveld 408576698