The queries that are run by postgres_exporter by default may not be sufficient for a user to visualize a lot of important metrics. For this purpose, we could always create custom queries and ask postgres_exporter to expose the output of the custom queries. We shall discuss how this can be achieved through this recipe.
Getting ready
In order to add custom queries to postgres_exporter, we should have already set up monitoring of the PostgreSQL server using postgres_exporter. Grafana should also be up and running on the monitoring server.
How to do it...
Prepare the list of custom queries and add it to the custom_queries.yml file:
- Add your custom queries to a file as seen in the following example:
$ cat /var/lib/pgsql/go/src/github.com/wrouesnel/postgres_exporter/custom_queries.yaml
pg_database_age:
query: "SELECT datname, age(datfrozenxid) age FROM pg_database"
metrics:
- datname:
usage: "LABEL"
description: "Name of the...