Add new metric config_lan_mode

This commit is contained in:
Jakub Chábek 2020-05-20 14:14:43 +02:00
parent 26628185da
commit 534775f13a
2 changed files with 43 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"crypto/rand" "crypto/rand"
"encoding/csv" "encoding/csv"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"math" "math"
"os" "os"
@ -189,6 +190,13 @@ var (
nil, nil,
nil, nil,
) )
lanModeDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "config", "lan_mode"),
"Returns configured LAN mode.",
nil,
nil,
)
) )
func pipeName() string { func pipeName() string {
@ -404,6 +412,7 @@ func (c collector) Describe(ch chan<- *prometheus.Desc) {
ch <- selFreeSpaceDesc ch <- selFreeSpaceDesc
ch <- upDesc ch <- upDesc
ch <- durationDesc ch <- durationDesc
ch <- lanModeDesc
} }
func collectTypedSensor(ch chan<- prometheus.Metric, desc, stateDesc *prometheus.Desc, state float64, data sensorData) { func collectTypedSensor(ch chan<- prometheus.Metric, desc, stateDesc *prometheus.Desc, state float64, data sensorData) {
@ -491,6 +500,37 @@ func collectMonitoring(ch chan<- prometheus.Metric, target ipmiTarget) (int, err
return 1, nil return 1, nil
} }
func collectSmLanMode(ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
output, err := freeipmiOutput("ipmi-raw", target, "0x0", "0x30", "0x70", "0x0c", "0")
if err != nil {
log.Errorf("Failed to collect sm-lan-mode data from %s: %s", targetName(target.host), err)
return 0, err
}
strOutput := strings.Trim(string(output), " \r\n")
if !strings.HasPrefix(strOutput, "rcvd: ") {
log.Errorf("Unexpected output of ipmi-raw from %s: %s", targetName(target.host), strOutput)
return 0, errors.New("unexpected output")
}
octects := strings.Split(strOutput[6:], " ")
if len(octects) != 3 {
log.Errorf("Unexpected number of octects of ipmi-raw from %s: %+v", targetName(target.host), octects)
return 0, errors.New("unexpected number of octects")
}
switch octects[2] {
case "00", "01", "02":
value, _ := strconv.Atoi(octects[2])
ch <- prometheus.MustNewConstMetric(lanModeDesc, prometheus.GaugeValue, float64(value))
default:
log.Errorf("Unexpected lan mode status (ipmi-raw) from %s: %+v", targetName(target.host), octects[2])
return 0, errors.New("unexpected lan mode status")
}
return 1, nil
}
func collectDCMI(ch chan<- prometheus.Metric, target ipmiTarget) (int, error) { func collectDCMI(ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
output, err := ipmiDCMIOutput(target) output, err := ipmiDCMIOutput(target)
if err != nil { if err != nil {
@ -617,6 +657,8 @@ func (c collector) Collect(ch chan<- prometheus.Metric) {
switch collector { switch collector {
case "ipmi": case "ipmi":
up, _ = collectMonitoring(ch, target) up, _ = collectMonitoring(ch, target)
case "sm-lan-mode":
up, _ = collectSmLanMode(ch, target)
case "dcmi": case "dcmi":
up, _ = collectDCMI(ch, target) up, _ = collectDCMI(ch, target)
case "bmc": case "bmc":

View File

@ -79,7 +79,7 @@ func (s *IPMIConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err return err
} }
for _, c := range s.Collectors { for _, c := range s.Collectors {
if !(c == "ipmi" || c == "dcmi" || c == "bmc" || c == "chassis" || c == "sel") { if !(c == "ipmi" || c == "sm-lan-mode" || c == "dcmi" || c == "bmc" || c == "chassis" || c == "sel") {
return fmt.Errorf("unknown collector name: %s", c) return fmt.Errorf("unknown collector name: %s", c)
} }
} }