mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-02-02 08:42:31 -08:00
Merge pull request #479 from prometheus/grobie/fix-vet-and-lint-errors
Fix all open go lint and vet issues
This commit is contained in:
commit
e15263fd9f
|
@ -11,7 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Exporter is a prometheus exporter using multiple Factories to collect and export system metrics.
|
// Package collector includes all individual collectors to gather and export system metrics.
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -19,15 +19,17 @@ import (
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Namespace defines the common namespace to be used by all metrics.
|
||||||
const Namespace = "node"
|
const Namespace = "node"
|
||||||
|
|
||||||
|
// Factories contains the list of all available collectors.
|
||||||
var Factories = make(map[string]func() (Collector, error))
|
var Factories = make(map[string]func() (Collector, error))
|
||||||
|
|
||||||
func warnDeprecated(collector string) {
|
func warnDeprecated(collector string) {
|
||||||
log.Warnf("The %s collector is deprecated and will be removed in the future!", collector)
|
log.Warnf("The %s collector is deprecated and will be removed in the future!", collector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface a collector has to implement.
|
// Collector is the interface a collector has to implement.
|
||||||
type Collector interface {
|
type Collector interface {
|
||||||
// Get new metrics and expose them via prometheus registry.
|
// Get new metrics and expose them via prometheus registry.
|
||||||
Update(ch chan<- prometheus.Metric) (err error)
|
Update(ch chan<- prometheus.Metric) (err error)
|
||||||
|
|
|
@ -28,8 +28,7 @@ func init() {
|
||||||
Factories["conntrack"] = NewConntrackCollector
|
Factories["conntrack"] = NewConntrackCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewConntrackCollector returns a new Collector exposing conntrack stats.
|
||||||
// conntrack stats
|
|
||||||
func NewConntrackCollector() (Collector, error) {
|
func NewConntrackCollector() (Collector, error) {
|
||||||
return &conntrackCollector{
|
return &conntrackCollector{
|
||||||
current: prometheus.NewDesc(
|
current: prometheus.NewDesc(
|
||||||
|
|
|
@ -47,8 +47,7 @@ func init() {
|
||||||
Factories["diskstats"] = NewDiskstatsCollector
|
Factories["diskstats"] = NewDiskstatsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
|
||||||
// disk device stats.
|
|
||||||
func NewDiskstatsCollector() (Collector, error) {
|
func NewDiskstatsCollector() (Collector, error) {
|
||||||
var diskLabelNames = []string{"device"}
|
var diskLabelNames = []string{"device"}
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,7 @@ func init() {
|
||||||
Factories["edac"] = NewEdacCollector
|
Factories["edac"] = NewEdacCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewEdacCollector returns a new Collector exposing edac stats.
|
||||||
// edac stats.
|
|
||||||
func NewEdacCollector() (Collector, error) {
|
func NewEdacCollector() (Collector, error) {
|
||||||
return &edacCollector{
|
return &edacCollector{
|
||||||
ceCount: prometheus.NewDesc(
|
ceCount: prometheus.NewDesc(
|
||||||
|
|
|
@ -22,18 +22,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type entropyCollector struct {
|
type entropyCollector struct {
|
||||||
entropy_avail *prometheus.Desc
|
entropyAvail *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Factories["entropy"] = NewEntropyCollector
|
Factories["entropy"] = NewEntropyCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewEntropyCollector returns a new Collector exposing entropy stats.
|
||||||
// entropy stats
|
|
||||||
func NewEntropyCollector() (Collector, error) {
|
func NewEntropyCollector() (Collector, error) {
|
||||||
return &entropyCollector{
|
return &entropyCollector{
|
||||||
entropy_avail: prometheus.NewDesc(
|
entropyAvail: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, "", "entropy_available_bits"),
|
prometheus.BuildFQName(Namespace, "", "entropy_available_bits"),
|
||||||
"Bits of available entropy.",
|
"Bits of available entropy.",
|
||||||
nil, nil,
|
nil, nil,
|
||||||
|
@ -47,7 +46,7 @@ func (c *entropyCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
return fmt.Errorf("couldn't get entropy_avail: %s", err)
|
return fmt.Errorf("couldn't get entropy_avail: %s", err)
|
||||||
}
|
}
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.entropy_avail, prometheus.GaugeValue, float64(value))
|
c.entropyAvail, prometheus.GaugeValue, float64(value))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,7 @@ func init() {
|
||||||
Factories["filesystem"] = NewFilesystemCollector
|
Factories["filesystem"] = NewFilesystemCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewFilesystemCollector returns a new Collector exposing filesystems stats.
|
||||||
// Filesystems stats.
|
|
||||||
func NewFilesystemCollector() (Collector, error) {
|
func NewFilesystemCollector() (Collector, error) {
|
||||||
subsystem := "filesystem"
|
subsystem := "filesystem"
|
||||||
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)
|
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)
|
||||||
|
|
|
@ -26,8 +26,8 @@ import (
|
||||||
const (
|
const (
|
||||||
defIgnoredMountPoints = "^/(dev)($|/)"
|
defIgnoredMountPoints = "^/(dev)($|/)"
|
||||||
defIgnoredFSTypes = "^devfs$"
|
defIgnoredFSTypes = "^devfs$"
|
||||||
MNT_RDONLY = 0x1
|
readOnly = 0x1 // MNT_RDONLY
|
||||||
MNT_NOWAIT = 0x2
|
noWait = 0x2 // MNT_NOWAIT
|
||||||
)
|
)
|
||||||
|
|
||||||
func gostring(b []int8) string {
|
func gostring(b []int8) string {
|
||||||
|
@ -43,7 +43,7 @@ func gostring(b []int8) string {
|
||||||
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
buf := make([]unix.Statfs_t, 16)
|
buf := make([]unix.Statfs_t, 16)
|
||||||
for {
|
for {
|
||||||
n, err := unix.Getfsstat(buf, MNT_NOWAIT)
|
n, err := unix.Getfsstat(buf, noWait)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var ro float64
|
var ro float64
|
||||||
if (fs.Flags & MNT_RDONLY) != 0 {
|
if (fs.Flags & readOnly) != 0 {
|
||||||
ro = 1
|
ro = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@ import (
|
||||||
const (
|
const (
|
||||||
defIgnoredMountPoints = "^/(sys|proc|dev)($|/)"
|
defIgnoredMountPoints = "^/(sys|proc|dev)($|/)"
|
||||||
defIgnoredFSTypes = "^(sys|proc|auto)fs$"
|
defIgnoredFSTypes = "^(sys|proc|auto)fs$"
|
||||||
ST_RDONLY = 0x1
|
readOnly = 0x1 // ST_RDONLY
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expose filesystem fullness.
|
// GetStats returns filesystem stats.
|
||||||
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
mps, err := mountPointDetails()
|
mps, err := mountPointDetails()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,7 +57,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var ro float64
|
var ro float64
|
||||||
if buf.Flags&ST_RDONLY != 0 {
|
if (buf.Flags & readOnly) != 0 {
|
||||||
ro = 1
|
ro = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Types for unmarshalling gmond's XML output.
|
// Package ganglia provides types for unmarshalling gmond's XML output.
|
||||||
//
|
//
|
||||||
// Not used elements in gmond's XML output are commented.
|
// Not used elements in gmond's XML output are commented.
|
||||||
// In case you want to use them, please change the names so that one
|
// In case you want to use them, please change the names so that one
|
||||||
|
@ -20,15 +20,18 @@ package ganglia
|
||||||
|
|
||||||
import "encoding/xml"
|
import "encoding/xml"
|
||||||
|
|
||||||
|
// ExtraElement describes EXTRA_ELEMENT elements.
|
||||||
type ExtraElement struct {
|
type ExtraElement struct {
|
||||||
Name string `xml:"NAME,attr"`
|
Name string `xml:"NAME,attr"`
|
||||||
Val string `xml:"VAL,attr"`
|
Val string `xml:"VAL,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExtraData describes EXTRA_DATA elements.
|
||||||
type ExtraData struct {
|
type ExtraData struct {
|
||||||
ExtraElements []ExtraElement `xml:"EXTRA_ELEMENT"`
|
ExtraElements []ExtraElement `xml:"EXTRA_ELEMENT"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Metric describes METRIC elements.
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
Name string `xml:"NAME,attr"`
|
Name string `xml:"NAME,attr"`
|
||||||
Value float64 `xml:"VAL,attr"`
|
Value float64 `xml:"VAL,attr"`
|
||||||
|
@ -42,6 +45,7 @@ type Metric struct {
|
||||||
ExtraData ExtraData `xml:"EXTRA_DATA"`
|
ExtraData ExtraData `xml:"EXTRA_DATA"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Host describes HOST elements.
|
||||||
type Host struct {
|
type Host struct {
|
||||||
Name string `xml:"NAME,attr"`
|
Name string `xml:"NAME,attr"`
|
||||||
/*
|
/*
|
||||||
|
@ -57,6 +61,7 @@ type Host struct {
|
||||||
Metrics []Metric `xml:"METRIC"`
|
Metrics []Metric `xml:"METRIC"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cluster describes CLUSTER elements.
|
||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
Name string `xml:"NAME,attr"`
|
Name string `xml:"NAME,attr"`
|
||||||
/*
|
/*
|
||||||
|
@ -68,6 +73,7 @@ type Cluster struct {
|
||||||
Hosts []Host `xml:"HOST"`
|
Hosts []Host `xml:"HOST"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ganglia describes the top-level XML structure.
|
||||||
type Ganglia struct {
|
type Ganglia struct {
|
||||||
XMLNAME xml.Name `xml:"GANGLIA_XML"`
|
XMLNAME xml.Name `xml:"GANGLIA_XML"`
|
||||||
Clusters []Cluster `xml:"CLUSTER"`
|
Clusters []Cluster `xml:"CLUSTER"`
|
||||||
|
|
|
@ -46,7 +46,7 @@ func init() {
|
||||||
|
|
||||||
var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector scraping ganglia.
|
// NewGmondCollector returns a new Collector scraping ganglia.
|
||||||
func NewGmondCollector() (Collector, error) {
|
func NewGmondCollector() (Collector, error) {
|
||||||
warnDeprecated("gmond")
|
warnDeprecated("gmond")
|
||||||
c := gmondCollector{
|
c := gmondCollector{
|
||||||
|
|
|
@ -51,8 +51,8 @@ func init() {
|
||||||
|
|
||||||
type hwMonCollector struct{}
|
type hwMonCollector struct{}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
|
||||||
// /sys/class/hwmon stats (similar to lm-sensors).
|
// (similar to lm-sensors).
|
||||||
func NewHwMonCollector() (Collector, error) {
|
func NewHwMonCollector() (Collector, error) {
|
||||||
return &hwMonCollector{}, nil
|
return &hwMonCollector{}, nil
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ func addValueFile(data map[string]map[string]string, sensor string, prop string,
|
||||||
data[sensor][prop] = value
|
data[sensor][prop] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split a sensor name into <type><num>_<property>
|
// explodeSensorFilename splits a sensor name into <type><num>_<property>.
|
||||||
func explodeSensorFilename(filename string) (ok bool, sensorType string, sensorNum int, sensorProperty string) {
|
func explodeSensorFilename(filename string) (ok bool, sensorType string, sensorNum int, sensorProperty string) {
|
||||||
matches := hwmonFilenameFormat.FindStringSubmatch(filename)
|
matches := hwmonFilenameFormat.FindStringSubmatch(filename)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
|
@ -164,7 +164,7 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) (e
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// format all sensors
|
// Format all sensors.
|
||||||
for sensor, sensorData := range data {
|
for sensor, sensorData := range data {
|
||||||
|
|
||||||
_, sensorType, _, _ := explodeSensorFilename(sensor)
|
_, sensorType, _, _ := explodeSensorFilename(sensor)
|
||||||
|
|
|
@ -45,6 +45,7 @@ func init() {
|
||||||
Factories["infiniband"] = NewInfiniBandCollector
|
Factories["infiniband"] = NewInfiniBandCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInfiniBandCollector returns a new Collector exposing InfiniBand stats.
|
||||||
func NewInfiniBandCollector() (Collector, error) {
|
func NewInfiniBandCollector() (Collector, error) {
|
||||||
var i infinibandCollector
|
var i infinibandCollector
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestInfiniBandDevices(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := len(devices); l != 1 {
|
if l := len(devices); l != 1 {
|
||||||
t.Fatal("Retrieved an unexpected number of InfiniBand devices: %d", l)
|
t.Fatalf("Retrieved an unexpected number of InfiniBand devices: %d", l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,6 @@ func TestInfiniBandPorts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := len(ports); l != 2 {
|
if l := len(ports); l != 2 {
|
||||||
t.Fatal("Retrieved an unexpected number of InfiniBand ports: %d", l)
|
t.Fatalf("Retrieved an unexpected number of InfiniBand ports: %d", l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ func init() {
|
||||||
Factories["interrupts"] = NewInterruptsCollector
|
Factories["interrupts"] = NewInterruptsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewInterruptsCollector returns a new Collector exposing interrupts stats.
|
||||||
// interrupts stats
|
|
||||||
func NewInterruptsCollector() (Collector, error) {
|
func NewInterruptsCollector() (Collector, error) {
|
||||||
return &interruptsCollector{
|
return &interruptsCollector{
|
||||||
desc: typedDesc{prometheus.NewDesc(
|
desc: typedDesc{prometheus.NewDesc(
|
||||||
|
|
|
@ -46,8 +46,7 @@ func getCanonicalMetricName(filename string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewKsmdCollector returns a new Collector exposing kernel/system statistics.
|
||||||
// kernel/system statistics.
|
|
||||||
func NewKsmdCollector() (Collector, error) {
|
func NewKsmdCollector() (Collector, error) {
|
||||||
subsystem := "ksmd"
|
subsystem := "ksmd"
|
||||||
descs := make(map[string]*prometheus.Desc)
|
descs := make(map[string]*prometheus.Desc)
|
||||||
|
@ -60,7 +59,7 @@ func NewKsmdCollector() (Collector, error) {
|
||||||
return &ksmdCollector{descs}, nil
|
return &ksmdCollector{descs}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expose kernel and system statistics.
|
// Update implements Collector and exposes kernel and system statistics.
|
||||||
func (c *ksmdCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
func (c *ksmdCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
for _, n := range ksmdFiles {
|
for _, n := range ksmdFiles {
|
||||||
val, err := readUintFromFile(sysFilePath(path.Join("kernel/mm/ksm", n)))
|
val, err := readUintFromFile(sysFilePath(path.Join("kernel/mm/ksm", n)))
|
||||||
|
|
|
@ -31,7 +31,7 @@ func init() {
|
||||||
Factories["loadavg"] = NewLoadavgCollector
|
Factories["loadavg"] = NewLoadavgCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a prometheus registry and return a new Collector exposing load average.
|
// NewLoadavgCollector returns a new Collector exposing load average stats.
|
||||||
func NewLoadavgCollector() (Collector, error) {
|
func NewLoadavgCollector() (Collector, error) {
|
||||||
return &loadavgCollector{
|
return &loadavgCollector{
|
||||||
metric: []typedDesc{
|
metric: []typedDesc{
|
||||||
|
|
|
@ -65,15 +65,15 @@ type logindSession struct {
|
||||||
|
|
||||||
// Struct elements must be public for the reflection magic of godbus to work.
|
// Struct elements must be public for the reflection magic of godbus to work.
|
||||||
type logindSessionEntry struct {
|
type logindSessionEntry struct {
|
||||||
SessionId string
|
SessionID string
|
||||||
UserId uint32
|
UserID uint32
|
||||||
UserName string
|
UserName string
|
||||||
SeatId string
|
SeatID string
|
||||||
SessionObjectPath dbus.ObjectPath
|
SessionObjectPath dbus.ObjectPath
|
||||||
}
|
}
|
||||||
|
|
||||||
type logindSeatEntry struct {
|
type logindSeatEntry struct {
|
||||||
SeatId string
|
SeatID string
|
||||||
SeatObjectPath dbus.ObjectPath
|
SeatObjectPath dbus.ObjectPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +81,7 @@ func init() {
|
||||||
Factories["logind"] = NewLogindCollector
|
Factories["logind"] = NewLogindCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewLogindCollector returns a new Collector exposing logind statistics.
|
||||||
// logind statistics.
|
|
||||||
func NewLogindCollector() (Collector, error) {
|
func NewLogindCollector() (Collector, error) {
|
||||||
return &logindCollector{}, nil
|
return &logindCollector{}, nil
|
||||||
}
|
}
|
||||||
|
@ -197,7 +196,7 @@ func (c *logindDbus) listSeats() ([]string, error) {
|
||||||
|
|
||||||
ret := make([]string, len(seats)+1)
|
ret := make([]string, len(seats)+1)
|
||||||
for i := range seats {
|
for i := range seats {
|
||||||
ret[i] = seats[i].SeatId
|
ret[i] = seats[i].SeatID
|
||||||
}
|
}
|
||||||
// Always add the empty seat, which is used for remote sessions like SSH
|
// Always add the empty seat, which is used for remote sessions like SSH
|
||||||
ret[len(seats)] = ""
|
ret[len(seats)] = ""
|
||||||
|
@ -260,7 +259,7 @@ func (c *logindDbus) getSession(session logindSessionEntry) *logindSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &logindSession{
|
return &logindSession{
|
||||||
seat: session.SeatId,
|
seat: session.SeatID,
|
||||||
remote: remote.String(),
|
remote: remote.String(),
|
||||||
sessionType: knownStringOrOther(sessionTypeStr, attrTypeValues),
|
sessionType: knownStringOrOther(sessionTypeStr, attrTypeValues),
|
||||||
class: knownStringOrOther(classStr, attrClassValues),
|
class: knownStringOrOther(classStr, attrClassValues),
|
||||||
|
|
|
@ -31,17 +31,17 @@ func (c *testLogindInterface) listSeats() ([]string, error) {
|
||||||
func (c *testLogindInterface) listSessions() ([]logindSessionEntry, error) {
|
func (c *testLogindInterface) listSessions() ([]logindSessionEntry, error) {
|
||||||
return []logindSessionEntry{
|
return []logindSessionEntry{
|
||||||
{
|
{
|
||||||
SessionId: "1",
|
SessionID: "1",
|
||||||
UserId: 0,
|
UserID: 0,
|
||||||
UserName: "",
|
UserName: "",
|
||||||
SeatId: "",
|
SeatID: "",
|
||||||
SessionObjectPath: dbus.ObjectPath("/org/freedesktop/login1/session/1"),
|
SessionObjectPath: dbus.ObjectPath("/org/freedesktop/login1/session/1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SessionId: "2",
|
SessionID: "2",
|
||||||
UserId: 0,
|
UserID: 0,
|
||||||
UserName: "",
|
UserName: "",
|
||||||
SeatId: "seat0",
|
SeatID: "seat0",
|
||||||
SessionObjectPath: dbus.ObjectPath("/org/freedesktop/login1/session/2"),
|
SessionObjectPath: dbus.ObjectPath("/org/freedesktop/login1/session/2"),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -50,13 +50,13 @@ func (c *testLogindInterface) listSessions() ([]logindSessionEntry, error) {
|
||||||
func (c *testLogindInterface) getSession(session logindSessionEntry) *logindSession {
|
func (c *testLogindInterface) getSession(session logindSessionEntry) *logindSession {
|
||||||
sessions := map[dbus.ObjectPath]*logindSession{
|
sessions := map[dbus.ObjectPath]*logindSession{
|
||||||
dbus.ObjectPath("/org/freedesktop/login1/session/1"): {
|
dbus.ObjectPath("/org/freedesktop/login1/session/1"): {
|
||||||
seat: session.SeatId,
|
seat: session.SeatID,
|
||||||
remote: "true",
|
remote: "true",
|
||||||
sessionType: knownStringOrOther("tty", attrTypeValues),
|
sessionType: knownStringOrOther("tty", attrTypeValues),
|
||||||
class: knownStringOrOther("user", attrClassValues),
|
class: knownStringOrOther("user", attrClassValues),
|
||||||
},
|
},
|
||||||
dbus.ObjectPath("/org/freedesktop/login1/session/2"): {
|
dbus.ObjectPath("/org/freedesktop/login1/session/2"): {
|
||||||
seat: session.SeatId,
|
seat: session.SeatID,
|
||||||
remote: "false",
|
remote: "false",
|
||||||
sessionType: knownStringOrOther("x11", attrTypeValues),
|
sessionType: knownStringOrOther("x11", attrTypeValues),
|
||||||
class: knownStringOrOther("greeter", attrClassValues),
|
class: knownStringOrOther("greeter", attrClassValues),
|
||||||
|
|
|
@ -56,10 +56,8 @@ func evalStatusline(statusline string) (active, total, size int64, err error) {
|
||||||
// +1 to make it more obvious that the whole string containing the info is also returned as matches[0].
|
// +1 to make it more obvious that the whole string containing the info is also returned as matches[0].
|
||||||
if len(matches) < 3+1 {
|
if len(matches) < 3+1 {
|
||||||
return 0, 0, 0, fmt.Errorf("too few matches found in statusline: %s", statusline)
|
return 0, 0, 0, fmt.Errorf("too few matches found in statusline: %s", statusline)
|
||||||
} else {
|
} else if len(matches) > 3+1 {
|
||||||
if len(matches) > 3+1 {
|
return 0, 0, 0, fmt.Errorf("too many matches found in statusline: %s", statusline)
|
||||||
return 0, 0, 0, fmt.Errorf("too many matches found in statusline: %s", statusline)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size, err = strconv.ParseInt(matches[1], 10, 64)
|
size, err = strconv.ParseInt(matches[1], 10, 64)
|
||||||
|
@ -109,7 +107,7 @@ func evalUnknownPersonalitylineRE(statusline string) (size int64, err error) {
|
||||||
return size, nil
|
return size, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the size that has already been synced out of the sync-line.
|
// evalBuildline gets the size that has already been synced out of the sync-line.
|
||||||
func evalBuildline(buildline string) (int64, error) {
|
func evalBuildline(buildline string) (int64, error) {
|
||||||
matches := buildlineRE.FindStringSubmatch(buildline)
|
matches := buildlineRE.FindStringSubmatch(buildline)
|
||||||
|
|
||||||
|
@ -131,7 +129,7 @@ func evalBuildline(buildline string) (int64, error) {
|
||||||
return syncedSize, nil
|
return syncedSize, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses an mdstat-file and returns a struct with the relevant infos.
|
// parseMdstat parses an mdstat-file and returns a struct with the relevant infos.
|
||||||
func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
|
func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
|
||||||
content, err := ioutil.ReadFile(mdStatusFilePath)
|
content, err := ioutil.ReadFile(mdStatusFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -234,7 +232,7 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
|
||||||
return mdStates, nil
|
return mdStates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just returns the pointer to an empty struct as we only use throwaway-metrics.
|
// NewMdadmCollector returns a new Collector exposing raid statistics.
|
||||||
func NewMdadmCollector() (Collector, error) {
|
func NewMdadmCollector() (Collector, error) {
|
||||||
return &mdadmCollector{}, nil
|
return &mdadmCollector{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ func init() {
|
||||||
Factories["megacli"] = NewMegaCliCollector
|
Factories["megacli"] = NewMegaCliCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewMegaCliCollector returns a new Collector exposing RAID status through
|
||||||
// RAID status through megacli.
|
// megacli.
|
||||||
func NewMegaCliCollector() (Collector, error) {
|
func NewMegaCliCollector() (Collector, error) {
|
||||||
warnDeprecated("megacli")
|
warnDeprecated("megacli")
|
||||||
return &megaCliCollector{
|
return &megaCliCollector{
|
||||||
|
|
|
@ -50,8 +50,7 @@ func init() {
|
||||||
Factories["meminfo_numa"] = NewMeminfoNumaCollector
|
Factories["meminfo_numa"] = NewMeminfoNumaCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewMeminfoNumaCollector returns a new Collector exposing memory stats.
|
||||||
// memory stats.
|
|
||||||
func NewMeminfoNumaCollector() (Collector, error) {
|
func NewMeminfoNumaCollector() (Collector, error) {
|
||||||
return &meminfoNumaCollector{
|
return &meminfoNumaCollector{
|
||||||
metricDescs: map[string]*prometheus.Desc{},
|
metricDescs: map[string]*prometheus.Desc{},
|
||||||
|
|
|
@ -93,6 +93,7 @@ func init() {
|
||||||
Factories["mountstats"] = NewMountStatsCollector
|
Factories["mountstats"] = NewMountStatsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMountStatsCollector returns a new Collector exposing NFS statistics.
|
||||||
func NewMountStatsCollector() (Collector, error) {
|
func NewMountStatsCollector() (Collector, error) {
|
||||||
fs, err := procfs.NewFS(*procPath)
|
fs, err := procfs.NewFS(*procPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,7 +106,7 @@ func NewMountStatsCollector() (Collector, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// For the time being, only NFS statistics are available via this mechanism
|
// For the time being, only NFS statistics are available via this mechanism.
|
||||||
subsystem = "mountstats_nfs"
|
subsystem = "mountstats_nfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -78,19 +78,19 @@ var (
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
nfsRpcOperationsDesc = prometheus.NewDesc(
|
nfsRPCOperationsDesc = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, "nfs", "rpc_operations"),
|
prometheus.BuildFQName(Namespace, "nfs", "rpc_operations"),
|
||||||
"Number of RPCs performed.",
|
"Number of RPCs performed.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
nfsRpcRetransmissionsDesc = prometheus.NewDesc(
|
nfsRPCRetransmissionsDesc = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, "nfs", "rpc_retransmissions"),
|
prometheus.BuildFQName(Namespace, "nfs", "rpc_retransmissions"),
|
||||||
"Number of RPC transmissions performed.",
|
"Number of RPC transmissions performed.",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
nfsRpcAuthenticationRefreshesDesc = prometheus.NewDesc(
|
nfsRPCAuthenticationRefreshesDesc = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, "nfs", "rpc_authentication_refreshes"),
|
prometheus.BuildFQName(Namespace, "nfs", "rpc_authentication_refreshes"),
|
||||||
"Number of RPC authentication refreshes performed.",
|
"Number of RPC authentication refreshes performed.",
|
||||||
nil,
|
nil,
|
||||||
|
@ -111,6 +111,7 @@ func init() {
|
||||||
Factories["nfs"] = NewNfsCollector
|
Factories["nfs"] = NewNfsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNfsCollector returns a new Collector exposing NFS statistics.
|
||||||
func NewNfsCollector() (Collector, error) {
|
func NewNfsCollector() (Collector, error) {
|
||||||
return &nfsCollector{}, nil
|
return &nfsCollector{}, nil
|
||||||
}
|
}
|
||||||
|
@ -145,17 +146,17 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
} else if fields := rpcLineRE.FindStringSubmatch(line); fields != nil {
|
} else if fields := rpcLineRE.FindStringSubmatch(line); fields != nil {
|
||||||
value, _ := strconv.ParseFloat(fields[1], 64)
|
value, _ := strconv.ParseFloat(fields[1], 64)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
nfsRpcOperationsDesc,
|
nfsRPCOperationsDesc,
|
||||||
prometheus.CounterValue, value)
|
prometheus.CounterValue, value)
|
||||||
|
|
||||||
value, _ = strconv.ParseFloat(fields[2], 64)
|
value, _ = strconv.ParseFloat(fields[2], 64)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
nfsRpcRetransmissionsDesc,
|
nfsRPCRetransmissionsDesc,
|
||||||
prometheus.CounterValue, value)
|
prometheus.CounterValue, value)
|
||||||
|
|
||||||
value, _ = strconv.ParseFloat(fields[3], 64)
|
value, _ = strconv.ParseFloat(fields[3], 64)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
nfsRpcAuthenticationRefreshesDesc,
|
nfsRPCAuthenticationRefreshesDesc,
|
||||||
prometheus.CounterValue, value)
|
prometheus.CounterValue, value)
|
||||||
} else if fields := procLineRE.FindStringSubmatch(line); fields != nil {
|
} else if fields := procLineRE.FindStringSubmatch(line); fields != nil {
|
||||||
version := fields[1]
|
version := fields[1]
|
||||||
|
|
|
@ -37,8 +37,8 @@ func init() {
|
||||||
Factories["ntp"] = NewNtpCollector
|
Factories["ntp"] = NewNtpCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewNtpCollector returns a new Collector exposing the offset between ntp and
|
||||||
// the offset between ntp and the current system time.
|
// the current system time.
|
||||||
func NewNtpCollector() (Collector, error) {
|
func NewNtpCollector() (Collector, error) {
|
||||||
warnDeprecated("ntp")
|
warnDeprecated("ntp")
|
||||||
if *ntpServer == "" {
|
if *ntpServer == "" {
|
||||||
|
|
|
@ -36,6 +36,7 @@ func init() {
|
||||||
Factories["runit"] = NewRunitCollector
|
Factories["runit"] = NewRunitCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRunitCollector returns a new Collector exposing runit statistics.
|
||||||
func NewRunitCollector() (Collector, error) {
|
func NewRunitCollector() (Collector, error) {
|
||||||
var (
|
var (
|
||||||
subsystem = "service"
|
subsystem = "service"
|
||||||
|
|
|
@ -42,8 +42,7 @@ func init() {
|
||||||
Factories["stat"] = NewStatCollector
|
Factories["stat"] = NewStatCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewStatCollector returns a new Collector exposing kernel/system statistics.
|
||||||
// kernel/system statistics.
|
|
||||||
func NewStatCollector() (Collector, error) {
|
func NewStatCollector() (Collector, error) {
|
||||||
return &statCollector{
|
return &statCollector{
|
||||||
cpu: prometheus.NewDesc(
|
cpu: prometheus.NewDesc(
|
||||||
|
|
|
@ -39,6 +39,7 @@ func init() {
|
||||||
Factories["supervisord"] = NewSupervisordCollector
|
Factories["supervisord"] = NewSupervisordCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSupervisordCollector returns a new Collector exposing supervisord statistics.
|
||||||
func NewSupervisordCollector() (Collector, error) {
|
func NewSupervisordCollector() (Collector, error) {
|
||||||
client, err := xmlrpc.NewClient(*supervisordURL, nil)
|
client, err := xmlrpc.NewClient(*supervisordURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -51,8 +51,7 @@ func init() {
|
||||||
Factories["systemd"] = NewSystemdCollector
|
Factories["systemd"] = NewSystemdCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewSystemdCollector returns a new Collector exposing systemd statistics.
|
||||||
// systemd statistics.
|
|
||||||
func NewSystemdCollector() (Collector, error) {
|
func NewSystemdCollector() (Collector, error) {
|
||||||
const subsystem = "systemd"
|
const subsystem = "systemd"
|
||||||
|
|
||||||
|
|
|
@ -26,20 +26,31 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TCPConnectionState int
|
type tcpConnectionState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TCP_ESTABLISHED TCPConnectionState = iota + 1
|
// TCP_ESTABLISHED
|
||||||
TCP_SYN_SENT
|
tcpEstablished tcpConnectionState = iota + 1
|
||||||
TCP_SYN_RECV
|
// TCP_SYN_SENT
|
||||||
TCP_FIN_WAIT1
|
tcpSynSent
|
||||||
TCP_FIN_WAIT2
|
// TCP_SYN_RECV
|
||||||
TCP_TIME_WAIT
|
tcpSynRecv
|
||||||
TCP_CLOSE
|
// TCP_FIN_WAIT1
|
||||||
TCP_CLOSE_WAIT
|
tcpFinWait1
|
||||||
TCP_LAST_ACK
|
// TCP_FIN_WAIT2
|
||||||
TCP_LISTEN
|
tcpFinWait2
|
||||||
TCP_CLOSING
|
// TCP_TIME_WAIT
|
||||||
|
tcpTimeWait
|
||||||
|
// TCP_CLOSE
|
||||||
|
tcpClose
|
||||||
|
// TCP_CLOSE_WAIT
|
||||||
|
tcpCloseWait
|
||||||
|
// TCP_LAST_ACK
|
||||||
|
tcpLastAck
|
||||||
|
// TCP_LISTEN
|
||||||
|
tcpListen
|
||||||
|
// TCP_CLOSING
|
||||||
|
tcpClosing
|
||||||
)
|
)
|
||||||
|
|
||||||
type tcpStatCollector struct {
|
type tcpStatCollector struct {
|
||||||
|
@ -84,10 +95,10 @@ func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
for st, value := range tcpStats {
|
for st, value := range tcpStats {
|
||||||
ch <- c.desc.mustNewConstMetric(value, st.String())
|
ch <- c.desc.mustNewConstMetric(value, st.String())
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTCPStats(statsFile string) (map[TCPConnectionState]float64, error) {
|
func getTCPStats(statsFile string) (map[tcpConnectionState]float64, error) {
|
||||||
file, err := os.Open(statsFile)
|
file, err := os.Open(statsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -97,9 +108,9 @@ func getTCPStats(statsFile string) (map[TCPConnectionState]float64, error) {
|
||||||
return parseTCPStats(file)
|
return parseTCPStats(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTCPStats(r io.Reader) (map[TCPConnectionState]float64, error) {
|
func parseTCPStats(r io.Reader) (map[tcpConnectionState]float64, error) {
|
||||||
var (
|
var (
|
||||||
tcpStats = map[TCPConnectionState]float64{}
|
tcpStats = map[tcpConnectionState]float64{}
|
||||||
scanner = bufio.NewScanner(r)
|
scanner = bufio.NewScanner(r)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -116,35 +127,35 @@ func parseTCPStats(r io.Reader) (map[TCPConnectionState]float64, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tcpStats[TCPConnectionState(st)]++
|
tcpStats[tcpConnectionState(st)]++
|
||||||
}
|
}
|
||||||
|
|
||||||
return tcpStats, nil
|
return tcpStats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st TCPConnectionState) String() string {
|
func (st tcpConnectionState) String() string {
|
||||||
switch st {
|
switch st {
|
||||||
case TCP_ESTABLISHED:
|
case tcpEstablished:
|
||||||
return "established"
|
return "established"
|
||||||
case TCP_SYN_SENT:
|
case tcpSynSent:
|
||||||
return "syn_sent"
|
return "syn_sent"
|
||||||
case TCP_SYN_RECV:
|
case tcpSynRecv:
|
||||||
return "syn_recv"
|
return "syn_recv"
|
||||||
case TCP_FIN_WAIT1:
|
case tcpFinWait1:
|
||||||
return "fin_wait1"
|
return "fin_wait1"
|
||||||
case TCP_FIN_WAIT2:
|
case tcpFinWait2:
|
||||||
return "fin_wait2"
|
return "fin_wait2"
|
||||||
case TCP_TIME_WAIT:
|
case tcpTimeWait:
|
||||||
return "time_wait"
|
return "time_wait"
|
||||||
case TCP_CLOSE:
|
case tcpClose:
|
||||||
return "close"
|
return "close"
|
||||||
case TCP_CLOSE_WAIT:
|
case tcpCloseWait:
|
||||||
return "close_wait"
|
return "close_wait"
|
||||||
case TCP_LAST_ACK:
|
case tcpLastAck:
|
||||||
return "last_ack"
|
return "last_ack"
|
||||||
case TCP_LISTEN:
|
case tcpListen:
|
||||||
return "listen"
|
return "listen"
|
||||||
case TCP_CLOSING:
|
case tcpClosing:
|
||||||
return "closing"
|
return "closing"
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
|
@ -30,11 +30,11 @@ func TestTCPStat(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if want, got := 1, int(tcpStats[TCP_ESTABLISHED]); want != got {
|
if want, got := 1, int(tcpStats[tcpEstablished]); want != got {
|
||||||
t.Errorf("want tcpstat number of established state %d, got %d", want, got)
|
t.Errorf("want tcpstat number of established state %d, got %d", want, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
if want, got := 1, int(tcpStats[TCP_LISTEN]); want != got {
|
if want, got := 1, int(tcpStats[tcpListen]); want != got {
|
||||||
t.Errorf("want tcpstat number of listen state %d, got %d", want, got)
|
t.Errorf("want tcpstat number of listen state %d, got %d", want, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,8 @@ func init() {
|
||||||
Factories["textfile"] = NewTextFileCollector
|
Factories["textfile"] = NewTextFileCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a registers a
|
// NewTextFileCollector returns a new Collector exposing metrics read from files
|
||||||
// SetMetricFamilyInjectionHook.
|
// in the given textfile directory.
|
||||||
func NewTextFileCollector() (Collector, error) {
|
func NewTextFileCollector() (Collector, error) {
|
||||||
c := &textFileCollector{
|
c := &textFileCollector{
|
||||||
path: *textFileDirectory,
|
path: *textFileDirectory,
|
||||||
|
@ -65,7 +65,7 @@ func NewTextFileCollector() (Collector, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// textFile collector works via SetMetricFamilyInjectionHook in parseTextFiles.
|
// Update implements the Collector interface.
|
||||||
func (c *textFileCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
func (c *textFileCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ func init() {
|
||||||
Factories["time"] = NewTimeCollector
|
Factories["time"] = NewTimeCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewTimeCollector returns a new Collector exposing the current system time in
|
||||||
// the current system time in seconds since epoch.
|
// seconds since epoch.
|
||||||
func NewTimeCollector() (Collector, error) {
|
func NewTimeCollector() (Collector, error) {
|
||||||
return &timeCollector{
|
return &timeCollector{
|
||||||
desc: prometheus.NewDesc(
|
desc: prometheus.NewDesc(
|
||||||
|
|
|
@ -35,8 +35,7 @@ func init() {
|
||||||
Factories["vmstat"] = NewvmStatCollector
|
Factories["vmstat"] = NewvmStatCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a prometheus registry and returns a new Collector exposing
|
// NewvmStatCollector returns a new Collector exposing vmstat stats.
|
||||||
// vmstat stats.
|
|
||||||
func NewvmStatCollector() (Collector, error) {
|
func NewvmStatCollector() (Collector, error) {
|
||||||
return &vmStatCollector{}, nil
|
return &vmStatCollector{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ type wifiStater interface {
|
||||||
StationInfo(ifi *wifi.Interface) (*wifi.StationInfo, error)
|
StationInfo(ifi *wifi.Interface) (*wifi.StationInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWifiCollector returns a new Collector exposing Wifi statistics.
|
||||||
func NewWifiCollector() (Collector, error) {
|
func NewWifiCollector() (Collector, error) {
|
||||||
const (
|
const (
|
||||||
subsystem = "wifi"
|
subsystem = "wifi"
|
||||||
|
|
|
@ -24,20 +24,16 @@ import (
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var zfsNotAvailableError = errors.New("ZFS / ZFS statistics are not available")
|
var errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available")
|
||||||
|
|
||||||
type zfsSysctl string
|
type zfsSysctl string
|
||||||
|
|
||||||
// Metrics
|
|
||||||
|
|
||||||
type zfsMetric struct {
|
type zfsMetric struct {
|
||||||
subsystem string // The Prometheus subsystem name.
|
subsystem string // The Prometheus subsystem name.
|
||||||
name string // The Prometheus name of the metric.
|
name string // The Prometheus name of the metric.
|
||||||
sysctl zfsSysctl // The sysctl of the ZFS metric.
|
sysctl zfsSysctl // The sysctl of the ZFS metric.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collector
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Factories["zfs"] = NewZFSCollector
|
Factories["zfs"] = NewZFSCollector
|
||||||
}
|
}
|
||||||
|
@ -49,6 +45,7 @@ type zfsCollector struct {
|
||||||
linuxPathMap map[string]string
|
linuxPathMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewZFSCollector returns a new Collector exposing ZFS statistics.
|
||||||
func NewZFSCollector() (Collector, error) {
|
func NewZFSCollector() (Collector, error) {
|
||||||
var z zfsCollector
|
var z zfsCollector
|
||||||
z.linuxProcpathBase = "spl/kstat/zfs"
|
z.linuxProcpathBase = "spl/kstat/zfs"
|
||||||
|
@ -65,14 +62,13 @@ func NewZFSCollector() (Collector, error) {
|
||||||
return &z, nil
|
return &z, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
for subsystem := range c.linuxPathMap {
|
for subsystem := range c.linuxPathMap {
|
||||||
err = c.updateZfsStats(subsystem, ch)
|
if err := c.updateZfsStats(subsystem, ch); err != nil {
|
||||||
switch {
|
if err == errZFSNotAvailable {
|
||||||
case err == zfsNotAvailableError:
|
log.Debug(err)
|
||||||
log.Debug(err)
|
return nil
|
||||||
return nil
|
}
|
||||||
case err != nil:
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) {
|
||||||
file, err = os.Open(procFilePath(path))
|
file, err = os.Open(procFilePath(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", procFilePath(path))
|
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", procFilePath(path))
|
||||||
err = zfsNotAvailableError
|
err = errZFSNotAvailable
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) (err error)
|
||||||
file, err := os.Open(zpoolPath)
|
file, err := os.Open(zpoolPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", zpoolPath)
|
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", zpoolPath)
|
||||||
return zfsNotAvailableError
|
return errZFSNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.parsePoolProcfsFile(file, zpoolPath, func(poolName string, s zfsSysctl, v int) {
|
err = c.parsePoolProcfsFile(file, zpoolPath, func(poolName string, s zfsSysctl, v int) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterAvailableCollectors(collectors string) string {
|
func filterAvailableCollectors(collectors string) string {
|
||||||
availableCollectors := make([]string, 0)
|
var availableCollectors []string
|
||||||
for _, c := range strings.Split(collectors, ",") {
|
for _, c := range strings.Split(collectors, ",") {
|
||||||
_, ok := collector.Factories[c]
|
_, ok := collector.Factories[c]
|
||||||
if ok {
|
if ok {
|
||||||
|
|
Loading…
Reference in a new issue