Skip to content

Commit

Permalink
feat: add md5sum label of binary and cmdline for procstat
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 committed Apr 18, 2024
1 parent 1a8c871 commit 1be63fe
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions inputs/procstat/procstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ func (ins *Instance) Gather(slist *types.SampleList) {
}

ins.updateProcesses(pids)
for pid, p := range ins.procs {
info := map[string]string{
"pid": fmt.Sprint(pid),
}
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 {
if sum, err := md5sum(exe); err == nil {
info["binary_md5sum"] = sum
} else {
if ins.DebugMod {

Check failure on line 204 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 exe:", exe, "pid:", p.PID(), err)
}
}
}
}
slist.PushFront(types.NewSample(inputName, "info", 1, info, tags))
}

for _, field := range ins.GatherMoreMetrics {
switch field {
Expand Down Expand Up @@ -259,18 +285,7 @@ func (ins *Instance) makeProcTag(p Process) map[string]string {
if err == nil {
info["comm"] = comm
}
info["md5sum"] = ""
if runtime.GOOS == "linux" {
if exe, err := p.Exe(); err == nil {
if sum, err := md5sum(exe); err == nil {
info["md5sum"] = sum
} else {
if ins.DebugMod {
log.Println("E! failed to get md5sum of exe:", exe, "pid:", p.PID(), err)
}
}
}
}

if runtime.GOOS == "windows" {
title := getWindowTitleByPid(uint32(p.PID()))
if len(title) != 0 {
Expand Down

0 comments on commit 1be63fe

Please sign in to comment.