Whether the Postgres server is reachable or not.
The agent checks that a connection to the server is still alive on each scrape.
How long it took to execute an empty SQL query (";") on the server.
This metric shows the round-trip time between the agent and the server.
The time spent executing db.Ping().
The server info.
pg_settings.server_version
server_version
Value of the pg_setting variable.
The agent only collects variables of the following types: integer, real, and bool.
name, unit
The number of the database connections.
pg_stat_activity
db
user
state - current state of the connection, < active | idle | idle in transaction >
wait_event_type - the
type
of event that the connection is waiting for.
query - If the state of a connection is active, this is the currently executing query.
For idle in transaction connections, this is the last executed query. This label holds a normalized and obfuscated query.
Query execution time.
pg_stat_activity,
pg_stat_statements.
summary - < avg | max | p50 | p75 | p95 | p99 >
Number of queries executed in the database.
Aggregation of pg_stat_activity.state = 'Active' and pg_stat_statements.calls.
db - name of the database
Number of queries awaiting a lock.
Number of connections with pg_stat_activity.wait_event_type = 'Lock'.
The blocking_query label is calculated using the pg_blocking_pids function.
db
user
blocking_query - the query holding the lock
Query metrics
The pg_stat_statements view shows statistics only for queries that have been completed.
So, to provide comprehensive statistics, the agent extends this with data about the currently active queries from
the pg_stat_activity view.
Collecting stats about each query would produce metrics with very high cardinality.
However, the primary purpose of such metrics is to show the most resource-consuming queries.
So, the agent collects these metrics only for TOP-20 queries by total execution time.
Each metric described below has query, db and user labels.
Query is a normalized and obfuscated query from pg_stat_statements.query, and pg_stat_activity.query.
For example, the following queries:
SELECT * FROM tbl WHERE id='1';
SELECT * FROM tbl WHERE id='2';
will be grouped to
SELECT * FROM tbl WHERE id=?;
Number of times the query has been executed.
pg_stat_statements.calls and pg_stat_activity.state = 'Active'
db, user, query
Time spent executing the query.
clock_timestamp()-pg_stat_activity.query_start and pg_stat_statements.total_time
db, user, query
Time the query spent awaiting I/O.
pg_stat_activity.wait_event_type = 'IO', pg_stat_statements.blk_read_time and pg_stat_statements.blk_write_time
db, user, query
Replication metrics
WAL receiver status: 1 if the receiver is connected, otherwise 0.
pg_stat_wal_receiver and pg_settings[primary_conninfo]
sender_host, sender_port
Whether WAL replay paused or not.
pg_is_wal_replay_paused() or pg_is_xlog_replay_paused()
Current WAL sequence number.
pg_current_wal_lsn() or pg_current_xlog_location()
WAL sequence number that has been received and synced to disk by streaming replication.
pg_last_wal_receive_lsn() or pg_last_xlog_receive_location()
WAL sequence number that has been replayed during recovery.
pg_last_wal_replay_lsn() or pg_last_xlog_replay_location()