Overview
The Kubernetes Dashboard Metrics API provides access to resource metrics through integration with the metrics-scraper sidecar. Metrics include CPU usage, memory usage, and custom application metrics.Metrics Architecture
The metrics system consists of:- Metrics-Scraper Sidecar: Collects metrics from Kubernetes metrics server
- Integration Manager: Manages metrics provider connections
- Metric Client: Downloads and aggregates metric data
- REST API: Exposes metrics through Dashboard endpoints
Configuration
Metrics Provider
Metrics provider to useOptions:
sidecar: Use the metrics-scraper sidecar (default)none: Disable metrics collection
Metrics-scraper sidecar host URLExample:
http://dashboard-metrics-scraper:8000Health check interval for metrics client
In-Cluster Configuration
When running in-cluster, the sidecar is accessed via Kubernetes service:Metrics Integration
Sidecar Integration
The API integrates with the metrics-scraper sidecar:Health Check
Check metrics integration health:Health check for sidecar metrics integration
Whether the integration is healthy
Health status message
Available Metrics
CPU Metrics
CPU usage in nanocores
CPU request in nanocores
CPU limit in nanocores
Memory Metrics
Memory usage in bytes
Memory request in bytes
Memory limit in bytes
Query Parameters
Metric Names
Comma-separated list of metrics to retrieveExample:
metricNames=cpu/usage,memory/usageAggregations
Aggregation method for metricsOptions:
sum: Sum all valuesavg: Average of valuesmin: Minimum valuemax: Maximum value
Resource-Specific Metrics
Many resource endpoints support themetricNames query parameter to include metrics in the response.
Pod Metrics
Get pods with CPU and memory metrics
Example Request
Example Response
Deployment Metrics
Get deployments with aggregated metrics from all pods
Node Metrics
Get nodes with system metrics
Metric Data Structures
Metric Object
Name of the metric (e.g.,
cpu/usage)Array of data points for chartingStructure:
Array of metric points with timestampsStructure:
Resource labels for the metricStructure:
Sidecar REST API
The metrics-scraper sidecar exposes its own REST API:Base Path
Pod Metrics
Get metrics for a specific pod
Batch Pod Metrics
Get metrics for multiple pods in one request
Node Metrics
Get metrics for a specific node
Metric Client Interface
The Dashboard uses a metric client interface to download and aggregate metrics:Download Metrics
Aggregate Metrics
Resource Selectors
Metric downloads use resource selectors to specify target resources:Example
Aggregation Modes
Sum Aggregation
Adds all metric values:Average Aggregation
Calculates the mean:Min/Max Aggregation
Finds minimum or maximum values:Batch Metric Downloads
The system optimizes metric downloads by:- Compressing selectors: Combining similar requests
- Batch downloads: Downloading multiple resources in one request
- Parallel processing: Using goroutines for concurrent downloads
All-in-One Downloads
Supported resource types for batch downloads:- Pods
- Nodes
- PersistentVolumeClaims
Metric Promises
Metrics are returned as promises for asynchronous processing:Usage Example
Prometheus Metrics
The Dashboard exposes its own Prometheus metrics at:Prometheus metrics endpoint
Available Metrics
Total API requests by verb, resource, client, content type, and codeLabels:
verb, resource, client, contentType, codeRequest latency distribution in microsecondsLabels:
verb, resourceBuckets: 125ms, 250ms, 500ms, 1s, 2s, 4s, 8sRequest latency summary with 1-hour sliding windowLabels:
verb, resourceError Handling
Metric Unavailable
When metrics are not available:Sidecar Connection Error
If the sidecar is unreachable:Example: Complete Metrics Query
Request
Response
Best Practices
Performance
- Request only needed metrics: Don’t request all metrics if you only need CPU
- Use aggregations: Let the API aggregate instead of doing it client-side
- Batch requests: Request metrics for multiple resources in list endpoints
- Cache results: Implement client-side caching for dashboards
Metric Selection
Troubleshooting
- Check sidecar health: Verify metrics-scraper is running
- Verify metrics-server: Ensure metrics-server is deployed in cluster
- Check RBAC: Ensure service account has metrics read permissions
- Review logs: Check Dashboard and sidecar logs for errors