настраивал по этой доке
файл metrics.yaml
pg_database:
query: " SELECT pg_database.datname, pg_database_size(pg_database.datname) as size FROM pg_database"
metrics:
- datname:
usage: "LABEL"
description: "Name of the database"
- size:
usage: "GAUGE"
description: "Disk space used by the database"
pg_stat_statements:
query: "SELECT queryid, datname, left(query, 100) as short_query, sum(calls) as calls, sum(total_time) as total_time, min(min_time) as min_time, max(max_time) as max_time, sum(mean_time*calls)/sum(calls) as mean_time FROM pg_stat_statements JOIN pg_database ON pg_stat_statements.dbid = pg_database.oid group by queryid, short_query, datname"
metrics:
- queryid:
usage: "LABEL"
description: "Query ID"
- datname:
usage: "LABEL"
description: "Database name"
- short_query:
usage: "LABEL"
description: "Query limited to 100 symbols"
- calls:
usage: "COUNTER"
description: "Number of times executed"
- total_time:
usage: "COUNTER"
description: "Total time spent in the statement, in milliseconds"
- min_time:
usage: "GAUGE"
description: "Minimum time spent in the statement, in milliseconds"
- max_time:
usage: "GAUGE"
description: "Maximum time spent in the statement, in milliseconds"
- mean_time:
usage: "GAUGE"
description: "Mean time spent in the statement, in milliseconds"
запустил экспортер
DATA_SOURCE_NAME="postgresql://user_db:password_db@127.0.0.1:5432/db?sslmode=disable" ./postgres_exporter --extend.query-path="./metrics.yaml"
по логам все ок
INFO[0000] Established new database connection to "127.0.0.1:5432". source="postgres_exporter.go:814"
INFO[0000] Semantic Version Changed on "127.0.0.1:5432": 0.0.0 -> 9.6.15 source="postgres_exporter.go:1335"
INFO[0000] Starting Server: :9187 source="postgres_exporter.go:1576"
но если проверить метрики, то ничего нет
curl -s 127.0.0.1:9187/metrics | grep pg_stat_statements_mean_time | wc -l
0
и вообще по pg_stat_statements
curl -s 127.0.0.1:9187/metrics | grep pg_stat_statements
# HELP pg_settings_pg_stat_statements_max Sets the maximum number of statements tracked by pg_stat_statements.
# TYPE pg_settings_pg_stat_statements_max gauge
pg_settings_pg_stat_statements_max{server="127.0.0.1:5432"} 5000
# HELP pg_settings_pg_stat_statements_save Save pg_stat_statements statistics across server shutdowns.
# TYPE pg_settings_pg_stat_statements_save gauge
pg_settings_pg_stat_statements_save{server="127.0.0.1:5432"} 1
# HELP pg_settings_pg_stat_statements_track_utility Selects whether utility commands are tracked by pg_stat_statements.
# TYPE pg_settings_pg_stat_statements_track_utility gauge
pg_settings_pg_stat_statements_track_utility{server="127.0.0.1:5432"} 1
ЧЯДНТ?