Skip to content

Send Metrics to Managed Thanos

Push the metrics of a Managed PostgreSQL service into an Exoscale Managed Thanos service and query them with PromQL. Unlike exo dbaas metrics, which returns a few host-level series for fixed periods, a metrics integration also sends the PostgreSQL and PgBouncer counters.

This page covers a Thanos service of your own organization. For a Prometheus server or a Datadog account that you run elsewhere, use an external endpoint instead. See Monitor a Managed PostgreSQL service.

Prerequisites

  • The Exoscale CLI, configured with your API credentials.
  • A running Managed PostgreSQL service, on any plan.
  • A running Managed Thanos service in the same organization. It can run in another zone than the PostgreSQL service.

The IP filter of the Thanos service does not need to list the PostgreSQL service: the integration delivers metrics to a Thanos service whose filter allows only your own address.

Create the Integration

echo '{"integration-type":"metrics","source-service":"SERVICE_NAME","dest-service":"THANOS_SERVICE"}' | \
  exo api create-dbaas-integration -z ZONE

Parameters:

  • SERVICE_NAME: name of the Managed PostgreSQL service.
  • THANOS_SERVICE: name of the Managed Thanos service that stores the metrics.
  • ZONE: zone of the PostgreSQL service, also when the Thanos service runs in another zone.

The command returns the ID of the integration in reference.id. Create it without settings: how long the metrics are kept is set on the Thanos service, see Retention and downsampling.

The first series reach Thanos within a few minutes. The integration status reported by exo api get-dbaas-integration INTEGRATION_ID -z ZONE stays at starting while metrics flow, so check Thanos itself.

Query the Metrics

Read the address of the Thanos query endpoint:

exo api get-dbaas-service-thanos THANOS_SERVICE -z THANOS_ZONE -q '"connection-info"."query-frontend-uri"'

The command returns "https://avnadmin@THANOS_HOST:THANOS_PORT". Read the password of avnadmin:

exo dbaas user reveal-secrets THANOS_SERVICE avnadmin -z THANOS_ZONE

Then query the Prometheus-compatible API:

curl -s -u "avnadmin:THANOS_PASSWORD" "https://THANOS_HOST:THANOS_PORT/api/v1/query" \
  --data-urlencode 'query=postgresql_pg_stat_activity_conn_count{service="my-postgresql"}'

Parameters:

  • THANOS_ZONE: zone of the Thanos service.
  • THANOS_HOST, THANOS_PORT: host and port from the query endpoint address.
  • THANOS_PASSWORD: the password of avnadmin.

The answer carries one series per database:

{"metric":{"__name__":"postgresql_pg_stat_activity_conn_count","cloud":"exoscale-ch-gva-2","datname":"defaultdb","host":"my-postgresql-1","role":"master","service":"my-postgresql","service_type":"pg"},"value":[1794319226.062,"1"]}

Labels

Every series carries labels that identify where it comes from:

LabelContent
serviceName of the PostgreSQL service. Filter on it when several services send metrics to the same Thanos service.
hostNode, for example my-postgresql-1.
rolemaster on the primary node. Only on postgresql_* series.
datnameDatabase, on per-database series.
schema_name, table_nameSchema and table, on per-table series.
dbConnection pool, on pgbouncer_* series.
application_name, sync_stateReplication consumer, on postgresql_pg_stat_replication_* series.
cloudexoscale- followed by the zone, for example exoscale-ch-gva-2.
service_typepg.

Thanos and the platform add project, receive_cluster and tenant_id, which are the same on every series of a Thanos service.

What Is Collected

PrefixCovers
postgresql_Connections from pg_stat_activity, database size, pg_stat_database counters, per-table and per-index statistics, table cache hit ratio, replication lag and transaction ID age
pgbouncer_Query, transaction and wait counts and times per pool. They appear once a pool has served traffic.
cpu_, mem_, disk_, diskio_, net_, netstat_, processes_, swap_, system_, kernel_, procstat_Node resources
service_connections_accepted, dropped, limit_avg_per_second and limit_burst

The full list of PostgreSQL and PgBouncer metric names is in Service metrics. List every metric name a Thanos service holds with:

curl -s -u "avnadmin:THANOS_PASSWORD" "https://THANOS_HOST:THANOS_PORT/api/v1/label/__name__/values"

Two series need care when you read them:

  • Checkpoint counters keep their old names. PostgreSQL 17 moved the checkpoint counters from pg_stat_bgwriter to pg_stat_checkpointer. On PostgreSQL 18 the integration still exports them as postgresql_pg_stat_bgwriter_checkpoints_req, postgresql_pg_stat_bgwriter_checkpoints_timed and postgresql_pg_stat_bgwriter_buffers_checkpoint, with the values of pg_stat_checkpointer.
  • One replication row is the backup stream. postgresql_pg_stat_replication_* series exist even on a single-node service: the row with application_name="pghoard" is the stream that archives the write-ahead log for backups. Exclude it to watch standby nodes and read replicas.

max_connections is not exported. Compare the connection count with the value of SHOW max_connections;, or with the max-connections field of exo api get-dbaas-service-pg SERVICE_NAME -z ZONE.

Useful Queries

QuestionPromQL
Connections opensum by (service) (postgresql_pg_stat_activity_conn_count{service="my-postgresql"})
Disk used, in percentmax by (service) (disk_used_percent{service="my-postgresql", path="/var/lib/pgsql"})
Transaction ID age against autovacuum_freeze_max_agemax by (service, datname) (postgresql_transactions_txns / postgresql_transactions_freeze_limit)
Tables served least from cachemin by (service, table_name) (postgresql_pg_statio_user_tables_cache_hit_ratio{service="my-postgresql"})
Standby replication lag, in bytesmax by (service, application_name) (postgresql_pg_stat_replication_replication_flush_lag_bytes{service="my-postgresql", application_name!="pghoard"})
Commits per secondrate(postgresql_pg_stat_database_xact_commit{service="my-postgresql"}[5m])
Queries per second through a poolrate(pgbouncer_total_query_count{service="my-postgresql"}[5m])

The transaction ID ratio climbs towards 1 as the oldest unfrozen transaction ages. See Avoid transaction ID wraparound for what to do before it gets there. The replication lag query returns nothing on a service without standby nodes or read replicas.

To chart these series, add the Thanos service to Grafana as shown in Visualize a service in Managed Grafana.

Where the Metrics Are Stored

The metrics are stored in the zone of the Thanos service, which can differ from the zone of the PostgreSQL service. Keep both services in the same zone when the metrics must stay in one country.

Delete the Integration

exo api delete-dbaas-integration INTEGRATION_ID -z ZONE

Parameters:

  • INTEGRATION_ID: the ID returned when the integration was created, also listed by exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q integrations.
  • ZONE: zone of the PostgreSQL service.

Deleting the Thanos service also deletes the integration.

Related Pages

Last updated on