prometheus-net.DotNetRuntime icon indicating copy to clipboard operation
prometheus-net.DotNetRuntime copied to clipboard

process_cpu_count is no longer accurate in .NET Core 3.1

Open amrmahdi opened this issue 5 years ago • 3 comments

Please see https://github.com/dotnet/runtime/issues/622 for reference. Given that the cpu count is now reported as the number of cores on the node, not on the container, this metric is no longer accurate.

https://github.com/djluck/prometheus-net.DotNetRuntime/blob/4ae69225822816b7102a244992adf6a17c333016/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsCollector.cs#L137

amrmahdi avatar Dec 06 '19 22:12 amrmahdi

Interesting stuff- thanks for creating this issue @amrmahdi. https://github.com/dotnet/coreclr/issues/26053 seems to suggest some future workaround (i.e. Environment.ProcessorQuota) but for now, there's not a lot that can be done.

djluck avatar Dec 07 '19 01:12 djluck

What if we detect that the process is running a container using DOTNET_RUNNING_IN_CONTAINER then read the CPU shares from /sys/fs/cgroup/cpu/cpu.shares ?

amrmahdi avatar Dec 07 '19 06:12 amrmahdi

Actually that is really not needed, since container_spec_cpu_shares counter already published this metric. So I guess if using .NET Core 3.1 one can update the grafana dashboard to use container_spec_cpu_shares instead of process_cpu_count .

amrmahdi avatar Dec 07 '19 06:12 amrmahdi