mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
fix cpu resource metric type by changing to counter
This commit is contained in:
parent
8508875e4d
commit
86192d4b9a
@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nodeCPUUsageDesc = metrics.NewDesc("node_cpu_usage_seconds",
|
nodeCPUUsageDesc = metrics.NewDesc("node_cpu_usage_seconds_total",
|
||||||
"Cumulative cpu time consumed by the node in core-seconds",
|
"Cumulative cpu time consumed by the node in core-seconds",
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
@ -40,7 +40,7 @@ var (
|
|||||||
metrics.ALPHA,
|
metrics.ALPHA,
|
||||||
"")
|
"")
|
||||||
|
|
||||||
containerCPUUsageDesc = metrics.NewDesc("container_cpu_usage_seconds",
|
containerCPUUsageDesc = metrics.NewDesc("container_cpu_usage_seconds_total",
|
||||||
"Cumulative cpu time consumed by the container in core-seconds",
|
"Cumulative cpu time consumed by the container in core-seconds",
|
||||||
[]string{"container", "pod", "namespace"},
|
[]string{"container", "pod", "namespace"},
|
||||||
nil,
|
nil,
|
||||||
@ -120,7 +120,7 @@ func (rc *resourceMetricsCollector) collectNodeCPUMetrics(ch chan<- metrics.Metr
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- metrics.NewLazyMetricWithTimestamp(s.CPU.Time.Time,
|
ch <- metrics.NewLazyMetricWithTimestamp(s.CPU.Time.Time,
|
||||||
metrics.NewLazyConstMetric(nodeCPUUsageDesc, metrics.GaugeValue, float64(*s.CPU.UsageCoreNanoSeconds)/float64(time.Second)))
|
metrics.NewLazyConstMetric(nodeCPUUsageDesc, metrics.CounterValue, float64(*s.CPU.UsageCoreNanoSeconds)/float64(time.Second)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *resourceMetricsCollector) collectNodeMemoryMetrics(ch chan<- metrics.Metric, s summary.NodeStats) {
|
func (rc *resourceMetricsCollector) collectNodeMemoryMetrics(ch chan<- metrics.Metric, s summary.NodeStats) {
|
||||||
@ -138,7 +138,7 @@ func (rc *resourceMetricsCollector) collectContainerCPUMetrics(ch chan<- metrics
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch <- metrics.NewLazyMetricWithTimestamp(s.CPU.Time.Time,
|
ch <- metrics.NewLazyMetricWithTimestamp(s.CPU.Time.Time,
|
||||||
metrics.NewLazyConstMetric(containerCPUUsageDesc, metrics.GaugeValue,
|
metrics.NewLazyConstMetric(containerCPUUsageDesc, metrics.CounterValue,
|
||||||
float64(*s.CPU.UsageCoreNanoSeconds)/float64(time.Second), s.Name, pod.PodRef.Name, pod.PodRef.Namespace))
|
float64(*s.CPU.UsageCoreNanoSeconds)/float64(time.Second), s.Name, pod.PodRef.Name, pod.PodRef.Namespace))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ func TestCollectResourceMetrics(t *testing.T) {
|
|||||||
testTime := metav1.NewTime(time.Unix(2, 0)) // a static timestamp: 2000
|
testTime := metav1.NewTime(time.Unix(2, 0)) // a static timestamp: 2000
|
||||||
interestedMetrics := []string{
|
interestedMetrics := []string{
|
||||||
"scrape_error",
|
"scrape_error",
|
||||||
"node_cpu_usage_seconds",
|
"node_cpu_usage_seconds_total",
|
||||||
"node_memory_working_set_bytes",
|
"node_memory_working_set_bytes",
|
||||||
"container_cpu_usage_seconds",
|
"container_cpu_usage_seconds_total",
|
||||||
"container_memory_working_set_bytes",
|
"container_memory_working_set_bytes",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +85,9 @@ func TestCollectResourceMetrics(t *testing.T) {
|
|||||||
},
|
},
|
||||||
summaryErr: nil,
|
summaryErr: nil,
|
||||||
expectedMetrics: `
|
expectedMetrics: `
|
||||||
# HELP node_cpu_usage_seconds [ALPHA] Cumulative cpu time consumed by the node in core-seconds
|
# HELP node_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the node in core-seconds
|
||||||
# TYPE node_cpu_usage_seconds gauge
|
# TYPE node_cpu_usage_seconds_total counter
|
||||||
node_cpu_usage_seconds 10 2000
|
node_cpu_usage_seconds_total 10 2000
|
||||||
# HELP node_memory_working_set_bytes [ALPHA] Current working set of the node in bytes
|
# HELP node_memory_working_set_bytes [ALPHA] Current working set of the node in bytes
|
||||||
# TYPE node_memory_working_set_bytes gauge
|
# TYPE node_memory_working_set_bytes gauge
|
||||||
node_memory_working_set_bytes 1000 2000
|
node_memory_working_set_bytes 1000 2000
|
||||||
@ -156,11 +156,11 @@ func TestCollectResourceMetrics(t *testing.T) {
|
|||||||
# HELP scrape_error [ALPHA] 1 if there was an error while getting container metrics, 0 otherwise
|
# HELP scrape_error [ALPHA] 1 if there was an error while getting container metrics, 0 otherwise
|
||||||
# TYPE scrape_error gauge
|
# TYPE scrape_error gauge
|
||||||
scrape_error 0
|
scrape_error 0
|
||||||
# HELP container_cpu_usage_seconds [ALPHA] Cumulative cpu time consumed by the container in core-seconds
|
# HELP container_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the container in core-seconds
|
||||||
# TYPE container_cpu_usage_seconds gauge
|
# TYPE container_cpu_usage_seconds_total counter
|
||||||
container_cpu_usage_seconds{container="container_a",namespace="namespace_a",pod="pod_a"} 10 2000
|
container_cpu_usage_seconds_total{container="container_a",namespace="namespace_a",pod="pod_a"} 10 2000
|
||||||
container_cpu_usage_seconds{container="container_a",namespace="namespace_b",pod="pod_b"} 10 2000
|
container_cpu_usage_seconds_total{container="container_a",namespace="namespace_b",pod="pod_b"} 10 2000
|
||||||
container_cpu_usage_seconds{container="container_b",namespace="namespace_a",pod="pod_a"} 10 2000
|
container_cpu_usage_seconds_total{container="container_b",namespace="namespace_a",pod="pod_a"} 10 2000
|
||||||
# HELP container_memory_working_set_bytes [ALPHA] Current working set of the container in bytes
|
# HELP container_memory_working_set_bytes [ALPHA] Current working set of the container in bytes
|
||||||
# TYPE container_memory_working_set_bytes gauge
|
# TYPE container_memory_working_set_bytes gauge
|
||||||
container_memory_working_set_bytes{container="container_a",namespace="namespace_a",pod="pod_a"} 1000 2000
|
container_memory_working_set_bytes{container="container_a",namespace="namespace_a",pod="pod_a"} 1000 2000
|
||||||
|
Loading…
Reference in New Issue
Block a user