Summary
Display CPU and memory usage per pod/node by querying the Kubernetes metrics-server API.
Motivation
k9s shows real-time CPU/memory metrics. This is expected by users monitoring workloads. metrics-server is installed on most clusters (EKS, GKE, AKS all ship it by default).
Requirements
Metrics Source
- Query
metrics.k8s.io/v1beta1 API via kube-rs
- Pod metrics:
PodMetrics (cpu, memory per container)
- Node metrics:
NodeMetrics (cpu, memory, capacity)
- kube-rs has
kube::api::Api<PodMetrics> support
Display
- Optional columns:
CPU and MEM (e.g., 45m, 128Mi)
- Show as percentage of request/limit when available:
45m/100m (45%)
- For nodes: show usage vs allocatable:
2.1/4 cores, 6.2/8 Gi
- Color: green (<70%), yellow (70-90%), red (>90%)
Config
[metrics]
enabled = true # default true — disable for clusters without metrics-server
refresh_interval_secs = 15 # how often to refresh metrics
show_percentage = true # show % of request/limit
Implementation
- Create periodic metrics refresh task (separate from watcher)
- Store metrics in a
HashMap<(namespace, name), PodMetrics> shared via Arc<RwLock<>>
- Merge metrics into
K8sItem display at render time
- Don't block item display waiting for metrics — show "-" until first fetch
Graceful Degradation
- If metrics-server not installed: API returns 404 → disable metrics silently
- Log: "metrics-server not available, disabling CPU/MEM columns"
- No column shown if no metrics data
Acceptance Criteria
Summary
Display CPU and memory usage per pod/node by querying the Kubernetes metrics-server API.
Motivation
k9s shows real-time CPU/memory metrics. This is expected by users monitoring workloads. metrics-server is installed on most clusters (EKS, GKE, AKS all ship it by default).
Requirements
Metrics Source
metrics.k8s.io/v1beta1API via kube-rsPodMetrics(cpu, memory per container)NodeMetrics(cpu, memory, capacity)kube::api::Api<PodMetrics>supportDisplay
CPUandMEM(e.g.,45m,128Mi)45m/100m (45%)2.1/4 cores,6.2/8 GiConfig
Implementation
HashMap<(namespace, name), PodMetrics>shared viaArc<RwLock<>>K8sItemdisplay at render timeGraceful Degradation
Acceptance Criteria