If you’re looking for your PlanetScale database metrics in your New Relic account, this tutorial will show how to configure a Prometheus instance to scrape PlanetScale’s Prometheus infrastructure automatically, allowing you to collect detailed metrics for all of your PlanetScale branches.
In this tutorial, we will be using an instance of Prometheus running on a Linux VM to scrape metrics from PlanetScale and then forward them to New Relic using Remote Write. We will make sure that Prometheus stays running by creating a Systemd Unit File.The default configuration we will create will send all PlanetScale metrics to New Relic, and we will cover how to filter to drop certain metrics that may not be desired.In order to proceed, you’ll need:
First, let’s download the latest release of Prometheus and create our user that is going to run it. We’ll be using the latest 3.x release from the GitHub Releases Page.Create a prometheus user:
Now that we have the binary in place, let’s setup Systemd to run Prometheus by creating a Unit File in /etc/systemd/system/prometheus.service with the following contents:
Now that we’ve got Prometheus installed and a unit file present, let’s configure Prometheus. We will be borrowing some of our configuration from the Prometheus Guide, and adding some New Relic specific configuration. Edit /opt/prometheus/prometheus.yml in your editor of choice so that it contains this, making sure to replace your org name, service token information, and New Relic API key:
After a couple of minutes, head over to your New Relic dashboard and we can query for your database metrics. First, let’s get a list of the database branches in the nick organization that I’m using to test:
$ pscale branch list test --org nick ID NAME PARENT BRANCH REGION PRODUCTION SAFE MIGRATIONS READY CREATED AT UPDATED AT -------------- ------------ --------------- --------- ------------ ----------------- ------- -------------- ---------------- 7wxuxewx4l0p main n/a us-east Yes No Yes 2 years ago 50 minutes ago 6o0rr27785fl partitions main us-east No No Yes 2 months ago 7 minutes ago
For this, we’ll use the 7wxuxewx4l0p branch.Using New Relic’s NRQL, we can visualize the memory usage of my VTTablet instances with the following query:
FROM Metric SELECT average(planetscale_pods_cpu_util_percentages) WHERE planetscale_database_branch_id = '7wxuxewx4l0p' AND planetscale_component='vttablet' SINCE 30 minutes AGO TIMESERIES FACET planetscale_pod
Because my main branch is production, we will see the memory usage for my primary and both my replicas over the last 30 minutes:
If you don’t want to ingest every metric into New Relic, you can tell Prometheus to drop certain metrics. For more information, see the New Relic Documentation.If we adjust our Prometheus configuration that we have in /opt/prometheus/prometheus.yml we can instruct Prometheus to drop all metrics unless they match a certain naming convention:
If you replace your remote_write block with what’s above, Prometheus will only forward the timeseries that match the planetscale_pods_* name. For a full list of metrics, see our Metric List.