mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-12 16:44:18 -08:00
Merge pull request #215 from tux21b/master
systemd-collector: support private/direct connections without dbus
This commit is contained in:
commit
dd76a68f3c
|
@ -16,6 +16,7 @@
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/coreos/go-systemd/dbus"
|
"github.com/coreos/go-systemd/dbus"
|
||||||
|
@ -29,6 +30,14 @@ type systemdCollector struct {
|
||||||
|
|
||||||
var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}
|
var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}
|
||||||
|
|
||||||
|
var (
|
||||||
|
systemdPrivate = flag.Bool(
|
||||||
|
"collector.systemd.private",
|
||||||
|
false,
|
||||||
|
"Establish a private, direct connection to systemd without dbus.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Factories["systemd"] = NewSystemdCollector
|
Factories["systemd"] = NewSystemdCollector
|
||||||
}
|
}
|
||||||
|
@ -92,8 +101,15 @@ func (c *systemdCollector) collectSystemState(ch chan<- prometheus.Metric, syste
|
||||||
ch <- prometheus.MustNewConstMetric(c.systemRunningDesc, prometheus.GaugeValue, isSystemRunning)
|
ch <- prometheus.MustNewConstMetric(c.systemRunningDesc, prometheus.GaugeValue, isSystemRunning)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *systemdCollector) newDbus() (*dbus.Conn, error) {
|
||||||
|
if *systemdPrivate {
|
||||||
|
return dbus.NewSystemdConnection()
|
||||||
|
}
|
||||||
|
return dbus.New()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *systemdCollector) listUnits() ([]dbus.UnitStatus, error) {
|
func (c *systemdCollector) listUnits() ([]dbus.UnitStatus, error) {
|
||||||
conn, err := dbus.New()
|
conn, err := c.newDbus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("couldn't get dbus connection: %s", err)
|
return nil, fmt.Errorf("couldn't get dbus connection: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -103,7 +119,7 @@ func (c *systemdCollector) listUnits() ([]dbus.UnitStatus, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *systemdCollector) getSystemState() (state string, err error) {
|
func (c *systemdCollector) getSystemState() (state string, err error) {
|
||||||
conn, err := dbus.New()
|
conn, err := c.newDbus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("couldn't get dbus connection: %s", err)
|
return "", fmt.Errorf("couldn't get dbus connection: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue