Percona Monitoring and Management (PMM) boasts many functionalities that support its extension, be it by using Custom Queries, Custom Scripts, or by collecting data from already available External Exporters.

In this short blog post, we will see how to quickly (and easily) monitor a PostgreSQL cluster managed by Patroni. I will assume you already have an environment set up and running in which the PMM client is already monitoring the PostgreSQL database. I will assume a three-node PostgreSQL cluster, but it will, of course, work with other setups. If needed, refer to the online documentation on this:

https://docs.percona.com/percona-monitoring-and-management/setting-up/client/postgresql.html

Adding the Patroni metrics to PMM

Since version 2.1.0, Patroni exposes metrics in a Prometheus-compatible way via the /metrics endpoint:

https://patroni.readthedocs.io/en/latest/releases.html#version-2-1-0 

This means that we can instantly benefit from them by using the PMM External Exporters feature:

https://docs.percona.com/percona-monitoring-and-management/setting-up/client/external.html

In a nutshell, we just need to run the following in each client node:

Where –service-name can be whatever naming scheme you want that lets you easily know which Patroni node it refers to.

After running these commands and waiting some seconds, we should see metrics incoming in the Advanced Data Exploration dashboard, like the patroni_primary one:

Patroni Advanced Data Exploration dashboard

Up to now, no Patroni dashboard would use these metrics. So I took the chance while working on a customer ticket to improve this and created my own dashboard (which is proof of the power behind PMM’s extensibility, in my opinion).

Importing the new Patroni Dashboard

I have uploaded the dashboard to Grafana Labs so it’s easy for everyone to import and use. You can use the ID 18870 to do so in three easy steps.

1- Click on the Import dashboard button in PMM:

2- Select the ID:

3- Select the PostgreSQL folder, and Metrics, and import it:

After this, you should be able to see all the information available from the Patroni /metrics endpoint in your PMM! (Actually, all but patroni_xlog_replayed_timestamp, patroni_cluster_unlocked, and patroni_failsafe_mode_is_active). The dashboard is split into three main sections:

In the headers, we can see information about a node in particular (the one selected in the service_name drop-down list):

  • Patroni information like version, communication with the DCS, if it’s the current leader, etc.
  • PostgreSQL information like version, if it’s running, its timeline number, etc.

Then we have the Patroni section, with graphs showing which were the Patroni primary and replica nodes at any time.

Finally, we have a PostgreSQL section, with graphs showing which were the PostgreSQL primary and replica nodes at any time and information on WAL generation and application.

The following two screenshots show this more clearly:

Conclusion

Adding new information to PMM is easy, and in this case, it’s even easier because all the moving parts are already developed, and it’s a matter of simply knowing how to connect them.

Percona Monitoring and Management is a best-of-breed open source database monitoring solution. It helps you reduce complexity, optimize performance, and improve the security of your business-critical database environments, no matter where they are located or deployed.

 

Download Percona Monitoring and Management Today

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Aaron Malate

Hi I have imported the dashboard, I am having a challenge when I want to add datasource(s) into the patroni dashboard