From: Michael Vogt Date: Tue, 26 May 2026 13:51:14 +0000 (+0200) Subject: core: add io.systemd.Manager.Version to metrics X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3eb9864e23c969c82a157746000caa118ef65cba;p=thirdparty%2Fsystemd.git core: add io.systemd.Manager.Version to metrics This commit adds the systemd version to the metrics that `io.systemd.Manager` generates. --- diff --git a/src/core/varlink-metrics.c b/src/core/varlink-metrics.c index a470341c2b1..9992264c788 100644 --- a/src/core/varlink-metrics.c +++ b/src/core/varlink-metrics.c @@ -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, + }, {} }; diff --git a/test/units/TEST-74-AUX-UTILS.report.sh b/test/units/TEST-74-AUX-UTILS.report.sh index 4b733ad611f..e2d94df75b8 100755 --- a/test/units/TEST-74-AUX-UTILS.report.sh +++ b/test/units/TEST-74-AUX-UTILS.report.sh @@ -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)"