Datadog is a monitoring and security platform which teams use for cloud applications or cloud monitoring as a service. It is possible to integrate your installed Kubecost with Datadog to receive real-time cost monitoring and visualization in your Datadog dashboard. This article will show you everything you need to do this.
Before you get started, you will need the following:
Datadog account with API key and account permissions to create dashboards
Kubernetes cluster with permission to access and deploy new workloads
When installing your Datadog agent, you need to enable the following flags to allow the Datadog agent to collect the metrics from Kubecost’s cost-model container:
datadog.prometheusScrape.enabled=true
datadog.prometheusScrape.serviceEndpoints=true
To do this, start by setting up your Datadog API key as an environment variable. You can get the API key after logging into your Datadog account by selecting your account > Organization Settings > API Keys. The value of DATADOG_API_KEY
below can be found by selecting the line item and copying your API key (do not use the value in the Key ID column).
Finally, install the Datadog agent with your API key using the following command:
Install Kubecost using the following command to allow the Datadog agent to collect the metrics:
Allow 3-5 minutes to have the Kubecost installation completed, at which point the metrics are pushed into your Datadog account. Run the following command to enable port-forwarding and expose the Kubecost dashboard:
You can now access the Kubecost dashboard by navigating to http://localhost:9090
in your web browser.
First, verify if your Kubecost metrics are available in your Datadog account by using Datadog's Metrics Explorer interface, looking for metrics starting with kubecost
.
Once you have verified that Kubecost metrics are pushed into your Datadog account, you can download our example Datadog dashboard Kubecostdashboard.json
and import it into your Datadog account to visualize the Kubecost cost allocation data. Use the following command:
In Datadog, select Dashboards in the left navigation, then select New Dashboard in the top right corner of the Dashboards page. The Create a Dashboard window opens. Create a name for your dashboard and add any relevant teams if applicable. Then, select New Dashboard.
On your dashboard, select the gear icon in the top right corner, then select Import dashboard JSON... Add the Kubecostdashboard.json file and the dashboard should automatically import. The example dashboard gives you the overview of your cluster’s monthly cost and the costs at higher levels of granularity such as containers or namespaces. See the screenshot below depicting a successful import.
For extra help, read Datadog's Copy, import, or export dashboard JSON documentation to learn how to import a dashboard JSON.