prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.81k stars 742 forks source link

Cannot Enable auto-discover-databases with restriction to specific database #750

Open MichaelDBA opened 1 year ago

MichaelDBA commented 1 year ago

I expected to only pull statistics for the "mydb" database.

Here is my service execute command: ExecStart=/usr/local/bin/postgres_exporter --web.listen-address=localhost:9100 --web.telemetry-path=/metrics --disable-settings-metrics --auto-discover-databases --include-databases="mydb"

Here is my environment file referenced by the service:

DATA_SOURCE_NAME="postgresql://pgexporter:mypass@myhost:5432/mydb?sslmode=disable"
PG_EXPORTER_AUTO_DISCOVER_DATABASES
PG_EXPORTER_DISABLE_SETTINGS_METRICS
PG_EXPORTER_INCLUDE_DATABASES=mydb

When I test with the prometheus graphic interface, I expect to see only one line for mydb for this command: pg_stat_database_blks_read

Instead I get results for all databases:

pg_stat_database_blks_read{datid="0", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  14107
pg_stat_database_blks_read{datid="1", datname="template1", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  2076
pg_stat_database_blks_read{datid="14716", datname="template0", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  0
pg_stat_database_blks_read{datid="14717", datname="postgres", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  8490
pg_stat_database_blks_read{datid="16384", datname="rdsadmin", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  25678
pg_stat_database_blks_read{datid="24587", datname="mydb", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  7764984792
pg_stat_database_blks_read{datid="406941616", datname="pgbench", instance="localhost:9100", job="postgre_exporter", server="rdswhatever.rds.amazonaws.com:5432"}  360

Question: Am I using the right format for booleans in the execute command in service file? --auto-discover-databases --auto-discover-databases=true --> gives execute error, unknown value, true --auto-discover-databases="true" --> gives execute error, unknown value, true

Question: How about format for variables in the environment file as shown above?

Environment info: postgresql v14.6

postgres_exporter, version 0.11.1 (branch: HEAD, revision: b5fd2465646a09bb1c8dbd5c9c00b852da93927a) build user: root@a2c981f603ff build date: 20220818-20:58:17 go version: go1.18.5 platform: linux/amd64

Linux 5.10.149-133.644.amzn2.x86_64 x86_64

combrs commented 1 year ago

See similar issue https://github.com/prometheus-community/postgres_exporter/issues/735#issuecomment-1409969395