Expand description
Prometheus client for historical metrics. Prometheus Client for historical Kubernetes metrics.
Fetches historical CPU/memory usage data from Prometheus to calculate percentile values (P50, P95, P99, max) for accurate right-sizing.
§Prerequisites
- Prometheus accessible (via port-forward, ingress, or direct URL)
- Prometheus collecting Kubernetes metrics (typically via kube-state-metrics and cAdvisor)
§Authentication
Authentication is optional and typically not needed when using kubectl port-forward
because the connection goes directly to the pod, bypassing ingress/auth layers.
Auth is only needed for externally exposed Prometheus instances.
§Example
ⓘ
use syncable_cli::analyzer::k8s_optimize::prometheus_client::{PrometheusClient, PrometheusAuth};
// Default: No authentication (works with port-forward)
let client = PrometheusClient::new("http://localhost:9090")?;
// With authentication (for external Prometheus)
let client = PrometheusClient::with_auth(
"https://prometheus.example.com",
PrometheusAuth::Bearer("token123".to_string())
)?;
let history = client.get_container_history("default", "api-gateway", "main", "7d").await?;
println!("CPU P99: {}m", history.cpu_p99);Structs§
- Container
History - Historical resource usage data for a container.
- Historical
Recommendation - Right-sizing recommendation based on historical data.
- Prometheus
Client - Prometheus client for querying historical metrics.
- Workload
History - Aggregated history for a workload (Deployment/StatefulSet/etc).
Enums§
- Prometheus
Auth - Authentication method for Prometheus (optional).
- Prometheus
Error - Error type for Prometheus client operations.