mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-27 22:49:44 -08:00
Add systemd version as label string.
Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
5981bbe638
commit
5c0e4d61c8
|
@ -131,7 +131,7 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) {
|
||||||
"Total number of refused socket connections", []string{"name"}, nil)
|
"Total number of refused socket connections", []string{"name"}, nil)
|
||||||
systemdVersionDesc := prometheus.NewDesc(
|
systemdVersionDesc := prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(namespace, subsystem, "version"),
|
prometheus.BuildFQName(namespace, subsystem, "version"),
|
||||||
"Detected systemd version", []string{}, nil)
|
"Detected systemd version", []string{"version"}, nil)
|
||||||
|
|
||||||
if *oldUnitExclude != "" {
|
if *oldUnitExclude != "" {
|
||||||
if !unitExcludeSet {
|
if !unitExcludeSet {
|
||||||
|
@ -183,12 +183,16 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
systemdVersion := c.getSystemdVersion(conn)
|
systemdVersion, systemdVersionFull := c.getSystemdVersion(conn)
|
||||||
if systemdVersion < minSystemdVersionSystemState {
|
if systemdVersion < minSystemdVersionSystemState {
|
||||||
level.Debug(c.logger).Log("msg", "Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState)
|
level.Debug(c.logger).Log("msg", "Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState)
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.systemdVersionDesc, prometheus.GaugeValue, systemdVersion)
|
c.systemdVersionDesc,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
systemdVersion,
|
||||||
|
systemdVersionFull,
|
||||||
|
)
|
||||||
|
|
||||||
allUnits, err := c.getAllUnits(conn)
|
allUnits, err := c.getAllUnits(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -487,18 +491,19 @@ func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, lo
|
||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemdCollector) getSystemdVersion(conn *dbus.Conn) float64 {
|
func (c *systemdCollector) getSystemdVersion(conn *dbus.Conn) (float64, string) {
|
||||||
version, err := conn.GetManagerProperty("Version")
|
version, err := conn.GetManagerProperty("Version")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
level.Debug(c.logger).Log("msg", "Unable to get systemd version property, defaulting to 0")
|
level.Debug(c.logger).Log("msg", "Unable to get systemd version property, defaulting to 0")
|
||||||
return 0
|
return 0, ""
|
||||||
}
|
}
|
||||||
|
version = strings.TrimPrefix(strings.TrimSuffix(version, `"`), `"`)
|
||||||
level.Debug(c.logger).Log("msg", "Got systemd version", "version", version)
|
level.Debug(c.logger).Log("msg", "Got systemd version", "version", version)
|
||||||
version = systemdVersionRE.FindString(version)
|
parsedVersion := systemdVersionRE.FindString(version)
|
||||||
v, err := strconv.ParseFloat(version, 64)
|
v, err := strconv.ParseFloat(parsedVersion, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
level.Debug(c.logger).Log("msg", "Got invalid systemd version", "version", version)
|
level.Debug(c.logger).Log("msg", "Got invalid systemd version", "version", version)
|
||||||
return 0
|
return 0, ""
|
||||||
}
|
}
|
||||||
return v
|
return v, version
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue