Skip to content

Commit

Permalink
refactor: reduce ipmi log
Browse files Browse the repository at this point in the history
  • Loading branch information
tanxiao1990 committed Jun 13, 2024
1 parent beda1a1 commit d92ad58
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 5 additions & 2 deletions inputs/ipmi/exporter/collector_ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/prometheus/client_golang/prometheus"

cfg "flashcat.cloud/categraf/config"
"flashcat.cloud/categraf/inputs/ipmi/exporter/freeipmi"
)

Expand Down Expand Up @@ -167,11 +168,13 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
case "N/A":
state = math.NaN()
default:
log.Println("msg", "Unknown sensor state", "target", targetHost, "state", data.State)
log.Println("W!", "Unknown sensor state", "target", targetHost, "state", data.State)
state = math.NaN()
}

log.Println("msg", "Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))
if cfg.Config.DebugMode {
log.Println("D!", "Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))
}

switch data.Unit {
case "RPM":
Expand Down
10 changes: 8 additions & 2 deletions inputs/ipmi/exporter/collector_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/prometheus/client_golang/prometheus"

cfg "flashcat.cloud/categraf/config"
"flashcat.cloud/categraf/inputs/ipmi/exporter/freeipmi"
)

Expand Down Expand Up @@ -84,7 +85,10 @@ func Collect(ch chan<- prometheus.Metric, host, binPath string, config IPMIConfi
start := time.Now()
defer func() {
duration := time.Since(start).Seconds()
log.Println("msg", "Scrape duration", "target", targetName(host), "duration", duration)

if cfg.Config.DebugMode {
log.Println("D!", "Scrape duration", "target", targetName(host), "duration", duration)
}
ch <- prometheus.MustNewConstMetric(
durationDesc,
prometheus.GaugeValue,
Expand All @@ -99,7 +103,9 @@ func Collect(ch chan<- prometheus.Metric, host, binPath string, config IPMIConfi

for _, collector := range config.GetCollectors() {
var up int
log.Println("msg", "Running collector", "target", target.host, "collector", collector.Name())
if cfg.Config.DebugMode {
log.Println("D!", "Running collector", "target", target.host, "collector", collector.Name())
}

fqcmd := path.Join(binPath, collector.Cmd())
args := collector.Args()
Expand Down
7 changes: 6 additions & 1 deletion inputs/ipmi/exporter/freeipmi/freeipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"strconv"
"strings"
"syscall"

cfg "flashcat.cloud/categraf/config"
)

var (
Expand Down Expand Up @@ -152,7 +154,10 @@ func Execute(cmd string, args []string, config string, target string) Result {
args = append(args, "-h", target)
}

log.Println("msg", "Executing", "command", cmd, "args", fmt.Sprintf("%+v", args))
if cfg.Config.DebugMode {
log.Println("D!", "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)
Expand Down

0 comments on commit d92ad58

Please sign in to comment.