prometheus-net.DotNetRuntime
prometheus-net.DotNetRuntime copied to clipboard
process_cpu_count is no longer accurate in .NET Core 3.1
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
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.
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
?
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
.