core: add io.systemd.Manager.Version to metrics
This commit adds the systemd version to the metrics that `io.systemd.Manager` generates.
This commit is contained in:
@@ -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,
|
||||
},
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
@@ -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)"
|
||||
|
||||
Reference in New Issue
Block a user