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

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

Issue 2520873003: Count instances managed by each instance template (Closed)
Patch Set: Created 4 years 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/instance_group_managers.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 instance_group_managers
12 import instances 13 import instances
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 = {
27 'instances': gae_ts_mon.GaugeMetric( 28 'instances': gae_ts_mon.GaugeMetric(
28 'machine_provider/gce_backend/instances', 29 'machine_provider/gce_backend/instances',
29 description='Current count of the number of instances.', 30 description='Current count of the number of instances.',
30 ), 31 ),
32 'instances/v2': gae_ts_mon.GaugeMetric(
33 'machine_provider/gce_backend/instances/v2',
Sergey Berezin (google) 2016/11/23 02:28:25 I'd name it in a more self-descriptive way, e.g. .
smut 2016/11/23 22:50:57 I tried modifying the existing metric and the metr
Sergey Berezin (google) 2016/11/23 23:42:44 No, the field schema should be consistent globally
smut 2016/11/23 23:51:09 No, I don't care about the history. I would prefer
Sergey Berezin (google) 2016/11/24 03:51:47 Great, I deleted the metric - once the update prop
34 description='Current count of the number of instances.',
35 ),
31 } 36 }
32 37
33 38
34 config_valid = gae_ts_mon.BooleanMetric( 39 config_valid = gae_ts_mon.BooleanMetric(
35 'machine_provider/gce_backend/config/valid', 40 'machine_provider/gce_backend/config/valid',
36 description='Whether or not the current config is valid.', 41 description='Whether or not the current config is valid.',
37 ) 42 )
38 43
39 44
40 def compute_global_metrics(): 45 def compute_global_metrics():
41 orphaned, total = instances.count_instances() 46 orphaned, total = instances.count_instances()
42 GLOBAL_METRICS['instances'].set( 47 GLOBAL_METRICS['instances'].set(
43 orphaned, 48 orphaned,
44 fields={ 49 fields={
45 'orphaned': True, 50 'orphaned': True,
46 }, 51 },
47 target_fields=GLOBAL_TARGET_FIELDS, 52 target_fields=GLOBAL_TARGET_FIELDS,
48 ) 53 )
49 GLOBAL_METRICS['instances'].set( 54 GLOBAL_METRICS['instances'].set(
50 total - orphaned, 55 total - orphaned,
51 fields={ 56 fields={
52 'orphaned': False, 57 'orphaned': False,
53 }, 58 },
54 target_fields=GLOBAL_TARGET_FIELDS, 59 target_fields=GLOBAL_TARGET_FIELDS,
55 ) 60 )
61 for name, count in instance_group_managers.count_instances().iteritems():
62 logging.info('%s: %s', name, count)
63 GLOBAL_METRICS['instances/v2'].set(
64 count,
65 fields={
66 'instance_template': name,
67 },
68 target_fields=GLOBAL_TARGET_FIELDS,
69 )
56 70
57 71
58 def initialize(): 72 def initialize():
59 gae_ts_mon.register_global_metrics(GLOBAL_METRICS.values()) 73 gae_ts_mon.register_global_metrics(GLOBAL_METRICS.values())
60 gae_ts_mon.register_global_metrics_callback( 74 gae_ts_mon.register_global_metrics_callback(
61 'callback', compute_global_metrics) 75 'callback', compute_global_metrics)
62 76
63 77
64 def send_machine_event(state, hostname): 78 def send_machine_event(state, hostname):
65 """Sends an event_mon event about a GCE instance. 79 """Sends an event_mon event about a GCE instance.
66 80
67 Args: 81 Args:
68 state: gae_event_mon.ChromeInfraEvent.GCEBackendMachineState. 82 state: gae_event_mon.ChromeInfraEvent.GCEBackendMachineState.
69 hostname: Name of the GCE instance this event is for. 83 hostname: Name of the GCE instance this event is for.
70 """ 84 """
71 state = gae_event_mon.MachineProviderEvent.GCEBackendMachineState.Value(state) 85 state = gae_event_mon.MachineProviderEvent.GCEBackendMachineState.Value(state)
72 event = gae_event_mon.Event('POINT') 86 event = gae_event_mon.Event('POINT')
73 event.proto.event_source.host_name = hostname 87 event.proto.event_source.host_name = hostname
74 event.proto.machine_provider_event.gce_backend_state = state 88 event.proto.machine_provider_event.gce_backend_state = state
75 logging.info('Sending event: %s', event.proto) 89 logging.info('Sending event: %s', event.proto)
76 event.send() 90 event.send()
OLDNEW
« no previous file with comments | « appengine/gce-backend/instance_group_managers.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698