forked from prometheus-community/ipmi_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector_chassis.go
49 lines (40 loc) · 1.1 KB
/
collector_chassis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/soundcloud/ipmi_exporter/freeipmi"
)
const (
ChassisCollectorName CollectorName = "chassis"
)
var (
chassisPowerStateDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "chassis", "power_state"),
"Current power state (1=on, 0=off).",
[]string{},
nil,
)
)
type ChassisCollector struct{}
func (c ChassisCollector) Name() CollectorName {
return ChassisCollectorName
}
func (c ChassisCollector) Cmd() string {
return "ipmi-chassis"
}
func (c ChassisCollector) Args() []string {
return []string{"--get-chassis-status"}
}
func (c ChassisCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentChassisPowerState, err := freeipmi.GetChassisPowerState(result)
if err != nil {
log.Errorf("Failed to collect chassis data from %s: %s", targetName(target.host), err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(
chassisPowerStateDesc,
prometheus.GaugeValue,
currentChassisPowerState,
)
return 1, nil
}