> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitor CockroachDB Self-Hosted Clusters with Datadog

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

[Datadog](https://www.datadoghq.com/) is a monitoring and security platform for cloud applications. The integration of your CockroachDB self-hosted cluster with Datadog enables data collection and alerting on selected [CockroachDB metrics](https://docs.datadoghq.com/integrations/cockroachdb/?tab=host#data-collected) using the Datadog platform.

<Tip>
  This tutorial explores the CockroachDB self-hosted integration with Datadog. For the CockroachDB Cloud integration with Datadog, refer to <InternalLink version="cockroachcloud" path="tools-page#monitor-cockroachdb-cloud-with-datadog">Monitor CockroachDB Dedicated with Datadog</InternalLink> instead of this page.
</Tip>

The integration of your CockroachDB self-hosted cluster with Datadog is powered by the [Datadog Agent](https://app.datadoghq.com/account/settings#agent), and supported by Datadog directly:

* For more information about the integration, see the [Datadog blog post](https://www.datadoghq.com/blog/monitor-cockroachdb-performance-metrics-with-datadog/).
* For more information about using Datadog, see the [Datadog documentation](https://docs.datadoghq.com/).
* If you run into problems with this integration, please file an issue on the [Datadog Agent issue tracker](https://github.com/DataDog/datadog-agent).

In this tutorial, you will enable the CockroachDB integration in Datadog, configure logging and alerting, and visualize data.

## Before you begin

Before you can follow the steps presented in this tutorial, you must have:

* Downloaded and installed the [Datadog Agent](https://app.datadoghq.com/account/settings#agent).
* Started a <InternalLink path="secure-a-cluster">secure CockroachDB self-hosted cluster</InternalLink>.

## Step 1. Enable CockroachDB integration

To enable the CockroachDB check for your installed Datadog Agent, navigate to the [Integrations page](https://app.datadoghq.com/account/settings#integrations) and find CockroachDB in the list of available integrations. Hover over the icon and click **+ Install**.

<img src="https://mintcdn.com/cockroachlabs/TsHNTSgZo7_3Ti32/images/v25.3/datadog-crdb-integration.png?fit=max&auto=format&n=TsHNTSgZo7_3Ti32&q=85&s=86f6ce025ce5f459569aeb67c06184e4" alt="CockroachDB integration for Datadog installation" width="2641" height="1300" data-path="images/v25.3/datadog-crdb-integration.png" />

Note that you must restart the Datadog Agent for the change to take effect. CockroachDB will then be listed as an installed integration.

## Step 2. Configure Datadog Agent for CockroachDB

Follow the steps in the [Datadog documentation](https://docs.datadoghq.com/integrations/cockroachdb/?tab=host#configuration) to access and edit your `cockroachdb.d/conf.yaml` file in your Datadog `conf.d/` directory. For all available options, see the sample [`cockroachdb.d/conf.yaml`](https://github.com/DataDog/integrations-core/blob/master/cockroachdb/datadog_checks/cockroachdb/data/conf.yaml.example).

After making the following changes, restart the Datadog Agent to apply them.

### Enable metrics collection

Uncomment the following line in `cockroachdb.d/conf.yaml`:

```yaml theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
- prometheus_url: http://localhost:8080/_status/vars
```

This enables metrics collection via our <InternalLink path="prometheus-endpoint">Prometheus endpoint</InternalLink>.

### Configure security certificates

Uncomment the lines that begin with `tls_private_key` and `tls_ca_cert`. These should specify the full file paths to your CA key and certificate, respectively.

For example, if you used <InternalLink path="cockroach-cert">`cockroach cert`</InternalLink> to <InternalLink path="secure-a-cluster#step-1-generate-certificates">secure your cluster</InternalLink>, the paths would look something like:

```yaml theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
tls_private_key: /custom/dir/path/client.root.key
```

```yaml theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
tls_ca_cert: /custom/dir/path/ca.crt
```

### Enable log collection

Optionally enable Datadog to collect <InternalLink path="logging-overview">CockroachDB logs</InternalLink> by adding the following block to `cockroachdb.d/conf.yaml`:

```yaml theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
logs:
 - type: file
   path: /cockroach-data/logs/cockroach.log
   source: cockroachdb
   service: cockroachdb
   log_processing_rules:
   - type: multi_line
     name: new_log_start_with_status_and_date
     pattern: '[A-Z]\d{6}\s\d+\:\d+\:\d+\.\d+'
```

The `path` value specifies the <InternalLink path="configure-logs#default-logging-configuration">default</InternalLink> CockroachDB log file and location.

<Note>
  You can configure both the CockroachDB <InternalLink path="configure-logs#set-file-defaults">logging directory</InternalLink> and <InternalLink path="configure-logs#output-to-files">log files</InternalLink>.
</Note>

Log collection is disabled by default in the Datadog Agent. Follow the steps in the [Datadog documentation](https://docs.datadoghq.com/agent/logs/?tab=tailfiles#activate-log-collection) to activate log collection.

## Step 3. Verify Datadog connection to CockroachDB

To apply your configuration changes, ensure that you have restarted the Datadog Agent.

Run the Datadog Agent [`status` subcommand](https://docs.datadoghq.com/agent/guide/agent-commands/?tab=agentv6v7#agent-information) for your platform to verify that the CockroachDB integration is properly connected.

Your output should contain a block like this:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroachdb (1.6.0)
-------------------
  Instance ID: cockroachdb:42170ecfbfb171c5 [OK]
  Configuration Source: file:/opt/datadog-agent/etc/conf.d/cockroachdb.d/conf.yaml
  Total Runs: 4
  Metric Samples: Last Run: 548, Total: 2,154
  Events: Last Run: 0, Total: 0
  Service Checks: Last Run: 1, Total: 4
  Average Execution Time : 143ms
  Last Execution Date : 2021-07-14 12:34:56 EDT / 2021-07-14 16:34:56 UTC (1626280496000)
  Last Successful Execution Date : 2021-07-14 12:34:56 EDT / 2021-07-14 16:34:56 UTC (1626280496000)
  metadata:
    version.major: 21
    version.minor: 2
    version.patch: 0
    version.raw: v25.3.0-alpha.00000000-1724-gc5c74249f7
    version.release: alpha.0
    version.scheme: semver
```

## Step 4. View CockroachDB dashboards on Datadog

Open your Datadog [Dashboard List](https://app.datadoghq.com/dashboard/lists) and click on `CockroachDB Overview`:

<img src="https://mintcdn.com/cockroachlabs/TsHNTSgZo7_3Ti32/images/v25.3/datadog-crdb-dashboard-list.png?fit=max&auto=format&n=TsHNTSgZo7_3Ti32&q=85&s=cfcd0695159cae61d99774da6d83c14a" alt="CockroachDB Overview dashboard in Datadog Dashboard List" width="2984" height="1006" data-path="images/v25.3/datadog-crdb-dashboard-list.png" />

This sample dashboard presents metrics on cluster availability, query performance, and resource usage:

<img src="https://mintcdn.com/cockroachlabs/TsHNTSgZo7_3Ti32/images/v25.3/datadog-crdb-overview-dashboard.png?fit=max&auto=format&n=TsHNTSgZo7_3Ti32&q=85&s=4d674026c1a047ba6959c3cbf4b244ec" alt="CockroachDB Overview dashboard for Datadog" width="3004" height="1681" data-path="images/v25.3/datadog-crdb-overview-dashboard.png" />

<Note>
  If you wish to customize your CockroachDB dashboard, it's recommended that you clone the default `CockroachDB Overview` dashboard before adding and removing widgets. If you leave the default dashboard intact, Datadog will update it when new versions of the integration's dashboard are released.
</Note>

## Step 5. Run a sample workload

To test the dashboard functionality, use <InternalLink path="cockroach-workload">`cockroach workload`</InternalLink> to run a sample workload on the cluster.

Initialize the workload for MovR, a fictional vehicle-sharing company:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach workload init movr 'postgresql://root@localhost:26257?sslcert=certs%2Fclient.root.crt&sslkey=certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=certs%2Fca.crt'
```

Run the MovR workload for 5 minutes:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach workload run movr --duration=5m 'postgresql://root@localhost:26257?sslcert=certs%2Fclient.root.crt&sslkey=certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=certs%2Fca.crt'
```

The query metrics will appear on the dashboard:

<img src="https://mintcdn.com/cockroachlabs/TsHNTSgZo7_3Ti32/images/v25.3/datadog-crdb-workload-dashboard.png?fit=max&auto=format&n=TsHNTSgZo7_3Ti32&q=85&s=4183ba1c27fa6184bcc67f29516c7f84" alt="CockroachDB Overview dashboard for Datadog with SQL metrics" width="3004" height="1684" data-path="images/v25.3/datadog-crdb-workload-dashboard.png" />

## Step 6. Add monitoring and alerting

Follow the steps in the [Datadog documentation](https://docs.datadoghq.com/monitors/monitor_types/) to create a new Monitor.

Select **Threshold Alert** as the detection method. You can use this option to configure an alert that is sent when a [supported metric](https://docs.datadoghq.com/integrations/cockroachdb/?tab=host#data-collected) reaches a given threshold. For descriptions of some useful CockroachDB alerts, see <InternalLink path="monitoring-and-alerting#events-to-alert-on">Monitoring and Alerting</InternalLink>.

The example alert below will trigger when <InternalLink path="monitoring-and-alerting#node-is-running-low-on-disk-space">a node has less than 15% of storage capacity remaining</InternalLink>:

<img src="https://mintcdn.com/cockroachlabs/TsHNTSgZo7_3Ti32/images/v25.3/datadog-crdb-threshold-alert.png?fit=max&auto=format&n=TsHNTSgZo7_3Ti32&q=85&s=1534dfb655b7b9a41ff0769638d823e5" alt="CockroachDB Threshold Alert in Datadog" width="2980" height="1794" data-path="images/v25.3/datadog-crdb-threshold-alert.png" />

* `cockroachdb.capacity.available` is divided by `cockroachdb.capacity.total` to determine the fraction of available capacity on the node's <InternalLink path="architecture/storage-layer">store</InternalLink> (the directory on each node where CockroachDB reads and writes its data).
* The alert threshold is set to `0.15`.

The timeseries graph at the top of the page indicates the configured metric and threshold:

<img src="https://mintcdn.com/cockroachlabs/TsHNTSgZo7_3Ti32/images/v25.3/datadog-crdb-storage-alert.png?fit=max&auto=format&n=TsHNTSgZo7_3Ti32&q=85&s=be00a4bf10badb54a75d3f88566e264c" alt="CockroachDB Threshold Alert in Datadog" width="2620" height="455" data-path="images/v25.3/datadog-crdb-storage-alert.png" />

## Known limitations

* The integration of your CockroachDB self-hosted cluster with Datadog only supports displaying cluster-wide averages of reported metrics. Filtering by a specific node is unsupported.

## See also

* <InternalLink path="monitoring-and-alerting">Monitoring and Alerting</InternalLink>
* <InternalLink path="ui-overview">DB Console Overview</InternalLink>
* <InternalLink path="logging-overview">Logging Overview</InternalLink>
* <InternalLink path="metrics">Metrics</InternalLink>
