LINUX.ORG.RU

postgres_exporter pg_stat_statements для prometheus

 ,


0

1

настраивал по этой доке

файл 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
что-то вообще ничего нет

ЧЯДНТ?


Ответ на: комментарий от deadNightTiger

запустил с debug

DATA_SOURCE_NAME="postgresql://user_db:password_db@127.0.0.1:5432/db?sslmode=disable" ./postgres_exporter --extend.query-path="./metrics.yaml" --log.level="debug"
INFO[0000] Established new database connection to "127.0.0.1:5432".  source="postgres_exporter.go:814"
DEBU[0000] Querying Postgres Version on "127.0.0.1:5432"  source="postgres_exporter.go:1318"
INFO[0000] Semantic Version Changed on "127.0.0.1:5432": 0.0.0 -> 9.6.15  source="postgres_exporter.go:1335"
DEBU[0000] replay_lsn is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] pg_wal_lsn_diff is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] procpid is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] sent_lsn is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] write_lag is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] flush_lag is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] pg_current_wal_lsn is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] flush_lsn is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] write_lsn is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] pg_current_wal_lsn_bytes is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] replay_lag is being forced to discard due to version incompatibility.  source="postgres_exporter.go:532"
DEBU[0000] Querying pg_setting view on "127.0.0.1:5432"  source="pg_setting.go:15"
DEBU[0000] Querying namespace:  pg_stat_database_conflicts  source="postgres_exporter.go:1259"
DEBU[0000] Querying namespace:  pg_locks                 source="postgres_exporter.go:1259"
DEBU[0000] Querying namespace:  pg_stat_replication      source="postgres_exporter.go:1259"
DEBU[0000] Querying namespace:  pg_stat_activity         source="postgres_exporter.go:1259"
DEBU[0000] Querying namespace:  pg_stat_database         source="postgres_exporter.go:1259"
INFO[0000] Starting Server: :9187                        source="postgres_exporter.go:1576"

psql --version
psql (PostgreSQL) 9.6.15
postgres_exporter --version
postgres_exporter v0.7.0 (built with go1.11)
Garcia ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.