module/cpu: make ‘content’ particle a template

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
This commit is contained in:
Daniel Eklöf 2022-12-14 11:49:14 +01:00
parent 2e0e1a402f
commit b195bc4dcb
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 135 additions and 55 deletions

View file

@ -70,7 +70,7 @@ if plugin_clock_enabled
endif
if plugin_cpu_enabled
mod_data += {'cpu': [[], []]}
mod_data += {'cpu': [[], [dynlist]]}
endif
if plugin_disk_io_enabled