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

Add label "comm" from /proc to prometheus metrics #367

Open
ancoron opened this issue Feb 24, 2024 · 1 comment
Open

Add label "comm" from /proc to prometheus metrics #367

ancoron opened this issue Feb 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@ancoron
Copy link

ancoron commented Feb 24, 2024

Problem

For many processes on Linux, reading /proc/<pid>/exe or /proc/<pid>/cmdline does not yield any values, making it impossible to say "what" was it that consumed some energy.

Solution

At least as a workaround, reading /proc/<pid>/comm always yields something.

Alternatives

I am not aware of alternative ways to determine the executable or "name" of a process.

Additional context

Example Prometheus metrics query that prints out the comm value for every PID where there was no associated cmdline:

curl -s 'http://localhost:9876/metrics' | grep -F 'scaph_process_power_consumption_microwatts' | sed -n -E '/cmdline=""/ {s/^.*pid="([^"]+)".*$/\1/p}' | sort -n | while read -r process_id; do printf "PID %s: " "$process_id"; cat "/proc/$process_id/comm"; done
PID 2: kthreadd
PID 3: pool_workqueue_release
PID 4: kworker/R-rcu_g
PID 5: kworker/R-rcu_p
PID 6: kworker/R-slub_
PID 7: kworker/R-netns
PID 10: kworker/0:0H-events_highpri
PID 13: kworker/R-mm_pe
PID 14: rcu_tasks_kthread
PID 15: rcu_tasks_rude_kthread
PID 16: rcu_tasks_trace_kthread
PID 17: ksoftirqd/0
PID 18: rcu_preempt
PID 19: rcub/1
PID 20: migration/0
PID 21: idle_inject/0
PID 22: cpuhp/0
PID 23: cpuhp/1
PID 24: idle_inject/1
PID 25: migration/1
PID 26: ksoftirqd/1
PID 28: kworker/1:0H-events_highpri
PID 29: cpuhp/2
PID 30: idle_inject/2
PID 31: migration/2
PID 32: ksoftirqd/2
PID 34: kworker/2:0H-events_highpri
PID 35: cpuhp/3
PID 36: idle_inject/3
PID 37: migration/3
PID 38: ksoftirqd/3
PID 40: kworker/3:0H-events_highpri
PID 41: cpuhp/4
PID 42: idle_inject/4
PID 43: migration/4
PID 44: ksoftirqd/4
PID 46: kworker/4:0H-events_highpri
PID 47: cpuhp/5
PID 48: idle_inject/5
PID 49: migration/5
PID 50: ksoftirqd/5
PID 52: kworker/5:0H-events_highpri
PID 53: cpuhp/6
PID 54: idle_inject/6
PID 55: migration/6
PID 56: ksoftirqd/6
PID 59: cpuhp/7
PID 60: idle_inject/7
PID 61: migration/7
PID 62: ksoftirqd/7
PID 64: kworker/7:0H-events_highpri
PID 65: cpuhp/8
PID 66: idle_inject/8
PID 67: migration/8
PID 68: ksoftirqd/8
PID 70: kworker/8:0H-events_highpri
PID 71: cpuhp/9
PID 72: idle_inject/9
PID 73: migration/9
PID 74: ksoftirqd/9
PID 77: cpuhp/10
PID 78: idle_inject/10
PID 79: migration/10
PID 80: ksoftirqd/10
PID 82: kworker/10:0H-events_highpri
PID 83: cpuhp/11
PID 84: idle_inject/11
PID 85: migration/11
PID 86: ksoftirqd/11
PID 88: kworker/11:0H-events_highpri
PID 89: cpuhp/12
PID 90: idle_inject/12
PID 91: migration/12
PID 92: ksoftirqd/12
PID 94: kworker/12:0H-events_highpri
PID 95: cpuhp/13
PID 96: idle_inject/13
PID 97: migration/13
PID 98: ksoftirqd/13
PID 100: kworker/13:0H-events_highpri
PID 101: cpuhp/14
PID 102: idle_inject/14
PID 103: migration/14
PID 104: ksoftirqd/14
PID 106: kworker/14:0H-events_highpri
PID 107: cpuhp/15
PID 108: idle_inject/15
PID 109: migration/15
PID 110: ksoftirqd/15
PID 112: kworker/15:0H-kblockd
PID 113: kdevtmpfs
PID 114: kworker/R-inet_
PID 115: kauditd
PID 118: khungtaskd
PID 119: oom_reaper
PID 121: kworker/R-write
PID 122: kcompactd0
PID 123: ksmd
PID 126: khugepaged
PID 127: kworker/R-kinte
PID 128: kworker/R-kbloc
PID 129: kworker/R-blkcg
PID 131: kworker/R-tpm_d
PID 132: kworker/R-ata_s
PID 133: kworker/R-edac-
PID 134: kworker/R-devfr
PID 135: watchdogd
PID 136: kworker/1:1H-kblockd
PID 137: irq/25-AMD-Vi0-Evt
PID 138: irq/26-AMD-Vi0-PPR
PID 139: irq/27-AMD-Vi0-GA
PID 140: kswapd0
PID 141: kworker/R-kthro
PID 154: kworker/R-acpi_
PID 156: kworker/R-mld
PID 157: kworker/R-ipv6_
PID 165: kworker/R-kstrp
PID 166: kworker/R-zswap
PID 167: kworker/u65:0
PID 184: kworker/12:1H-kblockd
PID 185: kworker/11:1H-kblockd
PID 192: kworker/2:1H-kblockd
PID 195: kworker/R-amdgp
PID 200: kworker/R-ttm
PID 201: kworker/R-amdgp
PID 202: kworker/R-amdgp
PID 203: kworker/R-amdgp
PID 204: kworker/R-dm_vb
PID 205: card1-crtc0
PID 206: card1-crtc1
PID 207: card1-crtc2
PID 208: card1-crtc3
PID 209: gfx_low
PID 210: gfx_high
PID 211: comp_1.0.0
PID 212: comp_1.1.0
PID 213: comp_1.2.0
PID 214: comp_1.3.0
PID 215: comp_1.0.1
PID 216: comp_1.1.1
PID 217: comp_1.2.1
PID 218: comp_1.3.1
PID 219: sdma0
PID 220: vcn_dec
PID 221: vcn_enc0
PID 222: vcn_enc1
PID 223: jpeg_dec
PID 228: kworker/14:1H-kblockd
PID 235: kworker/7:1H-kblockd
PID 258: kworker/5:1H-kblockd
PID 259: kworker/6:1H-kblockd
PID 260: kworker/13:1H-kblockd
PID 261: kworker/8:1H-kblockd
PID 262: kworker/4:1H-kblockd
PID 263: kworker/10:1H-kblockd
PID 264: kworker/0:1H-kblockd
PID 265: kworker/9:1H-kblockd
PID 267: kworker/R-crypt
PID 268: kworker/R-nvme-
PID 269: kworker/R-nvme-
PID 270: kworker/R-nvme-
PID 271: kworker/R-nvme-
PID 272: kworker/3:1H-kblockd
PID 481: kworker/R-kdmfl
PID 485: kworker/R-kcryp
PID 486: kworker/R-kcryp
PID 487: dmcrypt_write/254:0
PID 492: kworker/R-kdmfl
PID 493: kworker/R-kdmfl
PID 495: kworker/R-kdmfl
PID 519: jbd2/dm-2-8
PID 520: kworker/R-ext4-
PID 526: kworker/u64:6-kcryptd/254:0
PID 628: psimon
PID 786: jbd2/dm-3-8
PID 787: kworker/R-ext4-
PID 871: kworker/R-cfg80
PID 2043: kworker/R-wg-cr
PID 2824: kworker/9:2H-ttm
PID 2859: kworker/15:2H-ttm
PID 2961: kworker/6:3H
PID 5409: kworker/2:1-events
PID 5423: kworker/14:0-events
PID 5854: kworker/12:1-events
PID 5894: kworker/1:2-events
PID 5915: kworker/3:0-wg-crypt-moz0
PID 5923: kworker/7:1-events
PID 5926: kworker/0:0-events
PID 5932: kworker/4:0-events
PID 5948: kworker/u64:1-flush-254:3
PID 5950: kworker/u64:4-kcryptd/254:0
PID 5963: kworker/13:2-events
PID 5965: kworker/11:1-events
PID 6047: kworker/8:2-events
PID 6071: kworker/5:1-events
PID 6092: kworker/10:1-events
PID 6098: kworker/6:1-events
PID 6113: kworker/1:1-wg-crypt-moz0
PID 6114: kworker/4:1-events
PID 6121: kworker/13:0-events
PID 6242: kworker/u64:5-events_unbound
PID 6243: kworker/u64:7-kcryptd/254:0
PID 6244: kworker/u64:8-kcryptd/254:0
PID 6371: kworker/9:1-events
PID 6419: kworker/14:2-events
PID 6420: kworker/15:0-events
PID 6567: psimon
PID 6689: kworker/u64:9+events_unbound
PID 6867: kworker/3:1-events
PID 6877: kworker/u64:10-kcryptd/254:0
PID 6890: kworker/11:0-events
PID 6919: kworker/9:0-events
PID 6934: kworker/10:0-events
PID 6938: kworker/5:2-events
PID 6949: kworker/15:1-events
PID 6972: kworker/6:0-events
PID 6990: kworker/8:0-events
PID 6992: kworker/14:1-events
PID 6994: kworker/1:3-events
PID 6999: kworker/12:2-events
PID 7000: kworker/0:2-events
PID 7009: kworker/u64:11-kcryptd/254:0
PID 7010: kworker/2:2-events
PID 7013: kworker/7:2-events
PID 7021: kworker/4:2-events
PID 7058: kworker/3:2-events
PID 7101: bash
PID 7117: kworker/13:1-events
PID 7145: kworker/11:2-mm_percpu_wq
PID 7220: kworker/10:2-events
PID 7272: kworker/12:0-events
PID 7273: kworker/0:1-events
PID 7277: kworker/1:0-events
PID 7278: kworker/8:1-events
PID 7279: kworker/9:2-events
PID 7286: kworker/15:2-events
PID 7287: kworker/2:0-mm_percpu_wq
PID 7288: kworker/6:2-events
PID 7548: kworker/7:0-events

As you can see, a lot of processes are managed by the Kernel itself, not any executable.

Also note PID 7101 above, bringing up "bash", which essentially is an actual process but a zombie, so reading comm helps here as well:

$ cat /proc/7101/cmdline 
$ cat /proc/7101/exe 
cat: /proc/7101/exe: No such file or directory
$ cat /proc/7101/comm 
bash
@ancoron ancoron added the enhancement New feature or request label Feb 24, 2024
@ancoron
Copy link
Author

ancoron commented Feb 25, 2024

TBH, the naming is a bit weird and kinda gets in the way here:

  • to provide the exe label, function utils::get_process_name is invoked
  • ...which reads field comm from IProcess
  • ...which is provided by reading exe from sysinfo::Process

So:

exe => comm => name

This should be cleaned up into just exe all the way, since it really is NOT comm and neither is the "name" of a process.

ancoron added a commit to ancoron/scaphandre that referenced this issue Feb 25, 2024
ancoron added a commit to ancoron/scaphandre that referenced this issue Feb 25, 2024
@bpetit bpetit added this to General Jun 19, 2024
@bpetit bpetit moved this to Triage in General Jun 19, 2024
meslubi2021 added a commit to Unity-Energy-and-renewable-energy/scaphandre that referenced this issue Aug 25, 2024
feat: add actual process name to attributes - refs hubblo-org#367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Triage
Development

No branches or pull requests

1 participant