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

Unified Diff: appengine/gce-backend/instance_group_managers.py

Issue 2520873003: Count instances managed by each instance template (Closed)
Patch Set: Replace old metric with new 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/gce-backend/instances.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/gce-backend/instance_group_managers.py
diff --git a/appengine/gce-backend/instance_group_managers.py b/appengine/gce-backend/instance_group_managers.py
index d8a02633489062d8237ccbf665bb2f9118cd0479..2f993a4865994ec54a97b5f548c96a4281db407e 100644
--- a/appengine/gce-backend/instance_group_managers.py
+++ b/appengine/gce-backend/instance_group_managers.py
@@ -4,6 +4,7 @@
"""Utilities for operating on instance group managers."""
+import collections
import logging
from google.appengine.ext import ndb
@@ -390,3 +391,18 @@ def schedule_resize():
'Failed to enqueue task for InstanceGroupManager: %s',
instance_group_manager_key,
)
+
+
+def count_instances():
+ """Counts the number of instances owned by each instance template.
+
+ Returns:
+ A dict mapping instance template name to count of instances.
+ """
+ # Aggregate the number of instances owned by each instance group manager
+ # created for each instance template.
+ totals = collections.defaultdict(int)
+ for instance_group_manager in models.InstanceGroupManager.query():
+ instance_template_name = instance_group_manager.key.parent().parent().id()
+ totals[instance_template_name] += len(instance_group_manager.instances)
+ return totals
« no previous file with comments | « no previous file | appengine/gce-backend/instances.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698