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

otel.process.context_switches metric counts only the context switches of the main thread #36804

Open
tobiasstarkwayve opened this issue Dec 12, 2024 · 1 comment
Labels
bug Something isn't working needs triage New item requiring triage receiver/hostmetrics

Comments

@tobiasstarkwayve
Copy link

Component(s)

receiver/hostmetrics

What happened?

Description

The otel.process.context_switches metric claims to count context switches for a given process. It obtains the number of context switches from /proc/<pid>/status (through https://github.com/shirou/gopsutil). Unfortunately, this file counts only the context switches of the lead thread on Linux. Calling it the context switches of the process is hence misleading.

Steps to Reproduce

Log into a Linux machine, find a process with multiple threads, and compare the context-switch count. It can happen that a thread has more context switches than the process context-switch count. Example:

cat /proc/4491/status /proc/4491/task/4491/status /proc/4491/task/4495/status | grep nonvoluntary
nonvoluntary_ctxt_switches:     9
nonvoluntary_ctxt_switches:     9
nonvoluntary_ctxt_switches:     139

Expected Result

Either the metric should note that is is correct only for single-threaded processes, or the scraper should go through all threads within the same process and sum up their individual context switches

Actual Result

The metric reports the context switches of the lead thread as if they were the context switches of the entire process

Collector version

0.110.0

Environment information

Environment

OS: Ubuntu 20.04
Compiler(if manually compiled):

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

@tobiasstarkwayve tobiasstarkwayve added bug Something isn't working needs triage New item requiring triage labels Dec 12, 2024
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New item requiring triage receiver/hostmetrics
Projects
None yet
Development

No branches or pull requests

1 participant