Skip to content

Comments

[metrics] Introduce metrics API#2

Merged
YapingLi04 merged 3 commits intomainfrom
metricsapi
Feb 9, 2026
Merged

[metrics] Introduce metrics API#2
YapingLi04 merged 3 commits intomainfrom
metricsapi

Conversation

@YapingLi04
Copy link
Owner

@YapingLi04 YapingLi04 commented Oct 3, 2025

See the design doc by @ikruglov

This PR introduces the metrics API framework, adds some basic system wide and per unit metrics, and a basic CLI. The PR is broken into two commits as described below.

First commit

The first commit includes:

  • 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

Second commit

The second commit adds some basic metrics, a basic CLI (systemd-report) which
lists the metrics, and integration tests.

System wide metrics:

  • units_by_type_total
  • units_by_state_total

Two per unit metrics:

  • unit_active_state
  • unit_load_state

A service state metric:

  • nrestarts

Deviations from the original design

  • Introduced top level field "object" for ease of filtering. Instead of having fields: { unit: "foo", unit_type: "service" }, we now have object: foo.service as the top level field.

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
}

@YapingLi04 YapingLi04 force-pushed the metricsapi branch 4 times, most recently from f3f0f23 to a58483a Compare October 3, 2025 13:34
@YapingLi04 YapingLi04 changed the title [metrics api] Introduce metrics API [metrics] Introduce metrics API Oct 3, 2025
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 4 times, most recently from a08c235 to d752c3d Compare October 7, 2025 18:10
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 4 times, most recently from dcf9f85 to 22c1de9 Compare October 24, 2025 11:17
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 3 times, most recently from fb58f07 to d522db9 Compare October 30, 2025 14:41
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 2 times, most recently from 435e127 to 0d405ec Compare November 9, 2025 14:02
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 3 times, most recently from 067174f to f4f0de4 Compare November 25, 2025 11:42
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 6 times, most recently from ed64627 to 9d0b19e Compare January 21, 2026 17:52
@YapingLi04 YapingLi04 force-pushed the metricsapi branch 2 times, most recently from 7ae31ca to 56eeda4 Compare February 2, 2026 12:54
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 merged commit e047394 into main Feb 9, 2026
33 of 44 checks passed
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.

1 participant