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

Side by Side Diff: appengine/gce-backend/metrics.py

Issue 2705153007: Count configured minimum and maximum numbers of instances (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « appengine/gce-backend/config.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Metrics to track with ts_mon and event_mon.""" 5 """Metrics to track with ts_mon and event_mon."""
6 6
7 import logging 7 import logging
8 8
9 import gae_event_mon 9 import gae_event_mon
10 import gae_ts_mon 10 import gae_ts_mon
11 11
12 import config
12 import instance_group_managers 13 import instance_group_managers
13 14
14 15
15 # Overrides to create app-global metrics. 16 # Overrides to create app-global metrics.
16 GLOBAL_TARGET_FIELDS = { 17 GLOBAL_TARGET_FIELDS = {
17 # Name of the module reporting the metric. 18 # Name of the module reporting the metric.
18 'job_name': '', 19 'job_name': '',
19 # Version of the app reporting the metric. 20 # Version of the app reporting the metric.
20 'hostname': '', 21 'hostname': '',
21 # ID of the instance reporting the metric. 22 # ID of the instance reporting the metric.
22 'task_num': 0, 23 'task_num': 0,
23 } 24 }
24 25
25 26
26 GLOBAL_METRICS = { 27 GLOBAL_METRICS = {
28 'config_max_instances': gae_ts_mon.GaugeMetric(
29 'machine_provider/gce_backend/config/instances/max',
30 description='Maximum number of instances currently configured.',
31 ),
32 'config_min_instances': gae_ts_mon.GaugeMetric(
33 'machine_provider/gce_backend/config/instances/min',
34 description='Minimum number of instances currently configured.',
35 ),
27 'instances': gae_ts_mon.GaugeMetric( 36 'instances': gae_ts_mon.GaugeMetric(
28 'machine_provider/gce_backend/instances', 37 'machine_provider/gce_backend/instances',
29 description='Current count of the number of instances.', 38 description='Current count of the number of instances.',
30 ), 39 ),
31 } 40 }
32 41
33 42
34 config_valid = gae_ts_mon.BooleanMetric( 43 config_valid = gae_ts_mon.BooleanMetric(
35 'machine_provider/gce_backend/config/valid', 44 'machine_provider/gce_backend/config/valid',
36 description='Whether or not the current config is valid.', 45 description='Whether or not the current config is valid.',
37 ) 46 )
38 47
39 48
40 def compute_global_metrics(): # pragma: no cover 49 def compute_global_metrics(): # pragma: no cover
50 for name, counts in config.count_instances().iteritems():
51 logging.info('%s min: %s', name, counts[0])
52 GLOBAL_METRICS['config_min_instances'].set(
53 counts[0],
54 fields={
55 'instance_template': name,
56 },
57 target_fields=GLOBAL_TARGET_FIELDS,
58 )
59 logging.info('%s max: %s', name, counts[1])
60 GLOBAL_METRICS['config_max_instances'].set(
61 counts[1],
62 fields={
63 'instance_template': name,
64 },
65 target_fields=GLOBAL_TARGET_FIELDS,
66 )
67
41 for name, count in instance_group_managers.count_instances().iteritems(): 68 for name, count in instance_group_managers.count_instances().iteritems():
42 logging.info('%s: %s', name, count) 69 logging.info('%s: %s', name, count)
43 GLOBAL_METRICS['instances'].set( 70 GLOBAL_METRICS['instances'].set(
44 count, 71 count,
45 fields={ 72 fields={
46 'instance_template': name, 73 'instance_template': name,
47 }, 74 },
48 target_fields=GLOBAL_TARGET_FIELDS, 75 target_fields=GLOBAL_TARGET_FIELDS,
49 ) 76 )
50 77
(...skipping 10 matching lines...) Expand all
61 Args: 88 Args:
62 state: gae_event_mon.ChromeInfraEvent.GCEBackendMachineState. 89 state: gae_event_mon.ChromeInfraEvent.GCEBackendMachineState.
63 hostname: Name of the GCE instance this event is for. 90 hostname: Name of the GCE instance this event is for.
64 """ 91 """
65 state = gae_event_mon.MachineProviderEvent.GCEBackendMachineState.Value(state) 92 state = gae_event_mon.MachineProviderEvent.GCEBackendMachineState.Value(state)
66 event = gae_event_mon.Event('POINT') 93 event = gae_event_mon.Event('POINT')
67 event.proto.event_source.host_name = hostname 94 event.proto.event_source.host_name = hostname
68 event.proto.machine_provider_event.gce_backend_state = state 95 event.proto.machine_provider_event.gce_backend_state = state
69 logging.info('Sending event: %s', event.proto) 96 logging.info('Sending event: %s', event.proto)
70 event.send() 97 event.send()
OLDNEW
« no previous file with comments | « appengine/gce-backend/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698