]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: add io.systemd.Manager.Version to metrics
authorMichael Vogt <michael@amutable.com>
Tue, 26 May 2026 13:51:14 +0000 (15:51 +0200)
committerMichael Vogt <michael@amutable.com>
Sat, 20 Jun 2026 08:37:47 +0000 (10:37 +0200)
This commit adds the systemd version to the metrics that
`io.systemd.Manager` generates.

src/core/varlink-metrics.c
test/units/TEST-74-AUX-UTILS.report.sh

index a470341c2b182c6150e74fe708e54cd1d1bcd644..9992264c788ac265da735628dd59e75dbda3b063 100644 (file)
@@ -10,6 +10,7 @@
 #include "unit-def.h"
 #include "unit.h"
 #include "varlink-metrics.h"
+#include "version.h"
 
 static int active_timestamp_build_json(const MetricFamily *mf, sd_varlink *vl, void *userdata) {
         Manager *manager = ASSERT_PTR(userdata);
@@ -84,6 +85,18 @@ static int inactive_exit_timestamp_build_json(const MetricFamily *mf, sd_varlink
         return 0;
 }
 
+static int version_build_json(const MetricFamily *mf, sd_varlink *vl, void *userdata) {
+        assert(mf && mf->name);
+        assert(vl);
+
+        return metric_build_send_string(
+                        mf,
+                        vl,
+                        /* object= */ NULL,
+                        GIT_VERSION,
+                        /* fields= */ NULL);
+}
+
 static int state_change_timestamp_build_json(const MetricFamily *mf, sd_varlink *vl, void *userdata) {
         Manager *manager = ASSERT_PTR(userdata);
         Unit *unit;
@@ -468,6 +481,12 @@ static const MetricFamily metric_family_table[] = {
                 .type = METRIC_FAMILY_TYPE_GAUGE,
                 .generate = units_total_build_json,
         },
+        {
+                .name = METRIC_IO_SYSTEMD_MANAGER_PREFIX "Version",
+                .description = "Version of systemd",
+                .type = METRIC_FAMILY_TYPE_STRING,
+                .generate = version_build_json,
+        },
         {}
 };
 
index 4b733ad611fc87243c789bf2c7d49ceef8357985..e2d94df75b84997ff5ddc67ceec559af61c2bd80 100755 (executable)
@@ -80,6 +80,11 @@ swap_reported="$(basic_value io.systemd.Basic.SwapBytes)"
 swap_expected=$(( $(awk '/^SwapTotal:/ { print $2; found=1 } END { if (!found) print 0 }' /proc/meminfo) * 1024 ))
 [ "$swap_reported" = "$swap_expected" ]
 
+# io.systemd.Manager.Version should be non-empty and match what `systemctl --version` reports
+metrics_version="$(varlinkctl call --more /run/systemd/report/io.systemd.Manager io.systemd.Metrics.List {} | jq --seq -r 'select(.name == "io.systemd.Manager.Version") | .value')"
+[ -n "$metrics_version" ]
+systemctl --version | grep -F "($metrics_version)" >/dev/null
+
 # test io.systemd.Basic.MachineInfo.* metrics, sourced from /etc/machine-info
 if [ -e /etc/machine-info ]; then
     MACHINE_INFO_BACKUP="$(mktemp)"