Skip to content

Commit

Permalink
Merge branch 'main' into slack
Browse files Browse the repository at this point in the history
  • Loading branch information
mattray authored Aug 30, 2023
2 parents a7056f5 + 19dca13 commit a6b0cb8
Showing 1 changed file with 76 additions and 7 deletions.
83 changes: 76 additions & 7 deletions docs/integrations/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,87 @@ OpenCost allows you to export pricing data to Prometheus and then write custom q

## 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__
__Total cost of the cluster workload the last 30 days__

```
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
sort_desc(
sum by (type, namespace) (
sum_over_time(
(
label_replace(
(
(
avg by (container, node, namespace, pod) (container_memory_allocation_bytes)
* on (node) group_left ()
avg by (node) (node_ram_hourly_cost)
)
/
(1024 * 1024 * 1024)
),
"type",
"ram",
"",
""
)
or
label_replace(
(
avg by (container, node, namespace, pod) (container_cpu_allocation)
* on (node) group_left ()
avg by (node) (node_cpu_hourly_cost)
),
"type",
"cpu",
"",
""
)
or
label_replace(
(
avg by (container, node, namespace, pod) (container_gpu_allocation)
* on (node) group_left ()
avg by (node) (node_gpu_hourly_cost)
),
"type",
"gpu",
"",
""
)
or
label_replace(
(
(
avg by (persistentvolume, namespace, pod) (pod_pvc_allocation)
* on (persistentvolume) group_left ()
avg by (persistentvolume) (pv_hourly_cost)
)
/
(1024 * 1024 * 1024)
),
"type",
"storage",
"",
""
)
)[30d:5m]
)
/
scalar(count_over_time(vector(1)[30d:5m]))
* 24 * 30
)
)
```

- `30` Represents the duration over which the data is aggregated, which is 30 days in this case.
- `5m` Defines the accuracy of the data. Modify this to adjust precision:
- **Decrease** (e.g., to `1m`): Enhances accuracy. It's typically not recommended to set it below the Prometheus scraping interval (`1m` by default)
- **Increase** Enhances the performance of the query.
- `sum by (type, namespace)` controls the grouping, available options are `container, namespace, node, pod, type`


__Hourly memory cost for the *default* namespace__

```
Expand All @@ -45,10 +114,10 @@ sum(
)
```

__Monthly cost of currently provisioned nodes__
__Monthly cost of provisioned nodes__

```
sum(node_total_hourly_cost) * 730
sum(sum_over_time(node_total_hourly_cost[30d:1h]))
```


Expand Down

0 comments on commit a6b0cb8

Please sign in to comment.