| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import socket | 8 import socket |
| 9 import sys | 9 import sys |
| 10 import urlparse | 10 import urlparse |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 parser.add_argument( | 152 parser.add_argument( |
| 153 '--ts-mon-task-hostname', | 153 '--ts-mon-task-hostname', |
| 154 default=host, | 154 default=host, |
| 155 help='name of the host on which this task is running ' | 155 help='name of the host on which this task is running ' |
| 156 '(default: %(default)s)') | 156 '(default: %(default)s)') |
| 157 parser.add_argument( | 157 parser.add_argument( |
| 158 '--ts-mon-task-number', type=int, default=0, | 158 '--ts-mon-task-number', type=int, default=0, |
| 159 help='number (e.g. for replication) of this instance of this task ' | 159 help='number (e.g. for replication) of this instance of this task ' |
| 160 '(default: %(default)s)') | 160 '(default: %(default)s)') |
| 161 | 161 |
| 162 parser.add_argument( |
| 163 '--ts-mon-metric-name-prefix', |
| 164 default='/chrome/infra/', |
| 165 help='metric name prefix for all metrics (default: %(default)s)') |
| 162 | 166 |
| 163 def process_argparse_options(args): | 167 def process_argparse_options(args): |
| 164 """Process command line arguments to initialize the global monitor. | 168 """Process command line arguments to initialize the global monitor. |
| 165 | 169 |
| 166 Also initializes the default target. | 170 Also initializes the default target. |
| 167 | 171 |
| 168 Starts a background thread to automatically flush monitoring metrics if not | 172 Starts a background thread to automatically flush monitoring metrics if not |
| 169 disabled by command line arguments. | 173 disabled by command line arguments. |
| 170 | 174 |
| 171 Args: | 175 Args: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 hostname = args.ts_mon_task_hostname | 209 hostname = args.ts_mon_task_hostname |
| 206 if args.ts_mon_autogen_hostname or autogen_hostname: | 210 if args.ts_mon_autogen_hostname or autogen_hostname: |
| 207 hostname = 'autogen:' + hostname | 211 hostname = 'autogen:' + hostname |
| 208 interface.state.target = targets.TaskTarget( | 212 interface.state.target = targets.TaskTarget( |
| 209 args.ts_mon_task_service_name, | 213 args.ts_mon_task_service_name, |
| 210 args.ts_mon_task_job_name, | 214 args.ts_mon_task_job_name, |
| 211 args.ts_mon_task_region, | 215 args.ts_mon_task_region, |
| 212 hostname, | 216 hostname, |
| 213 args.ts_mon_task_number) | 217 args.ts_mon_task_number) |
| 214 | 218 |
| 219 interface.state.metric_name_prefix = args.ts_mon_metric_name_prefix |
| 215 interface.state.global_monitor = monitors.NullMonitor() | 220 interface.state.global_monitor = monitors.NullMonitor() |
| 216 | 221 |
| 217 if endpoint.startswith('file://'): | 222 if endpoint.startswith('file://'): |
| 218 interface.state.global_monitor = monitors.DebugMonitor( | 223 interface.state.global_monitor = monitors.DebugMonitor( |
| 219 endpoint[len('file://'):]) | 224 endpoint[len('file://'):]) |
| 220 elif endpoint.startswith('pubsub://'): | 225 elif endpoint.startswith('pubsub://'): |
| 221 if credentials: | 226 if credentials: |
| 222 url = urlparse.urlparse(endpoint) | 227 url = urlparse.urlparse(endpoint) |
| 223 project = url.netloc | 228 project = url.netloc |
| 224 topic = url.path.strip('/') | 229 topic = url.path.strip('/') |
| 225 interface.state.global_monitor = monitors.PubSubMonitor( | 230 interface.state.global_monitor = monitors.PubSubMonitor( |
| 226 credentials, project, topic, use_instrumented_http=True) | 231 credentials, project, topic, use_instrumented_http=True) |
| 227 else: | 232 else: |
| 228 logging.error('ts_mon monitoring is disabled because credentials are not ' | 233 logging.error('ts_mon monitoring is disabled because credentials are not ' |
| 229 'available') | 234 'available') |
| 230 elif endpoint.lower() == 'none': | 235 elif endpoint.lower() == 'none': |
| 231 logging.info('ts_mon monitoring has been explicitly disabled') | 236 logging.info('ts_mon monitoring has been explicitly disabled') |
| 232 else: | 237 else: |
| 233 logging.error('ts_mon monitoring is disabled because the endpoint provided' | 238 logging.error('ts_mon monitoring is disabled because the endpoint provided' |
| 234 ' is invalid or not supported: %s', endpoint) | 239 ' is invalid or not supported: %s', endpoint) |
| 235 | 240 |
| 236 interface.state.flush_mode = args.ts_mon_flush | 241 interface.state.flush_mode = args.ts_mon_flush |
| 237 | 242 |
| 238 if args.ts_mon_flush == 'auto': | 243 if args.ts_mon_flush == 'auto': |
| 239 interface.state.flush_thread = interface._FlushThread( | 244 interface.state.flush_thread = interface._FlushThread( |
| 240 args.ts_mon_flush_interval_secs) | 245 args.ts_mon_flush_interval_secs) |
| 241 interface.state.flush_thread.start() | 246 interface.state.flush_thread.start() |
| 242 | 247 |
| 243 standard_metrics.init() | 248 standard_metrics.init() |
| OLD | NEW |