| 1 | <!-- |
| 2 | title: "Monitor CockroachDB metrics with Netdata" |
| 3 | sidebar_label: "Monitor CockroachDB metrics with Netdata" |
| 4 | custom_edit_url: https://github.com/netdata/netdata/edit/master/docs/guides/monitor-cockroachdb.md |
| 5 | learn_status: "Published" |
| 6 | learn_topic_type: "Tasks" |
| 7 | learn_rel_path: "Miscellaneous" |
| 8 | --> |
| 9 | |
| 10 | # Monitor CockroachDB metrics with Netdata |
| 11 | |
| 12 | [CockroachDB](https://github.com/cockroachdb/cockroach) is an open-source project that brings SQL databases into |
| 13 | scalable, disaster-resilient cloud deployments. Thanks to |
| 14 | a [new CockroachDB collector](/src/go/plugin/go.d/collector/cockroachdb/README.md) |
| 15 | released in |
| 16 | [v1.20](https://blog.netdata.cloud/posts/release-1.20/), you can now monitor any number of CockroachDB databases with |
| 17 | maximum granularity using Netdata. Collect more than 50 unique metrics and put them on interactive visualizations |
| 18 | designed for better visual anomaly detection. |
| 19 | |
| 20 | Netdata itself uses CockroachDB as part of its Netdata Cloud infrastructure, so we're happy to introduce this new |
| 21 | collector and help others get started with it straight away. |
| 22 | |
| 23 | Let's dive in and walk through the process of monitoring CockroachDB metrics with Netdata. |
| 24 | |
| 25 | ## What's in this guide |
| 26 | |
| 27 | - [Monitor CockroachDB metrics with Netdata](#monitor-cockroachdb-metrics-with-netdata) |
| 28 | - [What's in this guide](#whats-in-this-guide) |
| 29 | - [Configure the CockroachDB collector](#configure-the-cockroachdb-collector) |
| 30 | - [Manual setup for a local CockroachDB database](#manual-setup-for-a-local-cockroachdb-database) |
| 31 | - [Tweak CockroachDB alerts](#tweak-cockroachdb-alerts) |
| 32 | |
| 33 | ## Configure the CockroachDB collector |
| 34 | |
| 35 | Because _all_ of Netdata's collectors can auto-detect the services they monitor, you _shouldn't_ need to worry about |
| 36 | configuring CockroachDB. Netdata only needs to regularly query the database's `_status/vars` page to gather metrics and |
| 37 | display them on the dashboard. |
| 38 | |
| 39 | If your CockroachDB instance is accessible through `http://localhost:8080/` or `http://127.0.0.1:8080`, your setup is |
| 40 | complete. Restart Netdata with `sudo systemctl restart netdata`, or the appropriate |
| 41 | method for your system, and refresh your browser. You should see CockroachDB |
| 42 | metrics in your Netdata dashboard! |
| 43 | |
| 44 | <figure> |
| 45 | <img src="https://user-images.githubusercontent.com/1153921/73564467-d7e36b00-441c-11ea-9ec9-b5d5ea7277d4.png" alt="CPU utilization charts from a CockroachDB database monitored by Netdata" /> |
| 46 | <figcaption>CPU utilization charts from a CockroachDB database monitored by Netdata</figcaption> |
| 47 | </figure> |
| 48 | |
| 49 | > Note: Netdata collects metrics from CockroachDB every 10 seconds, instead of our usual 1 second, because CockroachDB |
| 50 | > only updates `_status/vars` every 10 seconds. You can't change this setting in CockroachDB. |
| 51 | |
| 52 | If you don't see CockroachDB charts, you may need to configure the collector manually. |
| 53 | |
| 54 | ### Manual setup for a local CockroachDB database |
| 55 | |
| 56 | To configure Netdata's CockroachDB collector, navigate to your Netdata configuration directory (typically at |
| 57 | `/etc/netdata/`) and use `edit-config` to initialize and edit your CockroachDB configuration file. |
| 58 | |
| 59 | ```bash |
| 60 | cd /etc/netdata/ # Replace with your Netdata configuration directory, if not /etc/netdata/ |
| 61 | ./edit-config go.d/cockroachdb.conf |
| 62 | ``` |
| 63 | |
| 64 | Scroll down to the `[JOBS]` section at the bottom of the file. You will see the two default jobs there, which you can |
| 65 | edit, or create a new job with any of the parameters listed above in the file. Both the `name` and `url` values are |
| 66 | required, and everything else is optional. |
| 67 | |
| 68 | For a production cluster, you'll use either an IP address or the system's hostname. Be sure that your remote system |
| 69 | allows TCP communication on port 8080, or whichever port you have configured CockroachDB's |
| 70 | [Admin UI](https://www.cockroachlabs.com/docs/stable/monitoring-and-alerting.html#prometheus-endpoint) to listen on. |
| 71 | |
| 72 | ```yaml |
| 73 | # [ JOBS ] |
| 74 | jobs: |
| 75 | - name: remote |
| 76 | url: http://203.0.113.0:8080/_status/vars |
| 77 | |
| 78 | - name: remote_hostname |
| 79 | url: http://cockroachdb.example.com:8080/_status/vars |
| 80 | ``` |
| 81 | |
| 82 | For a secure cluster, use `https` in the `url` field instead. |
| 83 | |
| 84 | ```yaml |
| 85 | # [ JOBS ] |
| 86 | jobs: |
| 87 | - name: remote |
| 88 | url: https://203.0.113.0:8080/_status/vars |
| 89 | tls_skip_verify: yes # If your certificate is self-signed |
| 90 | |
| 91 | - name: remote_hostname |
| 92 | url: https://cockroachdb.example.com:8080/_status/vars |
| 93 | tls_skip_verify: yes # If your certificate is self-signed |
| 94 | ``` |
| 95 | |
| 96 | You can add as many jobs as you'd like based on how many CockroachDB databases you have—Netdata will create separate |
| 97 | charts for each job. Once you've edited `cockroachdb.conf` according to the needs of your infrastructure, restart |
| 98 | Netdata to see your new charts. |
| 99 | |
| 100 | <figure> |
| 101 | <img src="https://user-images.githubusercontent.com/1153921/73564469-d7e36b00-441c-11ea-8333-02ba0e1c294c.png" alt="Charts showing a node failure during a simulated test" /> |
| 102 | <figcaption>Charts showing a node failure during a simulated test</figcaption> |
| 103 | </figure> |
| 104 | |
| 105 | ## Tweak CockroachDB alerts |
| 106 | |
| 107 | This release also includes eight pre-configured alerts for live nodes, such as whether the node is live, storage |
| 108 | capacity, issues with replication, and the number of SQL connections/statements. See [health.d/cockroachdb.conf on |
| 109 | GitHub](https://raw.githubusercontent.com/netdata/netdata/master/src/health/health.d/cockroachdb.conf) for details. |
| 110 | |
| 111 | You can also edit these files directly with `edit-config`: |
| 112 | |
| 113 | ```bash |
| 114 | cd /etc/netdata/ # Replace with your Netdata configuration directory, if not /etc/netdata/ |
| 115 | ./edit-config health.d/cockroachdb.conf # You may need to use `sudo` for write privileges |
| 116 | ``` |
| 117 | |
| 118 | For more information about editing the defaults or writing new alert entities, see our documentation on [configuring health alerts](/src/health/REFERENCE.md). |