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

Kubernetes.container.cpu.usage.node.pct reports capacity rather than documented allocatable usage #39906

Open
kevinsmithwrs opened this issue Jun 14, 2024 · 0 comments
Labels
Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team

Comments

@kevinsmithwrs
Copy link

According to the docs here:
https://www.elastic.co/guide/en/beats/metricbeat/current/exported-fields-kubernetes.html

The kubernetes.container.cpu.usage.node.pct and kubernetes.container.memory.usage.node.pct are supposed to report the node allocatable usage percentages, however they actually report node capacity percentages.

The relevant code is here:

if cpu, ok := r.Status.Capacity["cpu"]; ok {

<Snip inline below?

	}
	switch r := r.(type) {
	case *kubernetes.Pod:
		return map[string]mapstr.M{id: specificMetaGen.Generate(r)}
	case *kubernetes.Node:
		nodeName := r.GetObjectMeta().GetName()
		metrics := NewNodeMetrics()
		if cpu, ok := r.Status.Capacity["cpu"]; ok {
			if q, err := resource.ParseQuantity(cpu.String()); err == nil {
				metrics.CoresAllocatable = NewFloat64Metric(float64(q.MilliValue()) / 1000)
			}
		}
		if memory, ok := r.Status.Capacity["memory"]; ok {
			if q, err := resource.ParseQuantity(memory.String()); err == nil {
				metrics.MemoryAllocatable = NewFloat64Metric(float64(q.Value()))
			}
		}
		nodeStore, _ := metricsRepo.AddNodeStore(nodeName)

Indeed changing the the code from "Capacity" to "Allocatable" in the line above fixes the problem. I notice the Memory usage calculation is also likewise incorrect on line 632 of the above source.

Can this be fixed please?

Thanks,

Kevin

For confirmed bugs, please report:

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 14, 2024
@ycombinator ycombinator added Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team
Projects
None yet
Development

No branches or pull requests

2 participants