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

Unified Diff: appengine_module/gae_ts_mon/config.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: clean up code 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/config.py
diff --git a/appengine_module/gae_ts_mon/config.py b/appengine_module/gae_ts_mon/config.py
new file mode 100644
index 0000000000000000000000000000000000000000..3220ce73b9a73f49051eecfa13800f73c7bcf1dc
--- /dev/null
+++ b/appengine_module/gae_ts_mon/config.py
@@ -0,0 +1,77 @@
+# Copyright 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.
+
+import json
+import logging
+import os
+import socket
+import sys
+import urlparse
+import re
+
+import monitors
+import interface
+import standard_metrics
+from gae import targets
+
+
+def initialize(endpoint=None, flush='manual', flush_interval_secs=60,
+ job_name=None, service_name=None, number=0):
+ """Initialize the global monitor.
+
+ Also initializes the default target if sufficient arguments are supplied.
+ If they aren't, all created metrics will have to supply their own target.
+ This is generally a bad idea, as many libraries rely on the default target
+ being set up.
+
+ Starts a background thread to automatically flush monitoring metrics if not
+ disabled by arguments.
+
+ Args:
+ endpoint: url (including file://, pubsub://project/topic) to post monitoring
agable 2015/08/10 23:04:38 nit: remove reference to file:// urls; they don't
+ metrics to. If set, overrides the value in --ts-mon-config-file
agable 2015/08/10 23:04:38 nit: remove reference to command line flag
+ flush: metric push behavior: all (send every metric individually),
+ 'manual (only send when flush() is called), or auto (send
agable 2015/08/10 23:04:38 nit: stray leading single quote Also, does auto a
+ 'automatically every --ts-mon-flush-interval-secs seconds)
agable 2015/08/10 23:04:38 nit: another stray leading quote
+ flush_interval_secs: automatically push metrics on this interval if
+ --ts-mon-flush=auto
agable 2015/08/10 23:04:38 nit: remove reference to command line flag
+ job_name: name of the job instance of the task
+ number: number of instance for this task
+ service_name: name of service being monitored
+
+ """
+ hostname = socket.getfqdn().split('.')[0]
+ try:
+ region = fqdn.split('.')[1]
+ except:
+ region = ''
+
+ if endpoint.startswith('pubsub://'):
+ url = urlparse.urlparse(endpoint)
+ project = url.netloc
+ topic = url.path.strip('/')
+ interface.state.global_monitor = monitors.PubSubMonitor(project, topic)
+ else:
+ logging.error('Error: endpoint should begin with pubsub://')
+ interface.state.global_monitor = monitors.NullMonitor()
+
+ # Reimplement ArgumentParser.error, since we don't have access to the parser
+ if not service_name:
+ print >> sys.stderr, ('Argument --ts-mon-task-service-name must be '
agable 2015/08/10 23:04:38 Use logging.error instead of print, and don't refe
+ 'provided when the target type is "task".')
+ sys.exit(2)
agable 2015/08/10 23:04:38 Eep don't sys.exit in appengine :)
+ if not job_name: # pragma: no cover
+ print >> sys.stderr, ('Argument --ts-mon-task-job-name must be provided '
agable 2015/08/10 23:04:38 Same re: logging here
+ 'when the target type is "task".')
+ sys.exit(2)
+ interface.state.default_target = targets.TaskTarget(
+ service_name, job_name, region, hostname, number)
+
+ interface.state.flush_mode = flush
+
+ if flush == 'auto':
agable 2015/08/10 23:04:38 Remove 'auto', since I don't think it works on app
+ interface.state.flush_thread = interface._FlushThread(flush_interval_secs)
+ interface.state.flush_thread.start()
+
+ standard_metrics.init()

Powered by Google App Engine
This is Rietveld 408576698