mirror of
https://github.com/prometheus-community/ipmi_exporter
synced 2024-12-23 14:32:16 +00:00
67041ef633
- Move every collector into its own file - Move FreeIPMI code into own package - Allow more customization of commands executed by collectors - Split up documentation, so README is a little less overwhelming A single commit message does not do justice to the amount of changes here, but hey... :)
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
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
|
|
}
|