Skip to main content

Prometheus Usage

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.


- job_name: opencost
honor_labels: true
scrape_interval: 1m
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
- targets:
- < address of opencost service> # example: <service-name>.<namespace>:<port>

Example queries

Below are a set of sample queries that can be run after Prometheus begins ingesting OpenCost data:

Monthly cost of top 5 containers

topk( 5,
container_memory_allocation_bytes* on(instance) group_left() node_ram_hourly_cost / 1024 / 1024 / 1024 * 730
container_cpu_allocation * on(instance) group_left() node_cpu_hourly_cost * 730

Hourly memory cost for the default namespace

avg(container_memory_allocation_bytes{namespace="default"}) by (instance) / 1024 / 1024 / 1024
on(instance) group_left() avg(node_ram_hourly_cost) by (instance)

Monthly cost of currently provisioned nodes

sum(node_total_hourly_cost) * 730

Available Metrics

Note: Memetrics today have both instance and node labels. The instance label will be deprecated in a future version.

node_cpu_hourly_costHourly cost per vCPU on this node
node_gpu_hourly_costHourly cost per GPU on this node
node_ram_hourly_costHourly cost per Gb of memory on this node
node_total_hourly_costTotal node cost per hour
opencost_load_balancer_costHourly cost of a load balancer
opencost_cluster_management_costHourly management fee per cluster
pv_hourly_costHourly cost per GP on a persistent volume
node_gpu_countNumber of GPUs available on node
container_cpu_allocationAverage number of CPUs requested/used over last 1m
container_gpu_allocationAverage number of GPUs requested over last 1m
container_memory_allocation_bytesAverage bytes of RAM requested/used over last 1m
pod_pvc_allocationBytes provisioned for a PVC attached to a pod
The Linux Foundation® (TLF) has registered trademarks and uses trademarks. For a list of TLF trademarks, see: Trademark Usage