]> git.ipfire.org Git - thirdparty/systemd.git/commit
[metrics] Add basic system wide and per unit metrics
authorYaping Li <202858510+YapingLi04@users.noreply.github.com>
Tue, 21 Oct 2025 01:25:10 +0000 (18:25 -0700)
committerYaping Li <202858510+YapingLi04@users.noreply.github.com>
Mon, 2 Feb 2026 16:03:56 +0000 (08:03 -0800)
commitbb1ef2edf7d62de35291702635067ee85f09bad5
tree2be3daf5bf94d8b6619a60c48cf006189b8fa8af
parentfd73cd6c912a4d31f404d54700654d8398ea8f27
[metrics] Add basic system wide and per unit metrics

This commit adds some basic metrics and integration tests.

System wide metrics:
- units_by_type_total: target/device/automount etc.
- units_by_state_total: active/reloading/inactive etc.

Two per unit metrics which shows the current state of a unit:
- unit_active_state
- unit_load_state

A metric for service state:
- nrestarts

Here are some sample outputs:

units_by_type_total:

{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 52,
        "fields" : {
                "type" : "target"
        }
}
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 82,
        "fields" : {
                "type" : "device"
        }
}
{
        "name" : "io.systemd.Manager.units_by_type_total",
        "value" : 2,
        "fields" : {
                "type" : "automount"
        }
}

units_by_state_total:

{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 216,
        "fields" : {
                "state" : "active"
        }
}
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 0,
        "fields" : {
                "state" : "reloading"
        }
}
{
        "name" : "io.systemd.Manager.units_by_state_total",
        "value" : 120,
        "fields" : {
                "state" : "inactive"
        }
}

unit_active_state:

{
        "name" : "io.systemd.Manager.unit_active_state",
        "object" : "multi-user.target",
        "value" : "active"
}
{
        "name" : "io.systemd.Manager.unit_active_state",
        "object" : "systemd-sysusers.service",
        "value" : "inactive"
}

unit_load_state:

{
        "name" : "io.systemd.Manager.unit_load_state",
        "object" : "multi-user.target",
        "value" : "loaded"
}

nrestarts:

{
        "name" : "io.systemd.Manager.nrestarts",
        "object" : "user@0.service",
        "value" : 0
}
{
        "name" : "io.systemd.Manager.nrestarts",
        "object" : "user-runtime-dir@0.service",
        "value" : 0
}
src/core/manager.h
src/core/meson.build
src/core/varlink-metrics.c [new file with mode: 0644]
src/core/varlink-metrics.h [new file with mode: 0644]
src/core/varlink.c
test/units/TEST-74-AUX-UTILS.varlinkctl.sh