PageSourceSearch

https://opencost.io/assets/js/526101bc.6876bc53.js

js opencost.io collected 2026-10-02 03:22:11 UTC 12,442 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkweb_opencost=globalThis.webpackChunkweb_opencost||[]).push([[6325],{6917(e,t,s){s.r(t),s.d(t,{assets:()=>i,contentTitle:()=>l,default:()=>d,frontMatter:()=>a,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"integrations/opencost-exporter","title":"OpenCost as a Prometheus metric exporter","description":"Running OpenCost as a Prometheus metric exporter allows you to export various cost metrics to Prometheus without setting up any other OpenCost dependencies. Doing so lets you write PromQL queries to calculate the cost and efficiency of any Kubernetes concept, e.g. namespace, service, label, deployment, etc. You can also calculate the cost of different Kubernetes resources, e.g. nodes, PVs, LoadBalancers, and more. Finally, you can do other interesting things like create custom alerts via AlertManager and custom dashboards via Grafana.","source":"@site/docs/integrations/opencost-exporter.md","sourceDirName":"integrations","slug":"/integrations/opencost-exporter","permalink":"/docs/integrations/opencost-exporter","draft":false,"unlisted":false,"editUrl":"https://github.com/opencost/opencost-website/tree/main/docs/integrations/opencost-exporter.md","tags":[],"version":"current","sidebarPosition":8,"frontMatter":{"sidebar_position":8},"sidebar":"docsSidebar","previous":{"title":"Working with Prometheus","permalink":"/docs/integrations/prometheus"},"next":{"title":"MCP Server","permalink":"/docs/integrations/mcp"}}');var o=s(4848),r=s(8453);const a={sidebar_position:8},l="OpenCost as a Prometheus metric exporter",i={},c=[{value:"Prometheus OpenCost Exporter Helm Chart",id:"prometheus-opencost-exporter-helm-chart",level:2},{value:"Prerequisites",id:"prerequisites",level:3},{value:"Add Helm Chart Repository",id:"add-helm-chart-repository",level:3},{value:"Install Chart",id:"install-chart",level:3},{value:"Uninstall Chart",id:"uninstall-chart",level:3},{value:"Upgrading Chart",id:"upgrading-chart",level:3},{value:"Configuration",id:"configuration",level:3},{value:"Installing Manually",id:"installing-manually",level:2},{value:"Dashboard examples",id:"dashboard-examples",level:2},{value:"Example Queries",id:"example-queries",level:2},{value:"Monthly cost of all nodes",id:"monthly-cost-of-all-nodes",level:3},{value:"Hourly cost of all load balancers broken down by namespace",id:"hourly-cost-of-all-load-balancers-broken-down-by-namespace",level:3},{value:"Monthly rate of each namespace&#39;s CPU request",id:"monthly-rate-of-each-namespaces-cpu-request",level:3},{value:"Historical memory request spend for all <code>fluentd</code> pods in the <code>kube-system</code> namespace",id:"historical-memory-request-spend-for-all-fluentd-pods-in-the-kube-system-namespace",level:3},{value:"Setting Cost Alerts",id:"setting-cost-alerts",level:2},{value:"Determine in real-time if the monthly cost of all nodes is &gt; $1000",id:"determine-in-real-time-if-the-monthly-cost-of-all-nodes-is--1000",level:3},{value:"Limitations",id:"limitations",level:2}];function h(e){const t={a:"a",blockquote:"blockquote",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",header:"header",img:"img",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.header,{children:(0,o.jsx)(t.h1,{id:"opencost-as-a-prometheus-metric-exporter",children:"OpenCost as a Prometheus metric exporter"})}),"\n",(0,o.jsx)(t.p,{children:"Running OpenCost as a Prometheus metric exporter allows you to export various cost metrics to Prometheus without setting up any other OpenCost dependencies. Doing so lets you write PromQL queries to calculate the cost and efficiency of any Kubernetes concept, e.g. namespace, service, label, deployment, etc. You can also calculate the cost of different Kubernetes resources, e.g. nodes, PVs, LoadBalancers, and more. Finally, you can do other interesting things like create custom alerts via AlertManager and custom dashboards via Grafana."}),"\n",(0,o.jsx)(t.h2,{id:"prometheus-opencost-exporter-helm-chart",children:"Prometheus OpenCost Exporter Helm Chart"}),"\n",(0,o.jsxs)(t.p,{children:["The ",(0,o.jsx)(t.a,{href:"https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-opencost-exporter",children:"Prometheus OpenCost Exporter"})," is available within the ",(0,o.jsx)(t.a,{href:"https://github.com/prometheus-community/helm-charts",children:"Prometheus Community Kubernetes Helm Charts"})," repository. This provides the Prometheus metric exporter capabilities without the OpenCost UI or any other additional capabilities. It is maintained as part of the regular OpenCost release process and regularly updated."]}),"\n",(0,o.jsx)(t.h3,{id:"prerequisites",children:"Prerequisites"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:"Kubernetes 1.23+"}),"\n",(0,o.jsx)(t.li,{children:"Helm 3+"}),"\n"]}),"\n",(0,o.jsx)(t.h3,{id:"add-helm-chart-repository",children:"Add Helm Chart Repository"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"helm repo add prometheus-community https://prometheus-community.github.io/helm-charts\nhelm repo update\n"})}),"\n",(0,o.jsx)(t.h3,{id:"install-chart",children:"Install Chart"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"helm install [RELEASE_NAME] prometheus-community/prometheus-opencost-exporter\n"})}),"\n",(0,o.jsx)(t.h3,{id:"uninstall-chart",children:"Uninstall Chart"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"helm uninstall [RELEASE_NAME]\n"})}),"\n",(0,o.jsx)(t.p,{children:"This removes all the Kubernetes components associated with the chart and deletes the release."}),"\n",(0,o.jsx)(t.h3,{id:"upgrading-chart",children:"Upgrading Chart"}),"\n",(0,o.jsx)(t.p,{children:"For minor version upgrades:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"helm upgrade [RELEASE_NAME] [CHART] --install\n"})}),"\n",(0,o.jsx)(t.h3,{id:"configuration",children:"Configuration"}
1),"\n",(0,o.jsxs)(t.p,{children:["To see all configurable options with detailed comments, visit the chart's ",(0,o.jsx)(t.a,{href:"https://github.com/prometheus-community/helm-charts/blob/main/charts/prometheus-opencost-exporter/values.yaml",children:"values.yaml"}),", or run:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"helm show values prometheus-community/prometheus-opencost-exporter\n"})}),"\n",(0,o.jsx)(t.h2,{id:"installing-manually",children:"Installing Manually"}),"\n",(0,o.jsxs)(t.blockquote,{children:["\n",(0,o.jsxs)(t.p,{children:["Note: all deployments of OpenCost function as a Prometheus metric exporter. ",(0,o.jsx)(t.a,{href:"/docs/installation/install",children:"View recommended install"}),"."]}),"\n"]}),"\n",(0,o.jsx)(t.p,{children:"Follow these steps to set up OpenCost as exporter-only:"}),"\n",(0,o.jsxs)(t.ol,{children:["\n",(0,o.jsxs)(t.li,{children:["\n",(0,o.jsx)(t.p,{children:"Apply the combined YAML:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"kubectl apply --namespace opencost-exporter \\\n-f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/exporter/opencost-exporter.yaml\n"})}),"\n"]}),"\n",(0,o.jsxs)(t.li,{children:["\n",(0,o.jsx)(t.p,{children:"To verify that metrics are available:"}),"\n"]}),"\n"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-sh",children:"kubectl port-forward --namespace opencost-exporter service/opencost 9003\n"})}),"\n",(0,o.jsxs)(t.p,{children:[(0,o.jsx)(t.code,{children:"curl http://localhost:9003/metrics"})," to see exported metrics"]}),"\n",(0,o.jsxs)(t.p,{children:["Add OpenCost scrape config to your Prometheus (",(0,o.jsx)(t.a,{href:"https://prometheus.io/docs/introduction/first_steps/#configuring-prometheus",children:"more info"}),"):"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-yaml",children:"- job_name: opencost\n scrape_interval: 1m\n scrape_timeout: 10s\n metrics_path: /metrics\n scheme: http\n static_configs:\n - targets: ['opencost.opencost-exporter:9003']\n"})}),"\n",(0,o.jsx)(t.p,{children:"OpenCost is now exporting cost metrics. See the following sections for different metrics available and query examples."}),"\n",(0,o.jsx)(t.h2,{id:"dashboard-examples",children:"Dashboard examples"}),"\n",(0,o.jsx)(t.p,{children:"Here's an example dashboard using OpenCost Prometheus metrics:"}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.img,{src:"https://grafana.com/api/dashboards/8670/images/5480/image",alt:"sample dashboard"})}),"\n",(0,o.jsxs)(t.p,{children:["You can find other example dashboards at ",(0,o.jsx)(t.a,{href:"https://grafana.com/orgs/kubecost",children:"https://grafana.com/orgs/kubecost"})]}),"\n",(0,o.jsx)(t.h2,{id:"example-queries",children:"Example Queries"}),"\n",(0,o.jsx)(t.p,{children:"Once OpenCost's cost model is running in your cluster and you have added it in your Prometheus scrape configuration, you can hit Prometheus with useful queries like these:"}),"\n",(0,o.jsx)(t.h3,{id:"monthly-cost-of-all-nodes",children:"Monthly cost of all nodes"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-text",children:"sum(node_total_hourly_cost) * 730\n"})}),"\n",(0,o.jsx)(t.h3,{id:"hourly-cost-of-all-load-balancers-broken-down-by-namespace",children:"Hourly cost of all load balancers broken down by namespace"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-text",children:"sum(kubecost_load_balancer_cost) by (namespace)\n"})}),"\n",(0,o.jsx)(t.h3,{id:"monthly-rate-of-each-namespaces-cpu-request",children:"Monthly rate of each namespace's CPU request"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-text",children:"sum(container_cpu_allocation * on (node) group_left node_cpu_hourly_cost) by (namespace) * 730\n"})}),"\n",(0,o.jsxs)(t.h3,{id:"historical-memory-request-spend-for-all-fluentd-pods-in-the-kube-system-namespace",children:["Historical memory request spend for all ",(0,o.jsx)(t.code,{children:"fluentd"})," pods in the ",(0,o.jsx)(t.code,{children:"kube-system"})," namespace"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-text",children:'avg_over_time(container_memory_allocation_bytes{namespace="kube-system",pod=~"fluentd.*"}[1d])\n * on (pod,node) group_left\navg(count_over_time(container_memory_allocation_bytes{namespace="kube-system"}[1d:1m])/60) by (pod,node)\n * on (node) group_left\navg(avg_over_time(node_ram_hourly_cost[1d] )) by (node)\n'})}),"\n",(0,o.jsxs)(t.p,{children:["For more comprehensive examples and detailed metric information, please refer to our ",(0,o.jsx)(t.a,{href:"metrics",children:"OpenCost Metrics Reference Guide"}),"."]}),"\n",(0,o.jsx)(t.h2,{id:"setting-cost-alerts",children:"Setting Cost Alerts"}),"\n",(0,o.jsx)(t.p,{children:"Custom cost alerts can be implemented with a set of Prometheus queries and can be used for alerting with AlertManager or Grafana alerts. Below are example alerting rules."}),"\n",(0,o.jsx)(t.h3,{id:"determine-in-real-time-if-the-monthly-cost-of-all-nodes-is--1000",children:"Determine in real-time if the monthly cost of all nodes is > $1000"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-text",children:"sum(node_total_hourly_cost) * 730 > 1000\n"})}),"\n",(0,o.jsx)(t.h2,{id:"limitations",children:"Limitations"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsx)(t.li,{children:"For large cluster
1s, these Prometheus queries might not scale well over large time windows."}),"\n",(0,o.jsxs)(t.li,{children:["Allocation metrics, like ",(0,o.jsx)(t.code,{children:"container_cpu_allocation"})," only contain ",(0,o.jsx)(t.em,{children:"requests"})," and do not take usage into account."]}),"\n",(0,o.jsx)(t.li,{children:"Related to the previous point, efficiency metrics are not available."}),"\n"]})]})}function d(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(h,{...e})}):h(e)}},8453(e,t,s){s.d(t,{R:()=>a,x:()=>l});var n=s(6540);const o={},r=n.createContext(o);function a(e){const t=n.useContext(r);return n.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),n.createElement(r.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.