prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.72k stars 725 forks source link

One exporter to manage different database server versions #354

Open neel5481 opened 4 years ago

neel5481 commented 4 years ago

Hi,

We are running postgres exporter on one machine where POstgreSQL 9.6 and PostgreSQL 10 database servers are running.

All instances are running on same one machine as below.

PostgreSQL 10 running on port 5432 PostgreSQL 9.6 running on port 5433 Postgres Exporter on port 9187

DATA_SOURCE_NAME="postgresql://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable,postgresql://postgres:postgres@127.0.0.1:5433/postgres?sslmode=disable"

./postgres_exporter --extend.query-path="./queries.yml"

Queries that is written inside "queries.yml" file will be same for both the version of PG instances. But is there anyway to provide the PG version in "queries.yml" ? As it might possible that some of the columns are not present in PG 9.6 and newly added to PG 10. What is the alternate, if not possible ? Can I provide two different "queries.yml" file for different version of PG instances to postgres exporter ? Do I need to run two different postgres exporter for these two PostgreSQL instances ?

isaiasanchez commented 4 years ago

You can create those queries to run alternatively in one or another version using postgresql metadata information. For example: SELECT CASE WHEN split_part(trim(version()),' ',2) LIKE '9.5%' THEN column_9_5 WHEN split_part(trim(version()),' ',2) LIKE '9.6%' THEN column_9_6 ELSE colum_10 END as column_db ....