From 140b8b85c37553f5baebf433ac9be284cd1dd80d Mon Sep 17 00:00:00 2001 From: xginn8 Date: Sun, 22 Jul 2018 03:20:03 -0400 Subject: [PATCH] Filter out uninstalled systemd units when collecting all units (#1011) fixes #567 Signed-off-by: Matthew McGinn --- CHANGELOG.md | 2 +- collector/systemd_linux.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cb808db..45f7e262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ **Breaking changes** -* [CHANGE] +* [CHANGE] Filter out non-installed units when collecting all systemd units #1011 * [FEATURE] Collect NRefused property for systemd socket units (available as of systemd v239) * [FEATURE] Collect NRestarts property for systemd service units * [FEATURE] Add socket unit stats to systemd collector #968 diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index 99a10de1..6aee6241 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -227,7 +227,9 @@ func (c *systemdCollector) getAllUnits() ([]unit, error) { } defer conn.Close() - allUnits, err := conn.ListUnits() + // Filter out any units that are not installed and are pulled in only as dependencies. + allUnits, err := conn.ListUnitsFiltered([]string{"loaded"}) + if err != nil { return nil, err }