mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 23:19:46 -08:00
Add a counter for refused socket unit connections, available as of systemd 239 (#995)
Signed-off-by: xginn8 <mamcgi@gmail.com>
This commit is contained in:
parent
76bbd8dd18
commit
9b97f44a70
|
@ -3,6 +3,7 @@
|
||||||
**Breaking changes**
|
**Breaking changes**
|
||||||
|
|
||||||
* [CHANGE]
|
* [CHANGE]
|
||||||
|
* [FEATURE] Collect NRefused property for systemd socket units (available as of systemd v239)
|
||||||
* [FEATURE] Collect NRestarts property for systemd service units
|
* [FEATURE] Collect NRestarts property for systemd service units
|
||||||
* [FEATURE] Add socket unit stats to systemd collector #968
|
* [FEATURE] Add socket unit stats to systemd collector #968
|
||||||
* [ENHANCEMENT]
|
* [ENHANCEMENT]
|
||||||
|
|
|
@ -40,6 +40,7 @@ type systemdCollector struct {
|
||||||
timerLastTriggerDesc *prometheus.Desc
|
timerLastTriggerDesc *prometheus.Desc
|
||||||
socketAcceptedConnectionsDesc *prometheus.Desc
|
socketAcceptedConnectionsDesc *prometheus.Desc
|
||||||
socketCurrentConnectionsDesc *prometheus.Desc
|
socketCurrentConnectionsDesc *prometheus.Desc
|
||||||
|
socketRefusedConnectionsDesc *prometheus.Desc
|
||||||
unitWhitelistPattern *regexp.Regexp
|
unitWhitelistPattern *regexp.Regexp
|
||||||
unitBlacklistPattern *regexp.Regexp
|
unitBlacklistPattern *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
@ -78,6 +79,9 @@ func NewSystemdCollector() (Collector, error) {
|
||||||
socketCurrentConnectionsDesc := prometheus.NewDesc(
|
socketCurrentConnectionsDesc := prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, subsystem, "socket_current_connections"),
|
prometheus.BuildFQName(namespace, subsystem, "socket_current_connections"),
|
||||||
"Current number of socket connections", []string{"name"}, nil)
|
"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))
|
unitWhitelistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitWhitelist))
|
||||||
unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist))
|
unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist))
|
||||||
|
|
||||||
|
@ -89,6 +93,7 @@ func NewSystemdCollector() (Collector, error) {
|
||||||
timerLastTriggerDesc: timerLastTriggerDesc,
|
timerLastTriggerDesc: timerLastTriggerDesc,
|
||||||
socketAcceptedConnectionsDesc: socketAcceptedConnectionsDesc,
|
socketAcceptedConnectionsDesc: socketAcceptedConnectionsDesc,
|
||||||
socketCurrentConnectionsDesc: socketCurrentConnectionsDesc,
|
socketCurrentConnectionsDesc: socketCurrentConnectionsDesc,
|
||||||
|
socketRefusedConnectionsDesc: socketRefusedConnectionsDesc,
|
||||||
unitWhitelistPattern: unitWhitelistPattern,
|
unitWhitelistPattern: unitWhitelistPattern,
|
||||||
unitBlacklistPattern: unitBlacklistPattern,
|
unitBlacklistPattern: unitBlacklistPattern,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -148,6 +153,9 @@ func (c *systemdCollector) collectSockets(ch chan<- prometheus.Metric, units []u
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.socketCurrentConnectionsDesc, prometheus.GaugeValue,
|
c.socketCurrentConnectionsDesc, prometheus.GaugeValue,
|
||||||
float64(unit.currentConnections), unit.Name)
|
float64(unit.currentConnections), unit.Name)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.socketRefusedConnectionsDesc, prometheus.GaugeValue,
|
||||||
|
float64(unit.refusedConnections), unit.Name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -193,6 +201,7 @@ type unit struct {
|
||||||
nRestarts uint32
|
nRestarts uint32
|
||||||
acceptedConnections uint32
|
acceptedConnections uint32
|
||||||
currentConnections uint32
|
currentConnections uint32
|
||||||
|
refusedConnections uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemdCollector) getAllUnits() ([]unit, error) {
|
func (c *systemdCollector) getAllUnits() ([]unit, error) {
|
||||||
|
@ -244,6 +253,12 @@ func (c *systemdCollector) getAllUnits() ([]unit, error) {
|
||||||
}
|
}
|
||||||
unit.currentConnections = currentConnectionCount.Value.Value().(uint32)
|
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)
|
result = append(result, unit)
|
||||||
|
|
Loading…
Reference in a new issue