Skip to content

Comments

Sd varlink any metrics#4

Draft
YapingLi04 wants to merge 4 commits intomainfrom
sd-varlink-any-metrics
Draft

Sd varlink any metrics#4
YapingLi04 wants to merge 4 commits intomainfrom
sd-varlink-any-metrics

Conversation

@YapingLi04
Copy link
Owner

Check to see if ANY works for metrics API and open PR for CI

This allows representing fields that can be either an integer or
a string, like the "value" field we'll be adding in
systemd#39202.

Upstream spec change: varlink/varlink.github.io#43
@YapingLi04 YapingLi04 force-pushed the sd-varlink-any-metrics branch 2 times, most recently from 6a844f0 to c30a550 Compare January 14, 2026 17:05
This commit introduces the shared code for the metrics API framework:

- Metrics API definitions
- Code to set up the varlink server
- The describe method which shows all the metrics families
- The list method which lists all the metrics
- Type definitions related to MetricFamily
- Common code to build json objects
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
}
systemd-report will list all the metrics.
@YapingLi04 YapingLi04 force-pushed the sd-varlink-any-metrics branch from c30a550 to ec864e4 Compare January 14, 2026 21:17
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