| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 parser.add_argument( | 76 parser.add_argument( |
| 77 '--ts-mon-config-file', | 77 '--ts-mon-config-file', |
| 78 default=default_config_file, | 78 default=default_config_file, |
| 79 help='path to a JSON config file that contains suitable values for ' | 79 help='path to a JSON config file that contains suitable values for ' |
| 80 '"endpoint" and "credentials" for this machine. This config file is ' | 80 '"endpoint" and "credentials" for this machine. This config file is ' |
| 81 'intended to be shared by all processes on the machine, as the ' | 81 'intended to be shared by all processes on the machine, as the ' |
| 82 'values depend on the machine\'s position in the network, IP ' | 82 'values depend on the machine\'s position in the network, IP ' |
| 83 'whitelisting and deployment of credentials. (default: %(default)s)') | 83 'whitelisting and deployment of credentials. (default: %(default)s)') |
| 84 parser.add_argument( | 84 parser.add_argument( |
| 85 '--ts-mon-endpoint', | 85 '--ts-mon-endpoint', |
| 86 help='url (including file://, pubsub://project/topic, https://) to post ' | 86 help='url (file:// or https://) to post monitoring metrics to. If set, ' |
| 87 'monitoring metrics to. If set, overrides the value in ' | 87 'overrides the value in --ts-mon-config-file') |
| 88 '--ts-mon-config-file') | |
| 89 parser.add_argument( | 88 parser.add_argument( |
| 90 '--ts-mon-credentials', | 89 '--ts-mon-credentials', |
| 91 help='path to a pkcs8 json credential file. If set, overrides the value ' | 90 help='path to a pkcs8 json credential file. If set, overrides the value ' |
| 92 'in --ts-mon-config-file') | 91 'in --ts-mon-config-file') |
| 93 parser.add_argument( | 92 parser.add_argument( |
| 94 '--ts-mon-ca-certs', | 93 '--ts-mon-ca-certs', |
| 95 help='path to file containing root CA certificates for SSL server ' | 94 help='path to file containing root CA certificates for SSL server ' |
| 96 'certificate validation. If not set, a CA cert file bundled with ' | 95 'certificate validation. If not set, a CA cert file bundled with ' |
| 97 'httplib2 is used.') | 96 'httplib2 is used.') |
| 98 parser.add_argument( | 97 parser.add_argument( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 help='number (e.g. for replication) of this instance of this task ' | 164 help='number (e.g. for replication) of this instance of this task ' |
| 166 '(default: %(default)s)') | 165 '(default: %(default)s)') |
| 167 | 166 |
| 168 parser.add_argument( | 167 parser.add_argument( |
| 169 '--ts-mon-metric-name-prefix', | 168 '--ts-mon-metric-name-prefix', |
| 170 default='/chrome/infra/', | 169 default='/chrome/infra/', |
| 171 help='metric name prefix for all metrics (default: %(default)s)') | 170 help='metric name prefix for all metrics (default: %(default)s)') |
| 172 | 171 |
| 173 parser.add_argument( | 172 parser.add_argument( |
| 174 '--ts-mon-use-new-proto', | 173 '--ts-mon-use-new-proto', |
| 175 default=False, action='store_true', | 174 default=True, action='store_true', |
| 176 help='use the new proto schema (default: false)') | 175 help='deprecated and ignored') |
| 177 | 176 |
| 178 | 177 |
| 179 def process_argparse_options(args): | 178 def process_argparse_options(args): |
| 180 """Process command line arguments to initialize the global monitor. | 179 """Process command line arguments to initialize the global monitor. |
| 181 | 180 |
| 182 Also initializes the default target. | 181 Also initializes the default target. |
| 183 | 182 |
| 184 Starts a background thread to automatically flush monitoring metrics if not | 183 Starts a background thread to automatically flush monitoring metrics if not |
| 185 disabled by command line arguments. | 184 disabled by command line arguments. |
| 186 | 185 |
| 187 Args: | 186 Args: |
| 188 args (argparse.Namespace): the result of parsing the command line arguments | 187 args (argparse.Namespace): the result of parsing the command line arguments |
| 189 """ | 188 """ |
| 190 # Parse the config file if it exists. | 189 # Parse the config file if it exists. |
| 191 config = load_machine_config(args.ts_mon_config_file) | 190 config = load_machine_config(args.ts_mon_config_file) |
| 192 endpoint = config.get('endpoint', '') | 191 endpoint = config.get('endpoint', '') |
| 193 credentials = config.get('credentials', '') | 192 credentials = config.get('credentials', '') |
| 194 autogen_hostname = config.get('autogen_hostname', False) | 193 autogen_hostname = config.get('autogen_hostname', False) |
| 195 use_new_proto = config.get('use_new_proto', False) | |
| 196 | 194 |
| 197 # Command-line args override the values in the config file. | 195 # Command-line args override the values in the config file. |
| 198 if args.ts_mon_endpoint is not None: | 196 if args.ts_mon_endpoint is not None: |
| 199 endpoint = args.ts_mon_endpoint | 197 endpoint = args.ts_mon_endpoint |
| 200 if args.ts_mon_credentials is not None: | 198 if args.ts_mon_credentials is not None: |
| 201 credentials = args.ts_mon_credentials | 199 credentials = args.ts_mon_credentials |
| 202 if args.ts_mon_use_new_proto: | |
| 203 use_new_proto = args.ts_mon_use_new_proto | |
| 204 | 200 |
| 205 if args.ts_mon_target_type == 'device': | 201 if args.ts_mon_target_type == 'device': |
| 206 hostname = args.ts_mon_device_hostname | 202 hostname = args.ts_mon_device_hostname |
| 207 if args.ts_mon_autogen_hostname or autogen_hostname: | 203 if args.ts_mon_autogen_hostname or autogen_hostname: |
| 208 hostname = 'autogen:' + hostname | 204 hostname = 'autogen:' + hostname |
| 209 interface.state.target = targets.DeviceTarget( | 205 interface.state.target = targets.DeviceTarget( |
| 210 args.ts_mon_device_region, | 206 args.ts_mon_device_region, |
| 211 args.ts_mon_device_role, | 207 args.ts_mon_device_role, |
| 212 args.ts_mon_device_network, | 208 args.ts_mon_device_network, |
| 213 hostname) | 209 hostname) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 230 args.ts_mon_task_region, | 226 args.ts_mon_task_region, |
| 231 hostname, | 227 hostname, |
| 232 args.ts_mon_task_number) | 228 args.ts_mon_task_number) |
| 233 | 229 |
| 234 interface.state.metric_name_prefix = args.ts_mon_metric_name_prefix | 230 interface.state.metric_name_prefix = args.ts_mon_metric_name_prefix |
| 235 interface.state.global_monitor = monitors.NullMonitor() | 231 interface.state.global_monitor = monitors.NullMonitor() |
| 236 | 232 |
| 237 if endpoint.startswith('file://'): | 233 if endpoint.startswith('file://'): |
| 238 interface.state.global_monitor = monitors.DebugMonitor( | 234 interface.state.global_monitor = monitors.DebugMonitor( |
| 239 endpoint[len('file://'):]) | 235 endpoint[len('file://'):]) |
| 240 elif endpoint.startswith('pubsub://'): | |
| 241 if credentials: | |
| 242 url = urlparse.urlparse(endpoint) | |
| 243 project = url.netloc | |
| 244 topic = url.path.strip('/') | |
| 245 interface.state.global_monitor = monitors.PubSubMonitor( | |
| 246 monitors.CredentialFactory.from_string(credentials), project, topic, | |
| 247 use_instrumented_http=True, ca_certs=args.ts_mon_ca_certs) | |
| 248 else: | |
| 249 logging.error('ts_mon monitoring is disabled because credentials are not ' | |
| 250 'available') | |
| 251 elif endpoint.startswith('https://'): | 236 elif endpoint.startswith('https://'): |
| 252 interface.state.global_monitor = monitors.HttpsMonitor( | 237 interface.state.global_monitor = monitors.HttpsMonitor( |
| 253 endpoint, monitors.CredentialFactory.from_string(credentials), | 238 endpoint, monitors.CredentialFactory.from_string(credentials), |
| 254 ca_certs=args.ts_mon_ca_certs) | 239 ca_certs=args.ts_mon_ca_certs) |
| 255 elif endpoint.lower() == 'none': | 240 elif endpoint.lower() == 'none': |
| 256 logging.info('ts_mon monitoring has been explicitly disabled') | 241 logging.info('ts_mon monitoring has been explicitly disabled') |
| 257 else: | 242 else: |
| 258 logging.error('ts_mon monitoring is disabled because the endpoint provided' | 243 logging.error('ts_mon monitoring is disabled because the endpoint provided' |
| 259 ' is invalid or not supported: %s', endpoint) | 244 ' is invalid or not supported: %s', endpoint) |
| 260 | 245 |
| 261 interface.state.flush_mode = args.ts_mon_flush | 246 interface.state.flush_mode = args.ts_mon_flush |
| 262 interface.state.use_new_proto = use_new_proto | |
| 263 | 247 |
| 264 if args.ts_mon_flush == 'auto': | 248 if args.ts_mon_flush == 'auto': |
| 265 interface.state.flush_thread = interface._FlushThread( | 249 interface.state.flush_thread = interface._FlushThread( |
| 266 args.ts_mon_flush_interval_secs) | 250 args.ts_mon_flush_interval_secs) |
| 267 interface.state.flush_thread.start() | 251 interface.state.flush_thread.start() |
| 268 | 252 |
| 269 standard_metrics.init() | 253 standard_metrics.init() |
| 270 | 254 |
| OLD | NEW |