Skip to content

Collect swap usage via the container_swap_usage_bytes metric #1680

@iholder101

Description

@iholder101

What would you like to be added:
Swap usage metrics were added as part of kubernetes/kubernetes#118865 in the form of container_swap_usage_bytes.
Swap is an important resource, and it would be beneficial to include it as part of the PodMetrics() collection.

Essentially, this issue suggests that calling c.client.PodMetricses() would result with metrics that include swap usage.

The /metrics/resource endpoint looks as follows:

> kubectl get --raw "/api/v1/nodes/<NODE-NAME>/proxy/metrics/resource"
# HELP container_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the container in core-seconds
# TYPE container_cpu_usage_seconds_total counter
container_cpu_usage_seconds_total{container="c1",namespace="default",pod="test-pod"} 128.476535 1687950863878
container_cpu_usage_seconds_total{container="coredns",namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 0.915609 1687950855483
# HELP container_memory_working_set_bytes [ALPHA] Current working set of the container in bytes
# TYPE container_memory_working_set_bytes gauge
container_memory_working_set_bytes{container="c1",namespace="default",pod="test-pod"} 3.92847388672e+11 1687950863878
container_memory_working_set_bytes{container="coredns",namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 1.5310848e+07 1687950855483
# HELP container_start_time_seconds [ALPHA] Start time of the container since unix epoch in seconds
# TYPE container_start_time_seconds gauge
container_start_time_seconds{container="c1",namespace="default",pod="test-pod"} 1.6879504889662333e+09 1687950488966
container_start_time_seconds{container="coredns",namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 1.6879504537882898e+09 1687950453788
# HELP container_swap_usage_bytes [ALPHA] Current container amount of swap usage in bytes
# TYPE container_swap_usage_bytes gauge
container_swap_usage_bytes{container="c1",namespace="default",pod="test-pod"} 3.4400333824e+10 1687950863878
container_swap_usage_bytes{container="coredns",namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 0 1687950855483
# HELP node_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the node in core-seconds
# TYPE node_cpu_usage_seconds_total counter
node_cpu_usage_seconds_total 45770.147028 1687950863599
# HELP node_memory_working_set_bytes [ALPHA] Current working set of the node in bytes
# TYPE node_memory_working_set_bytes gauge
node_memory_working_set_bytes 3.95755573248e+11 1687950863599
# HELP node_swap_usage_bytes [ALPHA] Current node swap usage in bytes
# TYPE node_swap_usage_bytes gauge
node_swap_usage_bytes 1.8446743709127774e+19 1687950863599
# HELP pod_cpu_usage_seconds_total [ALPHA] Cumulative cpu time consumed by the pod in core-seconds
# TYPE pod_cpu_usage_seconds_total counter
pod_cpu_usage_seconds_total{namespace="default",pod="test-pod"} 123.291472 1687950858784
pod_cpu_usage_seconds_total{namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 5.101812 1687950863144
# HELP pod_memory_working_set_bytes [ALPHA] Current working set of the pod in bytes
# TYPE pod_memory_working_set_bytes gauge
pod_memory_working_set_bytes{namespace="default",pod="test-pod"} 3.92474558464e+11 1687950858784
pod_memory_working_set_bytes{namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 1.5499264e+07 1687950863144
# HELP pod_swap_usage_bytes [ALPHA] Current pod amount of swap usage in bytes
# TYPE pod_swap_usage_bytes gauge
pod_swap_usage_bytes{namespace="default",pod="test-pod"} 3.4379333632e+10 1687950858784
pod_swap_usage_bytes{namespace="kube-system",pod="coredns-8f5847b64-t9gmr"} 0 1687950863144
# HELP scrape_error [ALPHA] 1 if there was an error while getting container metrics, 0 otherwise
# TYPE scrape_error gauge
scrape_error 0

Why is this needed:
Swap is an important resource which I think is beneficial to reason about.
One consumer of this would be kubernetes/kubernetes#129458.

/kind feature

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions