Skip to content

Comments

Metrics API refactor#3

Draft
YapingLi04 wants to merge 3 commits intomainfrom
metricsapi-refac
Draft

Metrics API refactor#3
YapingLi04 wants to merge 3 commits intomainfrom
metricsapi-refac

Conversation

@YapingLi04
Copy link
Owner

No description provided.

@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 6 times, most recently from a83624a to 9949284 Compare October 16, 2025 06:42
Copy link

@daandemeyer daandemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split the commit introducing the metrics and the report CLI into two separate commits?

Copy link
Owner Author

@YapingLi04 YapingLi04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed all the comments.

There are few unresolved comments which I had follow up questions or comments.

I made changes in the topmost commit and didn't do it in the two commits where the comments were. This way I can test the code still works. I will split the changes in the local units in the upstream PR.

@YapingLi04
Copy link
Owner Author

Added type specific metric_build_send()
fixed leaking varlinks array

will address remaining comment in the next around.

@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 6 times, most recently from 158998c to deeed86 Compare October 21, 2025 10:01
@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 3 times, most recently from fd59672 to 025abeb Compare October 22, 2025 01:42
@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 8 times, most recently from 067174f to f4f0de4 Compare November 25, 2025 11:42
@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 10 times, most recently from 65a4874 to 77b819c Compare January 21, 2026 17:11
@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 4 times, most recently from 00668ef to 14626bc Compare January 31, 2026 22:11
@YapingLi04 YapingLi04 force-pushed the metricsapi-refac branch 3 times, most recently from cb45273 to 7ae31ca Compare February 2, 2026 10:02
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.
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.

3 participants