From 7e0c42d03570206f937f896468484b5ce882ea82 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 24 Feb 2014 17:24:56 -0800 Subject: [PATCH] Roll up node stats As the number of providers and targets grows, the number of stats that graphite has to sum in order to produce the summary graphs that we use grows. Instead of asking graphite to summarize something like 400 metrics (takes about 3 seconds), have nodepool directly produce the metrics that we are going to use. Change-Id: I2a7403af2512ace0cbe795f2ec17ebcd9b90dd09 --- nodepool/nodepool.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/nodepool/nodepool.py b/nodepool/nodepool.py index 18b58d5b0..306c1402a 100644 --- a/nodepool/nodepool.py +++ b/nodepool/nodepool.py @@ -1367,32 +1367,44 @@ class NodePool(threading.Thread): states = {} + #nodepool.target.TARGET.IMAGE.min_ready + #nodepool.target.TARGET.IMAGE.PROVIDER.STATE + #nodepool.target.STATE + base_key = 'nodepool.target' for target in self.config.targets.values(): + target_key = '%s.%s' % (base_key, target.name) for image in target.images.values(): - image_key = 'nodepool.target.%s.%s' % ( - target.name, image.name) + image_key = '%s.%s' % (target_key, image.name) key = '%s.min_ready' % image_key statsd.gauge(key, image.min_ready) for provider in image.providers.values(): - provider_key = '%s.%s' % ( - image_key, provider.name) + provider_key = '%s.%s' % (image_key, provider.name) for state in nodedb.STATE_NAMES.values(): - key = '%s.%s' % (provider_key, state) - states[key] = 0 + base_state_key = '%s.%s' % (base_key, state) + provider_state_key = '%s.%s' % (provider_key, state) + for key in [base_state_key, provider_state_key]: + states[key] = 0 for node in session.getNodes(): if node.state not in nodedb.STATE_NAMES: continue - key = 'nodepool.target.%s.%s.%s.%s' % ( - node.target_name, node.image_name, - node.provider_name, nodedb.STATE_NAMES[node.state]) - if key not in states: - states[key] = 0 - states[key] += 1 + state = nodedb.STATE_NAMES[node.state] + target_key = '%s.%s' % (base_key, node.target_name) + image_key = '%s.%s' % (target_key, node.image_name) + provider_key = '%s.%s' % (image_key, node.provider_name) + + base_state_key = '%s.%s' % (base_key, state) + provider_state_key = '%s.%s' % (provider_key, state) + + for key in [base_state_key, provider_state_key]: + if key not in states: + states[key] = 0 + states[key] += 1 for key, count in states.items(): statsd.gauge(key, count) + #nodepool.provider.PROVIDER.max_servers for provider in self.config.providers.values(): key = 'nodepool.provider.%s.max_servers' % provider.name statsd.gauge(key, provider.max_servers)