From bfc1369346417251f6cfd58a0778e0e67552f0af Mon Sep 17 00:00:00 2001 From: kongfei Date: Sat, 6 Jul 2024 07:00:54 +0800 Subject: [PATCH] chore:options to disable md5 info gathering for procstat --- inputs/procstat/procstat.go | 43 ++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/inputs/procstat/procstat.go b/inputs/procstat/procstat.go index d1b78de9..4bc5b9ee 100644 --- a/inputs/procstat/procstat.go +++ b/inputs/procstat/procstat.go @@ -33,6 +33,7 @@ type Instance struct { SearchWinService string `toml:"search_win_service"` SearchUser string `toml:"search_user"` Mode string `toml:"mode"` + GatherMD5 bool `toml:"gather_md5"` GatherTotal bool `toml:"gather_total"` GatherPerPid bool `toml:"gather_per_pid"` GatherMoreMetrics []string `toml:"gather_more_metrics"` @@ -206,30 +207,32 @@ func (ins *Instance) Gather(slist *types.SampleList) { if comm, err := p.Name(); err == nil { info["comm"] = comm } - info["binary_md5sum"] = "" - if cmd, err := p.Cmdline(); err == nil { - md5b := md5.Sum([]byte(cmd)) - sum := hex.EncodeToString(md5b[:]) - info["cmdline_md5sum"] = sum - } - if runtime.GOOS == "linux" { - if exe, err := p.Exe(); err == nil { - cached, ok := exeMd5cache[exe] - if ok { - info["binary_md5sum"] = cached - } else if sum, err := md5sum(exe); err == nil { - info["binary_md5sum"] = sum - exeMd5cache[exe] = sum - } else { - if ins.DebugMod { - log.Println("E! failed to get md5sum of exe:", exe, "pid:", p.PID(), err) - } - if sum, err := md5sum(fmt.Sprintf("/proc/%d/exe", pid)); err == nil { + if ins.GatherMD5 { + info["binary_md5sum"] = "" + if cmd, err := p.Cmdline(); err == nil { + md5b := md5.Sum([]byte(cmd)) + sum := hex.EncodeToString(md5b[:]) + info["cmdline_md5sum"] = sum + } + if runtime.GOOS == "linux" { + if exe, err := p.Exe(); err == nil { + cached, ok := exeMd5cache[exe] + if ok { + info["binary_md5sum"] = cached + } else if sum, err := md5sum(exe); err == nil { info["binary_md5sum"] = sum exeMd5cache[exe] = sum } else { if ins.DebugMod { - log.Println("E! failed to get md5sum of /proc/pid/exe:", p.PID(), err) + log.Println("E! failed to get md5sum of exe:", exe, "pid:", p.PID(), err) + } + if sum, err := md5sum(fmt.Sprintf("/proc/%d/exe", pid)); err == nil { + info["binary_md5sum"] = sum + exeMd5cache[exe] = sum + } else { + if ins.DebugMod { + log.Println("E! failed to get md5sum of /proc/pid/exe:", p.PID(), err) + } } } }