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

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

Issue 2520873003: Count instances managed by each instance template (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | appengine/gce-backend/metrics.py » ('j') | appengine/gce-backend/metrics.py » ('J')
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 """Utilities for operating on instance group managers.""" 5 """Utilities for operating on instance group managers."""
6 6
7 import collections
7 import logging 8 import logging
8 9
9 from google.appengine.ext import ndb 10 from google.appengine.ext import ndb
10 11
11 from components import gce 12 from components import gce
12 from components import net 13 from components import net
13 from components import utils 14 from components import utils
14 15
15 import instance_templates 16 import instance_templates
16 import models 17 import models
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 '/internal/queues/resize-instance-group', 384 '/internal/queues/resize-instance-group',
384 'resize-instance-group', 385 'resize-instance-group',
385 params={ 386 params={
386 'key': instance_group_manager_key.urlsafe(), 387 'key': instance_group_manager_key.urlsafe(),
387 }, 388 },
388 ): 389 ):
389 logging.warning( 390 logging.warning(
390 'Failed to enqueue task for InstanceGroupManager: %s', 391 'Failed to enqueue task for InstanceGroupManager: %s',
391 instance_group_manager_key, 392 instance_group_manager_key,
392 ) 393 )
394
395
396 def count_instances():
397 """Counts the number of instances owned by each instance template.
398
399 Returns:
400 A dict mapping instance template name to count of instances.
401 """
402 # Aggregate the number of instances owned by each instance group manager
403 # created for each instance template.
404 totals = collections.defaultdict(int)
405 for instance_group_manager in models.InstanceGroupManager.query():
406 instance_template_name = instance_group_manager.key.parent().parent().id()
407 totals[instance_template_name] += len(instance_group_manager.instances)
408 return totals
OLDNEW
« no previous file with comments | « no previous file | appengine/gce-backend/metrics.py » ('j') | appengine/gce-backend/metrics.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698