PostgreSQL metrics

Collect metrics from the PostgreSQL database

status: stable role: daemon role: sidecar delivery: at-least-once acknowledgements: no 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"
      ]
    }
  }
}
[sources.my_source_id]
type = "postgresql_metrics"
endpoints = [ "postgresql://postgres:vector@localhost:5432/postgres" ]
sources:
  my_source_id:
    type: postgresql_metrics
    endpoints:
      - postgresql://postgres:vector@localhost:5432/postgres
{
  "sources": {
    "my_source_id": {
      "type": "postgresql_metrics",
      "endpoints": [
        "postgresql://postgres:vector@localhost:5432/postgres"
      ],
      "exclude_databases": [
        "^postgres$"
      ],
      "include_databases": [
        "^postgres$"
      ],
      "namespace": "postgresql",
      "scrape_interval_secs": 15
    }
  }
}
[sources.my_source_id]
type = "postgresql_metrics"
endpoints = [ "postgresql://postgres:vector@localhost:5432/postgres" ]
exclude_databases = [ "^postgres$" ]
include_databases = [ "^postgres$" ]
namespace = "postgresql"
scrape_interval_secs = 15
sources:
  my_source_id:
    type: postgresql_metrics
    endpoints:
      - postgresql://postgres:vector@localhost:5432/postgres
    exclude_databases:
      - ^postgres$
    include_databases:
      - ^postgres$
    namespace: postgresql
    scrape_interval_secs: 15

endpoints

required [string]

A list of PostgreSQL instances to scrape.

Each endpoint must be in the Connection URI format.

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 "" includes 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 "" includes 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
Overrides the default namespace for the metrics emitted by the source.
default: postgresql

scrape_interval_secs

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

tls

optional object
Configuration of TLS when connecting to PostgreSQL.

tls.ca_file

required string literal

Absolute path to an additional CA certificate file.

The certificate must be in the DER or PEM (X.509) format.

Examples
"certs/ca.pem"

Outputs

<component_id>

Default output stream of the component. Use this component’s ID as an input to downstream transforms and sinks.

Output Data

Metrics

pg_stat_bgwriter_buffers_alloc_total

counter
Number of buffers allocated.
endpoint
PostgreSQL endpoint.
host
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.

pg_stat_bgwriter_buffers_backend_total

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

pg_stat_bgwriter_buffers_checkpoint_total

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

pg_stat_bgwriter_buffers_clean_total

counter
Number of buffers written by the background writer.
endpoint
PostgreSQL endpoint.
host
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
PostgreSQL endpoint.
host
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.

pg_stat_bgwriter_checkpoints_req_total

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

pg_stat_bgwriter_checkpoints_timed_total

counter
Number of scheduled checkpoints that have been performed.
endpoint
PostgreSQL endpoint.
host
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.

pg_stat_bgwriter_stats_reset

gauge
Time at which these statistics were last reset.
endpoint
PostgreSQL endpoint.
host
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
Database name.

pg_stat_database_blks_read_total

counter
Number of disk blocks read in this database.
endpoint
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
Database name.

pg_stat_database_conflicts_confl_deadlock_total

counter
Number of queries in this database that have been canceled due to deadlocks.
endpoint
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
Database name.

pg_stat_database_datid

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

pg_stat_database_deadlocks_total

counter
Number of deadlocks detected in this database.
endpoint
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
Database name.

pg_stat_database_stats_reset

gauge
Time at which these statistics were last reset.
endpoint
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
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
PostgreSQL endpoint.
host
The hostname of the PostgreSQL server.
type
Database name.

pg_stat_database_tup_deleted_total

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

pg_stat_database_tup_fetched_total

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

pg_stat_database_tup_inserted_total

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

pg_stat_database_tup_returned_total

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

pg_stat_database_tup_updated_total

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

pg_stat_database_xact_commit_total

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

pg_stat_database_xact_rollback_total

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

up

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

Telemetry

Metrics

link

collect_completed_total

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

collect_duration_seconds

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

component_discarded_events_total

counter
The number of events dropped by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
intentional
True if the events were discarded intentionally, like a filter transform, or false if due to an error.
pid optional
The process ID of the Vector instance.

component_errors_total

counter
The total number of errors encountered by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
error_type
The type of the error
host optional
The hostname of the system Vector is running on.
pid optional
The process ID of the Vector instance.
stage
The stage within the component at which the error occurred.

component_received_bytes_total

counter
The number of raw bytes accepted by this component from source origins.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
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 data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

component_received_event_bytes_total

counter
The number of event bytes accepted by this component either from tagged origins like file and uri, or cumulatively from other origins.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
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 data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

component_received_events_count

histogram

A histogram of the number of events passed in each internal batch in Vector’s internal topology.

Note that this is separate than sink-level batching. It is mostly useful for low level debugging performance issues in Vector due to small internal batches.

component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
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 data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

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
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
container_name optional
The name of the container from which the data originated.
file optional
The file from which the data originated.
host optional
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 data originated.
peer_path optional
The pathname from which the data originated.
pid optional
The process ID of the Vector instance.
pod_name optional
The name of the pod from which the data originated.
uri optional
The sanitized URI from which the data originated.

component_sent_event_bytes_total

counter
The total number of event bytes emitted by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
output optional
The specific output of the component.
pid optional
The process ID of the Vector instance.

component_sent_events_total

counter
The total number of events emitted by this component.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
output optional
The specific output of the component.
pid optional
The process ID of the Vector instance.

source_lag_time_seconds

histogram
The difference between the timestamp recorded in each event and the time when it was ingested, expressed as fractional seconds.
component_id
The Vector component ID.
component_kind
The Vector component kind.
component_type
The Vector component type.
host optional
The hostname of the system Vector is running on.
pid optional
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.