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

Unified Diff: appengine/sheriff_o_matic/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: set correct metric and target fields 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/sheriff_o_matic/monitoring.py
diff --git a/appengine/sheriff_o_matic/monitoring.py b/appengine/sheriff_o_matic/monitoring.py
new file mode 100644
index 0000000000000000000000000000000000000000..464430576c7ed2d98693aad2aed29d50590ba597
--- /dev/null
+++ b/appengine/sheriff_o_matic/monitoring.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
agable 2015/08/12 22:18:08 This file (appengine module, really) is the meat o
+# 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
+
+import gae_ts_mon
+import ts_alerts
+
+from google.appengine.api import app_identity
+from google.appengine.api import modules
+
+
+access_count = gae_ts_mon.CounterMetric('gae/access/count')
+
+
+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'
+ gae_ts_mon.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):
+ if key:
+ url = app_identity.get_default_version_hostname()
+ access_count.increment(fields={'url_path': url + '/' + key,
+ 'request_path': key,
+ 'request_type': 'GET'})
agable 2015/08/12 22:18:08 The request type should be supplied by whoever cal
+ return
+ gae_ts_mon.flush()
+ self.response.write('Sheriff-o-matic metrics updated.')
+ return
+
+ def post(self):
agable 2015/08/12 22:18:08 This appears to be unreachable / dead code. Sucks
+ key = self.request.body['endpoint']
+ if key not in self.ACCESS_COUNT.keys():
+ self.response.write('Unknown key %s', key)
+ self.abort(400)
+ return
+ self.ACCESS_COUNT[key] += 1
+ self.response.write('Post success: ' + key)
+
+
+app = webapp2.WSGIApplication([
+ ('/_ah/start', InitializeMonitoringHandler),
+ ('/monitoring', MonitoringHandler),
+ ('/monitoring/(.*)', MonitoringHandler)
+], debug=True)
+
agable 2015/08/12 22:18:08 nit: no empty line

Powered by Google App Engine
This is Rietveld 408576698