Skip to content

Commit

Permalink
chore:options to disable md5 info gathering for procstat (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 authored Jul 5, 2024
1 parent e3313a6 commit 33a1520
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions inputs/procstat/procstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 33a1520

Please sign in to comment.