Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reduce ipmi log #971

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以参考用ins.debug。 这样--debug --inputs 就可以只输出当前插件的debug日志。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我看下

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
Loading