Mark Bergsma has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53346
Change subject: Handle average (sum/count) values properly
......................................................................
Handle average (sum/count) values properly
Change-Id: I852d711029d8103d66143e73928d2e0e755ea09e
---
M files/ganglia/plugins/ceph.py
1 file changed, 22 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/46/53346/1
diff --git a/files/ganglia/plugins/ceph.py b/files/ganglia/plugins/ceph.py
index f299624..f0bbd56 100644
--- a/files/ganglia/plugins/ceph.py
+++ b/files/ganglia/plugins/ceph.py
@@ -10,6 +10,7 @@
import json, os, sys
stats_cache = {}
+prev_values = {}
metric_types = {}
ceph_path = "/usr/bin/ceph"
@@ -43,34 +44,41 @@
'slope': ( counter and "positive" or
"both" ),
'format': ( valtype == "uint" and r'%u'
or r'%f' ),
'description': "%s %s" %
(section.encode('ascii'), metric.encode('ascii')),
- 'groups': "ceph " + instance
+ 'groups': "ceph osd " + instance
}
metrics.append(metric_properties)
return metrics
def get_value(metric):
- global stats_cache, metric_types
+ global stats_cache, prev_values, metric_types
instance, section, metric_name = metric.split('.', 2)
- try:
- stats_cache[instance][section][metric_name]
- except KeyError:
- get_stats()
t = metric_types[instance][section][metric_name]['type']
+ try:
+ v = stats_cache[instance][section].pop(metric_name)
+ except KeyError:
+ get_stats()
+ v = stats_cache[instance][section].pop(metric_name)
+
if t & 0b100 > 0:
# Average
try:
- values = stats_cache[instance][section].pop(metric_name)
- if t & 1 == 1:
- return float(values['sum'] / values['avgcount'])
- else:
- return int(values['sum'] / values['avgcount'])
- except:
- return 0
+ p = prev_values[instance][section][metric_name]
+ r = (v['sum'] - p['sum']) / (v['avgcount'] -
p['avgcount'])
+ except KeyError:
+ r = 0
+ finally:
+ prev_values.setdefault(instance,
{}).setdefault(section, {})[metric_name] = v
else:
- return stats_cache[instance][section].pop(metric_name, 0)
+ r = v
+
+ if t & 1 == 1:
+ return float(r)
+ else:
+ return int(r)
+
def get_stats():
global stats_cache, instances
--
To view, visit https://gerrit.wikimedia.org/r/53346
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I852d711029d8103d66143e73928d2e0e755ea09e
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Mark Bergsma <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits