Skip to content

Commit 2bede02

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 2bede02

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/collectors/cpu/cpu.py

Lines changed: 9 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 and 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,16 @@ 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
97+
# set (in which case return both)
98+
if str_to_bool(self.config['simple']) or \
99+
str_to_bool(self.config['extended']):
96100
dt = cpu_delta_time(self.INTERVAL)
97101
cpuPct = 100 - (dt[len(dt) - 1] * 100.00 / sum(dt))
98102
self.publish('percent', str('%.4f' % cpuPct))
99-
return True
103+
# Only return simple metrics, unless the `extended` flag is set
104+
if not str_to_bool(self.config['extended']):
105+
return True
100106

101107
results = {}
102108
# Open file

0 commit comments

Comments
 (0)