Before this patch, the cpu module instantiated a single particle (the
‘content’ particle), with one tag ("cpu") representing the total CPU
usage, and then one tag (cpuN) for each core.
This makes it cumbersome to configure, since you need to explicitly
reference each cpuN tag to get per-core usage.
This patch rewrites this, so that ‘content’ is now a template. It’s
instantiated once to represent the total CPU usage, and then once for
each core.
Each instance has a "cpu" tag, representing the CPU usage of that
core (or total usage). It also has an "id" tag. The ID is 0..n for
actual cores, and -1 for total usage.
This means you can do something like this in your config:
- cpu:
content:
map:
conditions:
id < 0: {string: {text: "Total: {cpu}%"}}
id >= 0: {string: {text: "Core #{id}: {cpu}%"}}
Closes#207
/proc/stat lists CPU usage, in the form:
cpu ...
cpu0 ...
cpu1 ...
...
cpuN ...
where the first line is a summary line. We’ve been using the CPU
numbers from /proc/stat to index into our internal stats array.
This doesn’t work on systems where the core IDs aren’t
consecutive. Examples of such systems are SMT systems with SMT
disabled. Here, /proc/stat may look like this instead:
cpu ...
cpu0 ...
cpu2 ...
cpu4 ...
...
With this patch, we ignore the CPU ID from /proc/stat. Instead, we use
a simple counter that is incremented for each (valid) cpu line found
in /proc/stat. To protect against corrupt /proc/stat content, stop
parsing /proc/stat if the number of parsed CPU lines exceed what we
consider to the be total number of CPUs in the system.
Closes#172