Skip to content

Commit 3f41630

Browse files
committed
Detailed error information when reading process metrics fails
1 parent d57be1c commit 3f41630

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

metrics/proc_metrics.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,33 @@ type ProcessMetrics struct {
2121
func getProcMetrics(pid int) (processMetrics *ProcessMetrics, err error) {
2222
proc, err := process.NewProcess(int32(pid))
2323
if err != nil {
24-
return nil, err
24+
return nil, fmt.Errorf("could not open PID %d: %w", pid, err)
2525
}
2626
m := &ProcessMetrics{}
2727
m.cpu, err = proc.CPUPercent()
2828
if err != nil {
29-
return nil, err
29+
return nil, fmt.Errorf("could not read CPU usage of PID %d: %w", pid, err)
3030
}
3131
mem, err := proc.MemoryInfo()
3232
if err != nil {
33-
return nil, err
33+
return nil, fmt.Errorf("could not read memory info of PID %d: %w", pid, err)
3434
}
3535
m.ram = mem.RSS
3636
m.swap = mem.Swap
3737
ioDisk, err := proc.IOCounters()
3838
if err != nil {
39-
return nil, err
39+
return nil, fmt.Errorf("could not read disk IO info of PID %d: %w", pid, err)
4040
}
4141
m.diskReadBytes = ioDisk.ReadBytes
4242
m.diskWriteBytes = ioDisk.WriteBytes
4343
m.diskReadCount = ioDisk.ReadCount
4444
m.diskWriteCount = ioDisk.WriteCount
4545
ioNet, err := proc.NetIOCounters(false)
4646
if err != nil {
47-
return nil, err
47+
return nil, fmt.Errorf("could not read net IO info of PID %d: %w", pid, err)
4848
}
4949
if len(ioNet) > 1 {
50-
return nil, fmt.Errorf("got IO info for all NICs seperately when sum was requested")
50+
return nil, fmt.Errorf("got IO info for multiple NICs seperately when total sum was requested for PID %d", pid)
5151
}
5252
if len(ioNet) == 1 {
5353
m.networkInBytes = ioNet[0].BytesRecv

0 commit comments

Comments
 (0)