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

chore: options to disable md5 info gathering for procstat #996

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
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
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 @@
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 @@
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 {

Check failure on line 233 in inputs/procstat/procstat.go

View workflow job for this annotation

GitHub Actions / Code Analysis

ins.DebugMod undefined (type *Instance has no field or method DebugMod) (typecheck)
log.Println("E! failed to get md5sum of /proc/pid/exe:", p.PID(), err)
}
}
}
}
Expand Down
Loading