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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import logging
7 import os
8 import socket
9 import sys
10 import urlparse
11 import re
12
13 import monitors
14 import interface
15 import standard_metrics
16 from gae import targets
17
18
19 def initialize(endpoint=None, flush='manual', flush_interval_secs=60,
20 job_name=None, service_name=None, number=0):
21 """Initialize the global monitor.
22
23 Also initializes the default target if sufficient arguments are supplied.
24 If they aren't, all created metrics will have to supply their own target.
25 This is generally a bad idea, as many libraries rely on the default target
26 being set up.
27
28 Starts a background thread to automatically flush monitoring metrics if not
29 disabled by arguments.
30
31 Args:
32 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
33 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
34 flush: metric push behavior: all (send every metric individually),
35 '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
36 'automatically every --ts-mon-flush-interval-secs seconds)
agable 2015/08/10 23:04:38 nit: another stray leading quote
37 flush_interval_secs: automatically push metrics on this interval if
38 --ts-mon-flush=auto
agable 2015/08/10 23:04:38 nit: remove reference to command line flag
39 job_name: name of the job instance of the task
40 number: number of instance for this task
41 service_name: name of service being monitored
42
43 """
44 hostname = socket.getfqdn().split('.')[0]
45 try:
46 region = fqdn.split('.')[1]
47 except:
48 region = ''
49
50 if endpoint.startswith('pubsub://'):
51 url = urlparse.urlparse(endpoint)
52 project = url.netloc
53 topic = url.path.strip('/')
54 interface.state.global_monitor = monitors.PubSubMonitor(project, topic)
55 else:
56 logging.error('Error: endpoint should begin with pubsub://')
57 interface.state.global_monitor = monitors.NullMonitor()
58
59 # Reimplement ArgumentParser.error, since we don't have access to the parser
60 if not service_name:
61 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
62 'provided when the target type is "task".')
63 sys.exit(2)
agable 2015/08/10 23:04:38 Eep don't sys.exit in appengine :)
64 if not job_name: # pragma: no cover
65 print >> sys.stderr, ('Argument --ts-mon-task-job-name must be provided '
agable 2015/08/10 23:04:38 Same re: logging here
66 'when the target type is "task".')
67 sys.exit(2)
68 interface.state.default_target = targets.TaskTarget(
69 service_name, job_name, region, hostname, number)
70
71 interface.state.flush_mode = flush
72
73 if flush == 'auto':
agable 2015/08/10 23:04:38 Remove 'auto', since I don't think it works on app
74 interface.state.flush_thread = interface._FlushThread(flush_interval_secs)
75 interface.state.flush_thread.start()
76
77 standard_metrics.init()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698