PostgreSQL metrics

Collect metrics from the PostgreSQL database

status: beta role: daemon role: sidecar delivery: at-least-once egress: batch state: stateless output: metrics
PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance.

Configuration

Example configurations

{
  "sources": {
    "my_source_id": {
      "type": "postgresql_metrics",
      "endpoints": [
        "postgresql://postgres:vector@localhost:5432/postgres"
      ],
      "scrape_interval_secs": 15
    }
  }
}
[sources.my_source_id]
type = "postgresql_metrics"
endpoints = [ "postgresql://postgres:vector@localhost:5432/postgres" ]
scrape_interval_secs = 15
---
sources:
  my_source_id:
    type: postgresql_metrics
    endpoints:
      - postgresql://postgres:vector@localhost:5432/postgres
    scrape_interval_secs: 15
{
  "sources": {
    "my_source_id": {
      "type": "postgresql_metrics",
      "endpoints": [
        "postgresql://postgres:vector@localhost:5432/postgres"
      ],
      "scrape_interval_secs": 15,
      "namespace": "postgresql",
      "include_databases": [
        "^postgres$"
      ],
      "exclude_databases": [
        "^postgres$"
      ]
    }
  }
}
[sources.my_source_id]
type = "postgresql_metrics"
endpoints = [ "postgresql://postgres:vector@localhost:5432/postgres" ]
scrape_interval_secs = 15
namespace = "postgresql"
include_databases = [ "^postgres$" ]
exclude_databases = [ "^postgres$" ]
---
sources:
  my_source_id:
    type: postgresql_metrics
    endpoints:
      - postgresql://postgres:vector@localhost:5432/postgres
    scrape_interval_secs: 15
    namespace: postgresql
    include_databases:
      - ^postgres$
    exclude_databases:
      - ^postgres$
    tls: null

endpoints

required [string]
PostgreSQL server endpoint in libpq-style connection strings.
Array string literal
Examples
[
 "postgresql://postgres:vector@localhost:5432/postgres"
]

exclude_databases

optional [string]
A list of databases to match (by using POSIX Regular Expressions) against the datname column for which you don’t want to collect metrics from. Specifying "" will include metrics where datname is NULL. This can be used in conjunction with include_databases.
Array string literal
Examples
[
 "^postgres$",
 "^template.*",
 ""
]

include_databases

optional [string]
A list of databases to match (by using POSIX Regular Expressions) against the datname column for which you want to collect metrics from. If not set, metrics are collected from all databases. Specifying "" will include metrics where datname is NULL. This can be used in conjunction with exclude_databases.
Array string literal
Examples
[
 "^postgres$",
 "^vector$",
 "^foo"
]

namespace

optional string literal
The namespace of metrics. Disabled if empty.
default: postgresql

scrape_interval_secs

common optional uint
The interval between scrapes.
default: 15 (seconds)

tls

optional object
TLS options to connect to the PostgreSQL Server.

tls.ca_file

required string literal
Path to CA certificate file.

Output

Metrics

pg_stat_bgwriter_buffers_alloc_total

counter
Number of buffers allocated.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_buffers_backend_fsync_total

counter
Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write).
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_buffers_backend_total

counter
Number of buffers written directly by a backend.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_buffers_checkpoint_total

counter
Number of buffers written during checkpoints.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_buffers_clean_total

counter
Number of buffers written by the background writer.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_checkpoint_sync_time_seconds_total

counter
Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_checkpoint_write_time_seconds_total

counter
Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_checkpoints_req_total

counter
Number of requested checkpoints that have been performed.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_checkpoints_timed_total

counter
Number of scheduled checkpoints that have been performed.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_maxwritten_clean_total

counter
Number of times the background writer stopped a cleaning scan because it had written too many buffers.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_bgwriter_stats_reset

gauge
Time at which these statistics were last reset.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

pg_stat_database_blk_read_time_seconds_total

counter
Time spent reading data file blocks by backends in this database, in milliseconds (if track_io_timing is enabled, otherwise zero).
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_blk_write_time_seconds_total

counter
Time spent writing data file blocks by backends in this database, in milliseconds (if track_io_timing is enabled, otherwise zero).
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_blks_hit_total

counter
Number of times disk blocks were found already in the buffer cache, so that a read was not necessary (this only includes hits in the PostgreSQL buffer cache, not the operating system’s file system cache).
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_blks_read_total

counter
Number of disk blocks read in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_checksum_failures_total

counter
Number of data page checksum failures detected in this database (or on a shared object), or 0 if data checksums are not enabled.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_checksum_last_failure

gauge
Time at which the last data page checksum failure was detected in this database (or on a shared object), or 0 if data checksums are not enabled.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_conflicts_confl_bufferpin_total

counter
Number of queries in this database that have been canceled due to pinned buffers.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_conflicts_confl_deadlock_total

counter
Number of queries in this database that have been canceled due to deadlocks.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_conflicts_confl_lock_total

counter
Number of queries in this database that have been canceled due to lock timeouts.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_conflicts_confl_snapshot_total

counter
Number of queries in this database that have been canceled due to old snapshots.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_conflicts_confl_tablespace_total

counter
Number of queries in this database that have been canceled due to dropped tablespaces.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_conflicts_total

counter
Number of queries canceled due to conflicts with recovery in this database. (Conflicts occur only on standby servers; see pg_stat_database_conflicts for details.)
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_datid

gauge
OID of this database, or 0 for objects belonging to a shared relation.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_deadlocks_total

counter
Number of deadlocks detected in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_numbackends

gauge
Number of backends currently connected to this database, or 0 for shared objects. This is the only column in this view that returns a value reflecting current state; all other columns return the accumulated values since the last reset.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_stats_reset

gauge
Time at which these statistics were last reset.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_temp_bytes_total

counter
Total amount of data written to temporary files by queries in this database. All temporary files are counted, regardless of why the temporary file was created, and regardless of the log_temp_files setting.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_temp_files_total

counter
Number of temporary files created by queries in this database. All temporary files are counted, regardless of why the temporary file was created (e.g., sorting or hashing), and regardless of the log_temp_files setting.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_tup_deleted_total

counter
Number of rows deleted by queries in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_tup_fetched_total

counter
Number of rows fetched by queries in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_tup_inserted_total

counter
Number of rows inserted by queries in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_tup_returned_total

counter
Number of rows returned by queries in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_tup_updated_total

counter
Number of rows updated by queries in this database.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_xact_commit_total

counter
Number of transactions in this database that have been committed.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

pg_stat_database_xact_rollback_total

counter
Number of transactions in this database that have been rolled back.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.
type required
Database name.

up

gauge
Whether the PostgreSQL server is up or not.
endpoint required
PostgreSQL endpoint.
host required
The hostname of the PostgreSQL server.

Telemetry

Metrics

link

collect_completed_total

counter
The total number of metrics collections completed for this component.
host required
The hostname of the system Vector is running on.
pid required
The process ID of the Vector instance.

collect_duration_seconds

histogram
The duration spent collecting of metrics for this component.
host required
The hostname of the system Vector is running on.
pid required
The process ID of the Vector instance.

component_received_events_total

counter
The number of events accepted by this component either from tagged origins like file and uri, or cumulatively from other origins.
component_id required
The Vector component ID.
component_kind required
The Vector component kind.
component_name required
Deprecated, use component_id instead. The value is the same as component_id.
component_scope required
The Vector component scope.
component_type required
The Vector component type.
container_name optional
The name of the container from which the event originates.
file optional
The file from which the event originates.
host required
The hostname of the system Vector is running on.
mode optional
The connection mode used by the component.
peer_addr optional
The IP from which the event originates.
peer_path optional
The pathname from which the event originates.
pid required
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the event originates.
uri optional
The sanitized URI from which the event originates.

component_sent_event_bytes_total

counter
The total number of event bytes emitted by this component.
component_id required
The Vector component ID.
component_kind required
The Vector component kind.
component_name required
Deprecated, use component_id instead. The value is the same as component_id.
component_scope required
The Vector component scope.
component_type required
The Vector component type.
host required
The hostname of the system Vector is running on.
pid required
The process ID of the Vector instance.

component_sent_events_total

counter
The total number of events emitted by this component.
component_id required
The Vector component ID.
component_kind required
The Vector component kind.
component_name required
Deprecated, use component_id instead. The value is the same as component_id.
component_scope required
The Vector component scope.
component_type required
The Vector component type.
host required
The hostname of the system Vector is running on.
pid required
The process ID of the Vector instance.

events_in_total

counter
The number of events accepted by this component either from tagged origins like file and uri, or cumulatively from other origins. This metric is deprecated and will be removed in a future version. Use component_received_events_total instead.
component_id required
The Vector component ID.
component_kind required
The Vector component kind.
component_name required
Deprecated, use component_id instead. The value is the same as component_id.
component_scope required
The Vector component scope.
component_type required
The Vector component type.
container_name optional
The name of the container from which the event originates.
file optional
The file from which the event originates.
host required
The hostname of the system Vector is running on.
mode optional
The connection mode used by the component.
peer_addr optional
The IP from which the event originates.
peer_path optional
The pathname from which the event originates.
pid required
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the event originates.
uri optional
The sanitized URI from which the event originates.

events_out_total

counter
The total number of events emitted by this component. This metric is deprecated and will be removed in a future version. Use component_sent_events_total instead.
component_id required
The Vector component ID.
component_kind required
The Vector component kind.
component_name required
Deprecated, use component_id instead. The value is the same as component_id.
component_scope required
The Vector component scope.
component_type required
The Vector component type.
host required
The hostname of the system Vector is running on.
pid required
The process ID of the Vector instance.

request_errors_total

counter
The total number of requests errors for this component.
host required
The hostname of the system Vector is running on.
pid required
The process ID of the Vector instance.

How it works

Context

By default, the postgresql_metrics source augments events with helpful context keys.

Required Privileges

PostgreSQL Metrics component collects metrics by making queries to the configured PostgreSQL server. Ensure the configured user is allowed to make the select queries against the following views:

  • pg_stat_database
  • pg_stat_database_conflicts
  • pg_stat_bgwriter

State

This component is stateless, meaning its behavior is consistent across each input.