Skip to content

Commit

Permalink
Add a counter for refused socket unit connections, available as of sy…
Browse files Browse the repository at this point in the history
…stemd 239 (prometheus#995)

Signed-off-by: xginn8 <mamcgi@gmail.com>
  • Loading branch information
xginn8 authored and SuperQ committed Jul 16, 2018
1 parent 76bbd8d commit 9b97f44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 15 additions & 0 deletions collector/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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))

Expand All @@ -89,6 +93,7 @@ func NewSystemdCollector() (Collector, error) {
timerLastTriggerDesc: timerLastTriggerDesc,
socketAcceptedConnectionsDesc: socketAcceptedConnectionsDesc,
socketCurrentConnectionsDesc: socketCurrentConnectionsDesc,
socketRefusedConnectionsDesc: socketRefusedConnectionsDesc,
unitWhitelistPattern: unitWhitelistPattern,
unitBlacklistPattern: unitBlacklistPattern,
}, nil
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -193,6 +201,7 @@ type unit struct {
nRestarts uint32
acceptedConnections uint32
currentConnections uint32
refusedConnections uint32
}

func (c *systemdCollector) getAllUnits() ([]unit, error) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b97f44

Please sign in to comment.