Skip to content

Commit 1de5dd5

Browse files
author
Scott Cunningham
committed
Add extended flag to CPU collector
This allows us to produce both simple and complex metrics - this way, simple metrics can be aggregated, but we still have the option to drill-down into per-host metrics in situations that require them (eg. checking steal on an individual VM)
1 parent f4a523f commit 1de5dd5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/collectors/cpu/cpu.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def get_default_config_help(self):
4343
config_help.update({
4444
'percore': 'Collect metrics per cpu core or just total',
4545
'simple': 'only return aggregate CPU% metric',
46+
'extended': 'return aggregate CPU% metric but also complex CPU metrics',
4647
'normalize': 'for cpu totals, divide by the number of CPUs',
4748
})
4849
return config_help
@@ -57,6 +58,7 @@ def get_default_config(self):
5758
'percore': 'True',
5859
'xenfix': None,
5960
'simple': 'False',
61+
'extended': 'False',
6062
'normalize': 'False',
6163
})
6264
return config
@@ -91,12 +93,14 @@ def cpu_delta_time(interval):
9193

9294
if os.access(self.PROC, os.R_OK):
9395

94-
# If simple only return aggregate CPU% metric
95-
if str_to_bool(self.config['simple']):
96+
# If simple only return aggregate CPU% metric, unless extended is set (in which case return both)
97+
if str_to_bool(self.config['simple']) or str_to_bool(self.config['extended']):
9698
dt = cpu_delta_time(self.INTERVAL)
9799
cpuPct = 100 - (dt[len(dt) - 1] * 100.00 / sum(dt))
98100
self.publish('percent', str('%.4f' % cpuPct))
99-
return True
101+
# Only return simple CPU metrics, unless the `extended` flag is set
102+
if not str_to_bool(self.config['extended']):
103+
return True
100104

101105
results = {}
102106
# Open file

0 commit comments

Comments
 (0)