From 9b97f44a704c9c31e45c864c105643e6b197abad Mon Sep 17 00:00:00 2001 From: xginn8 Date: Mon, 16 Jul 2018 10:01:42 -0400 Subject: [PATCH] Add a counter for refused socket unit connections, available as of systemd 239 (#995) Signed-off-by: xginn8 --- CHANGELOG.md | 1 + collector/systemd_linux.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f741f9f..85a04851 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ **Breaking changes** * [CHANGE] +* [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 * [ENHANCEMENT] diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index 13dc0aa3..3e16c451 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -40,6 +40,7 @@ type systemdCollector struct { timerLastTriggerDesc *prometheus.Desc socketAcceptedConnectionsDesc *prometheus.Desc socketCurrentConnectionsDesc *prometheus.Desc + socketRefusedConnectionsDesc *prometheus.Desc unitWhitelistPattern *regexp.Regexp unitBlacklistPattern *regexp.Regexp } @@ -78,6 +79,9 @@ func NewSystemdCollector() (Collector, error) { socketCurrentConnectionsDesc := prometheus.NewDesc( prometheus.BuildFQName(namespace, subsystem, "socket_current_connections"), "Current number of socket connections", []string{"name"}, nil) + socketRefusedConnectionsDesc := prometheus.NewDesc( + prometheus.BuildFQName(namespace, subsystem, "socket_refused_connections_total"), + "Total number of refused socket connections", []string{"name"}, nil) unitWhitelistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitWhitelist)) unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist)) @@ -89,6 +93,7 @@ func NewSystemdCollector() (Collector, error) { timerLastTriggerDesc: timerLastTriggerDesc, socketAcceptedConnectionsDesc: socketAcceptedConnectionsDesc, socketCurrentConnectionsDesc: socketCurrentConnectionsDesc, + socketRefusedConnectionsDesc: socketRefusedConnectionsDesc, unitWhitelistPattern: unitWhitelistPattern, unitBlacklistPattern: unitBlacklistPattern, }, nil @@ -148,6 +153,9 @@ func (c *systemdCollector) collectSockets(ch chan<- prometheus.Metric, units []u ch <- prometheus.MustNewConstMetric( c.socketCurrentConnectionsDesc, prometheus.GaugeValue, float64(unit.currentConnections), unit.Name) + ch <- prometheus.MustNewConstMetric( + c.socketRefusedConnectionsDesc, prometheus.GaugeValue, + float64(unit.refusedConnections), unit.Name) } return nil } @@ -193,6 +201,7 @@ type unit struct { nRestarts uint32 acceptedConnections uint32 currentConnections uint32 + refusedConnections uint32 } func (c *systemdCollector) getAllUnits() ([]unit, error) { @@ -244,6 +253,12 @@ func (c *systemdCollector) getAllUnits() ([]unit, error) { } unit.currentConnections = currentConnectionCount.Value.Value().(uint32) + refusedConnectionCount, err := conn.GetUnitTypeProperty(unit.Name, "Socket", "NRefused") + if err != nil { + log.Debugf("couldn't get unit '%s' NRefused: %s\n", unit.Name, err) + continue + } + unit.refusedConnections = refusedConnectionCount.Value.Value().(uint32) } result = append(result, unit)