Skip to content

Conversation

jcgl17
Copy link

@jcgl17 jcgl17 commented Aug 6, 2025

This PR follows up on #87. systemd_exporter already collects Task and IP Accounting metrics from systemd via dbus. This PR goes a step further to also collect IO, CPU, and Memory Accounting metrics.

The new metric names are noted in the README.

In my environment, this is preferable to deploying cAdvisor for at least a couple reasons:

  1. systemd_exporter's more minimal featureset and configuration options suit us better--we just need this additional information that systemd itself already exposes. Getting e.g. high-level memory usage is plenty for us.
  2. our team is already comfortable operating at the level of abstraction provided by systemd--services, slices, etc. We have some services that run under a specific parent slice, and it's useful for us to be able to look at both slice-wide and service-local metrics. Basically, it's useful to keep working with systemd's own abstractions, rather than going down a layer to cgroups.

unit, rather than service

Since systemd has accounting metrics for more units than just services, these new metrics are collected for all relevant unit types. They are accordingly named systemd_unit_* instead of systemd_service_*. The unit types this data is collected for are those noted in systemd.resource-control(5).

While this broader scope (no systemd .scope pun intended) for Accounting metrics would be relevant to the existing Task and IP Accounting metrics, I decided to leave them as-is to keep this PR's scope limited to adding new functionality. In the future, I do think it would make sense to modify collectServiceTasksMetrics() and collectIPAccountingMetrics() to work for these other unit types as well. Presumably, those metrics would keep their existing names (systemd_service_*) rather than changing the names; hard to imagine that breaking backwards compatibility would be worth the increased accuracy of a new name.

Task and IP Accounting metrics are now also collected for these unit types. The IP Accounting metrics are still called systemd_service_* instead of being changed to systemd_unit_* in order to preserve backwards compatibility.

minor tweak

The only change I've made to existing functionality is to not collect IP Accounting metrics that are null/unset (i.e. set to MaxUint64). This accords with existing behavior in the codebase, and seems like clearly the right thing to do--rather than creating useless/irrelevant labelsets.

dashboard

I've also taken a crack at adding these metrics to the dashboard that was mentioned here: https://grafana.com/grafana/dashboards/23844-systemd-exporter/

Edit: also added a multiselect dropdown for filtering units

other

I have a release with linux-amd64 built on my fork. It's just for my own use, but if anyone wants to quickly try out these changes without needing to build themselves, feel free to use it.

jcgl17 added 3 commits August 6, 2025 13:36
This metric is available for every all units with resource control
(those types listed in `systemd.resource-control(5)`).

Also broaden collection of `systemd_unit_memory_bytes` for all
executable units, rather than just .service units.

Signed-off-by: j <[email protected]>
@jcgl17 jcgl17 force-pushed the feature/cgroup-metrics branch from 80e1e8e to 584db73 Compare August 6, 2025 11:37
@jcgl17 jcgl17 force-pushed the feature/cgroup-metrics branch 3 times, most recently from c3ef5d5 to 8680dea Compare August 19, 2025 22:13
@jcgl17 jcgl17 force-pushed the feature/cgroup-metrics branch from 8680dea to 1d9cf56 Compare August 19, 2025 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants