chore!: adopt slog, drop go-kit/log

The bulk of this change set was automated by the following script which
is being used to aid in converting the various exporters/projects to use
slog:

https://gist.github.com/tjhop/49f96fb7ebbe55b12deee0b0312d8434

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
This commit is contained in:
TJ Hoplock 2024-10-17 20:09:00 -04:00
parent 90d956b434
commit 90bb0c0c16
17 changed files with 92 additions and 101 deletions

View File

@ -7,7 +7,7 @@ executors:
# also be updated.
golang:
docker:
- image: cimg/go:1.21
- image: cimg/go:1.23
jobs:
test:
executor: golang

View File

@ -7,6 +7,4 @@ issues:
linters-settings:
errcheck:
exclude-functions:
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
exclude-functions: []

View File

@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here,
# .circleci/config.yml should also be updated.
version: 1.21
version: 1.23
repository:
path: github.com/prometheus-community/ipmi_exporter

View File

@ -17,7 +17,6 @@ import (
"path"
"time"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -81,7 +80,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {
start := time.Now()
defer func() {
duration := time.Since(start).Seconds()
level.Debug(logger).Log("msg", "Scrape duration", "target", targetName(c.target), "duration", duration)
logger.Debug("Scrape duration", "target", targetName(c.target), "duration", duration)
ch <- prometheus.MustNewConstMetric(
durationDesc,
prometheus.GaugeValue,
@ -97,7 +96,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {
for _, collector := range config.GetCollectors() {
var up int
level.Debug(logger).Log("msg", "Running collector", "target", target.host, "collector", collector.Name())
logger.Debug("Running collector", "target", target.host, "collector", collector.Name())
fqcmd := collector.Cmd()
if !path.IsAbs(fqcmd) {

View File

@ -14,7 +14,6 @@
package main
import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -50,18 +49,18 @@ func (c BMCCollector) Args() []string {
func (c BMCCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
firmwareRevision, err := freeipmi.GetBMCInfoFirmwareRevision(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC data", "target", targetName(target.host), "error", err)
return 0, err
}
manufacturerID, err := freeipmi.GetBMCInfoManufacturerID(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC data", "target", targetName(target.host), "error", err)
return 0, err
}
systemFirmwareVersion, err := freeipmi.GetBMCInfoSystemFirmwareVersion(result)
if err != nil {
// This one is not always available.
level.Debug(logger).Log("msg", "Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
logger.Debug("Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
systemFirmwareVersion = "N/A"
}
ch <- prometheus.MustNewConstMetric(

View File

@ -14,7 +14,6 @@
package main
import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -95,42 +94,42 @@ func (c BMCWatchdogCollector) Args() []string {
func (c BMCWatchdogCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
timerState, err := freeipmi.GetBMCWatchdogTimerState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog timer", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog timer", "target", targetName(target.host), "error", err)
return 0, err
}
currentTimerUse, err := freeipmi.GetBMCWatchdogTimerUse(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog timer use", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog timer use", "target", targetName(target.host), "error", err)
return 0, err
}
loggingState, err := freeipmi.GetBMCWatchdogLoggingState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog logging", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog logging", "target", targetName(target.host), "error", err)
return 0, err
}
currentTimeoutAction, err := freeipmi.GetBMCWatchdogTimeoutAction(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog timeout action", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog timeout action", "target", targetName(target.host), "error", err)
return 0, err
}
currentPretimeoutInterrupt, err := freeipmi.GetBMCWatchdogPretimeoutInterrupt(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog pretimeout interrupt", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog pretimeout interrupt", "target", targetName(target.host), "error", err)
return 0, err
}
pretimeoutInterval, err := freeipmi.GetBMCWatchdogPretimeoutInterval(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog pretimeout interval", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog pretimeout interval", "target", targetName(target.host), "error", err)
return 0, err
}
initialCountdown, err := freeipmi.GetBMCWatchdogInitialCountdown(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog initial countdown", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog initial countdown", "target", targetName(target.host), "error", err)
return 0, err
}
currentCountdown, err := freeipmi.GetBMCWatchdogCurrentCountdown(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog current countdown", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog current countdown", "target", targetName(target.host), "error", err)
return 0, err
}

View File

@ -14,7 +14,6 @@
package main
import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -62,17 +61,17 @@ func (c ChassisCollector) Args() []string {
func (c ChassisCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentChassisPowerState, err := freeipmi.GetChassisPowerState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
currentChassisDriveFault, err := freeipmi.GetChassisDriveFault(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
currentChassisCoolingFault, err := freeipmi.GetChassisCoolingFault(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(

View File

@ -14,7 +14,6 @@
package main
import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -50,7 +49,7 @@ func (c DCMICollector) Args() []string {
func (c DCMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentPowerConsumption, err := freeipmi.GetCurrentPowerConsumption(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect DCMI data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect DCMI data", "target", targetName(target.host), "error", err)
return 0, err
}
// Returned value negative == Power Measurement is not avail

View File

@ -18,7 +18,6 @@ import (
"math"
"strconv"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -148,7 +147,7 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
targetHost := targetName(target.host)
results, err := freeipmi.GetSensorData(result, excludeIds)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect sensor data", "target", targetHost, "error", err)
logger.Error("Failed to collect sensor data", "target", targetHost, "error", err)
return 0, err
}
for _, data := range results {
@ -164,11 +163,11 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
case "N/A":
state = math.NaN()
default:
level.Error(logger).Log("msg", "Unknown sensor state", "target", targetHost, "state", data.State)
logger.Error("Unknown sensor state", "target", targetHost, "state", data.State)
state = math.NaN()
}
level.Debug(logger).Log("msg", "Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))
logger.Debug("Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))
switch data.Unit {
case "RPM":

View File

@ -14,7 +14,6 @@
package main
import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -57,12 +56,12 @@ func (c SELCollector) Args() []string {
func (c SELCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
entriesCount, err := freeipmi.GetSELInfoEntriesCount(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect SEL data", "target", targetName(target.host), "error", err)
return 0, err
}
freeSpace, err := freeipmi.GetSELInfoFreeSpace(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect SEL data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(

View File

@ -16,7 +16,6 @@ package main
import (
"time"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -75,7 +74,7 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus
events, err := freeipmi.GetSELEvents(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL events", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect SEL events", "target", targetName(target.host), "error", err)
return 0, err
}
@ -103,7 +102,7 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus
// ID,Date,Time,Name,Type,State,Event
// 3,PostInit,PostInit,Sensor #211,Memory,Warning,Correctable memory error ; Event Data3 = 34h
if err != nil {
level.Debug(logger).Log("msg", "Failed to parse time", "target", targetName(target.host), "error", err)
logger.Debug("Failed to parse time", "target", targetName(target.host), "error", err)
} else {
newTimestamp = float64(t.Unix())
}

View File

@ -17,7 +17,6 @@ import (
"fmt"
"strconv"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -53,11 +52,11 @@ func (c SMLANModeCollector) Args() []string {
func (c SMLANModeCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
octets, err := freeipmi.GetRawOctets(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect LAN mode data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect LAN mode data", "target", targetName(target.host), "error", err)
return 0, err
}
if len(octets) != 3 {
level.Error(logger).Log("msg", "Unexpected number of octets", "target", targetName(target.host), "octets", octets)
logger.Error("Unexpected number of octets", "target", targetName(target.host), "octets", octets)
return 0, fmt.Errorf("unexpected number of octets in raw response: %d", len(octets))
}
@ -66,7 +65,7 @@ func (c SMLANModeCollector) Collect(result freeipmi.Result, ch chan<- prometheus
value, _ := strconv.Atoi(octets[2])
ch <- prometheus.MustNewConstMetric(lanModeDesc, prometheus.GaugeValue, float64(value))
default:
level.Error(logger).Log("msg", "Unexpected lan mode status (ipmi-raw)", "target", targetName(target.host), "sgatus", octets[2])
logger.Error("Unexpected lan mode status (ipmi-raw)", "target", targetName(target.host), "sgatus", octets[2])
return 0, fmt.Errorf("unexpected lan mode status: %s", octets[2])
}

View File

@ -20,7 +20,6 @@ import (
"strings"
"sync"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus-community/ipmi_exporter/freeipmi"
@ -239,7 +238,7 @@ func (sc *SafeConfig) ReloadConfig(configFile string) error {
if configFile != "" {
config, err = os.ReadFile(configFile)
if err != nil {
level.Error(logger).Log("msg", "Error reading config file", "error", err)
logger.Error("Error reading config file", "error", err)
return err
}
} else {
@ -255,7 +254,7 @@ func (sc *SafeConfig) ReloadConfig(configFile string) error {
sc.Unlock()
if configFile != "" {
level.Info(logger).Log("msg", "Loaded config file", "path", configFile)
logger.Info("Loaded config file", "path", configFile)
}
return nil
}
@ -281,7 +280,7 @@ func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig {
if module != "default" {
config, ok = sc.C.Modules[module]
if !ok {
level.Error(logger).Log("msg", "Requested module not found, using default", "module", module, "target", targetName(target))
logger.Error("Requested module not found, using default", "module", module, "target", targetName(target))
}
}
@ -290,7 +289,7 @@ func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig {
config, ok = sc.C.Modules["default"]
if !ok {
// This is probably fine for running locally, so not making this a warning
level.Debug(logger).Log("msg", "Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target))
logger.Debug("Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target))
config = defaultConfig
}
}

View File

@ -20,6 +20,7 @@ import (
"encoding/csv"
"encoding/hex"
"fmt"
"log/slog"
"math"
"os"
"os/exec"
@ -28,9 +29,6 @@ import (
"strconv"
"strings"
"syscall"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
)
var (
@ -124,7 +122,7 @@ func getValue(ipmiOutput []byte, regex *regexp.Regexp) (string, error) {
return "", fmt.Errorf("could not find value in output: %s", string(ipmiOutput))
}
func freeipmiConfigPipe(config string, logger log.Logger) (string, error) {
func freeipmiConfigPipe(config string, logger *slog.Logger) (string, error) {
content := []byte(config)
pipe, err := pipeName()
if err != nil {
@ -138,24 +136,24 @@ func freeipmiConfigPipe(config string, logger log.Logger) (string, error) {
go func(file string, data []byte) {
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModeNamedPipe)
if err != nil {
level.Error(logger).Log("msg", "Error opening pipe", "error", err)
logger.Error("Error opening pipe", "error", err)
}
if _, err := f.Write(data); err != nil {
level.Error(logger).Log("msg", "Error writing config to pipe", "error", err)
logger.Error("Error writing config to pipe", "error", err)
}
f.Close()
}(pipe, content)
return pipe, nil
}
func Execute(cmd string, args []string, config string, target string, logger log.Logger) Result {
func Execute(cmd string, args []string, config string, target string, logger *slog.Logger) Result {
pipe, err := freeipmiConfigPipe(config, logger)
if err != nil {
return Result{nil, err}
}
defer func() {
if err := os.Remove(pipe); err != nil {
level.Error(logger).Log("msg", "Error deleting named pipe", "error", err)
logger.Error("Error deleting named pipe", "error", err)
}
}()
@ -164,7 +162,7 @@ func Execute(cmd string, args []string, config string, target string, logger log
args = append(args, "-h", target)
}
level.Debug(logger).Log("msg", "Executing", "command", cmd, "args", fmt.Sprintf("%+v", args))
logger.Debug("Executing", "command", cmd, "args", fmt.Sprintf("%+v", args))
out, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
err = fmt.Errorf("error running %s: %s", cmd, err)

22
go.mod
View File

@ -1,13 +1,12 @@
module github.com/prometheus-community/ipmi_exporter
go 1.19
go 1.22
require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/go-kit/log v0.2.1
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/common v0.59.1
github.com/prometheus/exporter-toolkit v0.11.0
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/common v0.60.0
github.com/prometheus/exporter-toolkit v0.13.0
gopkg.in/yaml.v2 v2.4.0
)
@ -16,19 +15,20 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/mdlayher/vsock v1.2.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

46
go.sum
View File

@ -11,36 +11,41 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ=
github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g=
github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q=
github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA=
github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
github.com/prometheus/exporter-toolkit v0.13.0 h1:lmA0Q+8IaXgmFRKw09RldZmZdnvu9wwcDLIXGmTPw1c=
github.com/prometheus/exporter-toolkit v0.13.0/go.mod h1:2uop99EZl80KdXhv/MxVI2181fMcwlsumFOqBecGkG0=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@ -52,22 +57,23 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

29
main.go
View File

@ -15,18 +15,17 @@ package main
import (
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
kingpin "github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/promslog/flag"
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
@ -48,7 +47,7 @@ var (
}
reloadCh chan chan error
logger log.Logger
logger *slog.Logger
)
func remoteIPMIHandler(w http.ResponseWriter, r *http.Request) {
@ -68,7 +67,7 @@ func remoteIPMIHandler(w http.ResponseWriter, r *http.Request) {
return
}
level.Debug(logger).Log("msg", "Scraping target", "target", target, "module", module)
logger.Debug("Scraping target", "target", target, "module", module)
registry := prometheus.NewRegistry()
remoteCollector := metaCollector{target: target, module: module, config: sc}
@ -86,25 +85,25 @@ func updateConfiguration(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("failed to reload config: %s", err), http.StatusInternalServerError)
}
default:
level.Error(logger).Log("msg", "Only POST requests allowed", "url", r.URL)
logger.Error("Only POST requests allowed", "url", r.URL)
w.Header().Set("Allow", "POST")
http.Error(w, "Only POST requests allowed", http.StatusMethodNotAllowed)
}
}
func main() {
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
promslogConfig := &promslog.Config{}
flag.AddFlags(kingpin.CommandLine, promslogConfig)
kingpin.CommandLine.UsageWriter(os.Stdout)
kingpin.HelpFlag.Short('h')
kingpin.Version(version.Print("ipmi_exporter"))
kingpin.Parse()
logger = promlog.New(promlogConfig)
level.Info(logger).Log("msg", "Starting ipmi_exporter", "version", version.Info())
logger = promslog.New(promslogConfig)
logger.Info("Starting ipmi_exporter", "version", version.Info())
// Bail early if the config is bad.
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Error parsing config file", "error", err)
logger.Error("Error parsing config file", "error", err)
os.Exit(1)
}
@ -116,11 +115,11 @@ func main() {
select {
case <-hup:
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Error reloading config", "error", err)
logger.Error("Error reloading config", "error", err)
}
case rc := <-reloadCh:
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Error reloading config", "error", err)
logger.Error("Error reloading config", "error", err)
rc <- err
} else {
rc <- nil
@ -167,7 +166,7 @@ func main() {
srv := &http.Server{}
if err := web.ListenAndServe(srv, webConfig, logger); err != nil {
level.Error(logger).Log("msg", "HTTP listener stopped", "error", err)
logger.Error("HTTP listener stopped", "error", err)
os.Exit(1)
}
}