Working with Prometheus
OpenCost allows you to export pricing data to Prometheus and then write custom queries for cost insights. Below are instructions for accomplishing this and a set of example queries to get you started.
Note: Configuring a Prometheus client is not necessary to emit cost metrics.
Configuration
- job_name: opencost
honor_labels: true
scrape_interval: 1m
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- < address of opencost service> # example: <service-name>.<namespace>:<port>
Metrics Reference
For a comprehensive list of all metrics used and generated by OpenCost, including:
- Required metrics from external sources (node-exporter, kube-state-metrics)
- Generated cost metrics
- Internal operation metrics
- Best practices for metric filtering and usage
- Example queries and troubleshooting
Please refer to our OpenCost Metrics Reference Guide.
Quick Start Examples
Below are a few sample queries to get you started with OpenCost and Prometheus:
Monthly cost of all nodes
sum(node_total_hourly_cost) * 730
Hourly cost of all load balancers broken down by namespace
sum(kubecost_load_balancer_cost) by (namespace)
Monthly rate of each namespace's CPU request
sum(avg(container_cpu_allocation) by (namespace)) * 730
For more comprehensive examples and detailed metric information, please refer to our OpenCost Metrics Reference Guide.