项目作者: adjust

项目描述 :
高级语言: Go
项目地址: git://github.com/adjust/postgresql_exporter.git
创建时间: 2019-04-16T12:41:53Z
项目社区:https://github.com/adjust/postgresql_exporter

开源协议:MIT License

下载


PostgreSQL Metrics Exporter

Prometheus exporter for PostgreSQL metrics.

Features

  • Use of multiple connections while fetching metrics
  • Statement timeouts to cancel long-running queries
  • Version-specific queries in the config file
  • Connection labels
  • No hard-coded metrics

Getting and running

Get:

  1. go get -u github.com/adjust/postgresql_exporter

Run:

  1. postgresql_exporter --config {path to the config file}

Config file

  1. {connection name}:
  2. host: {host}
  3. port: {port}
  4. user: {username}
  5. dbname: {db name}
  6. sslmode: {ssl mode}
  7. workers: {number of parallel connections to use}
  8. statementTimeout: {pg statement_timeout value for each connection}
  9. isNotPg: {true if the destination side is not postgresql (e.g. pgbouncer/odyssey)}
  10. labels:
  11. {labels added to each metric in the "queryFiles"}
  12. queryFiles:
  13. {use metric queries from files}

sample:

  1. test:
  2. host: localhost
  3. port: 5432
  4. user: postgres
  5. dbname: test
  6. sslmode: disable
  7. workers: 5
  8. statementTimeout: "3s"
  9. labels:
  10. production: true
  11. queryFiles:
  12. - "basic.yaml"
  13. - "pertable.yaml"

Query file

sample:
first query will be using for postgresql >=10
the second query will be using for postgresql >=9.4 but <10

  1. pg_slots:
  2. query:
  3. 10-: >-
  4. select
  5. slot_name,
  6. slot_type,
  7. active,
  8. case when not pg_is_in_recovery() then pg_current_wal_lsn() - restart_lsn end as current_lag_bytes
  9. from pg_replication_slots s
  10. order by s.slot_name
  11. 9.4-10: >-
  12. select
  13. slot_name,
  14. slot_type,
  15. active,
  16. case when not pg_is_in_recovery() then pg_current_xlog_location() - restart_lsn end as current_lag_bytes
  17. from pg_replication_slots s
  18. order by s.slot_name
  19. metrics:
  20. - slot_name:
  21. usage: "LABEL"
  22. description: "Slot name"
  23. - slot_type:
  24. usage: "LABEL"
  25. description: "Slot type"
  26. - active:
  27. usage: "LABEL"
  28. description: "Is slot active"
  29. - current_lag_bytes:
  30. usage: "GAUGE"
  31. description: "Lag in bytes"

query will be used for all the postgresql versions:

  1. relation_total_size:
  2. query: >-
  3. select
  4. n.nspname as schemaname,
  5. c.relname,
  6. pg_total_relation_size(c.oid) as inclusive_bytes,
  7. pg_relation_size(c.oid) as exclusive_bytes
  8. from pg_class c
  9. join pg_namespace n on c.relnamespace = n.oid
  10. where relkind = 'r'
  11. and n.nspname not in ('pg_toast', 'pg_catalog', 'information_schema')
  12. metrics:
  13. - schemaname:
  14. usage: "LABEL"
  15. description: "Schema of relation"
  16. - relname:
  17. usage: "LABEL"
  18. description: "Name of relation"
  19. - inclusive_bytes:
  20. usage: "GAUGE"
  21. description: "Size of table, including indexes and toast"
  22. - exclusive_bytes:
  23. usage: "GAUGE"
  24. description: "Size of table, excluding indexes and toast"

if you need to get metric names and values from the columns,
specify them in the “nameColumn” and “valueColumn” accordingly:

  1. pg_settings:
  2. query:
  3. 8.0-9.5: >-
  4. select
  5. name,
  6. case setting when 'off' then 0 when 'on' then 1 else setting::numeric end as setting
  7. from pg_settings
  8. where vartype IN ('bool', 'integer', 'real')
  9. 9.5-: >-
  10. select
  11. name,
  12. case setting when 'off' then 0 when 'on' then 1 else setting::numeric end as setting,
  13. pending_restart
  14. from pg_settings
  15. where vartype IN ('bool', 'integer', 'real')
  16. nameColumn: "name"
  17. valueColumn: "setting"
  18. metrics:
  19. - pending_restart:
  20. usage: "LABEL"
  21. description: "if the value has been changed in the configuration file but needs a restart"
  22. - allow_system_table_mods:
  23. usage: "GAUGE"
  24. description: "Allows modifications of the structure of system tables"
  25. - archive_timeout:
  26. usage: "GAUGE"
  27. description: "Forces a switch to the next WAL file if a new file has not been started within N seconds"
  28. ...