---
title: "Send Metrics to Managed Thanos"
description: "Store Managed PostgreSQL and PgBouncer metrics in an Exoscale Managed Thanos service with a metrics integration, and query them with PromQL."
url: https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/send-metrics-to-thanos/
product: "PostgreSQL"
section: product
last_updated: 2026-11-10
---
> For AI agents: the documentation index is at https://community.exoscale.com/llms.txt. Every page is available as markdown at `<page URL>index.md` or with `Accept: text/markdown`.

# 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](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/monitor-your-service/index.md#forward-metrics-to-an-external-system).

## Prerequisites

- The [Exoscale CLI](https://community.exoscale.com/reference/cli/exo/index.md), configured with your API credentials.
- A running Managed PostgreSQL service, on any plan.
- A running [Managed Thanos](https://community.exoscale.com/product/dbaas/service-specific/thanos/index.md) 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

```bash
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](https://community.exoscale.com/product/dbaas/service-specific/thanos/how-to/retention-downsampling/index.md).

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:

```bash
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`:

```bash
exo dbaas user reveal-secrets THANOS_SERVICE avnadmin -z THANOS_ZONE
```

Then query the Prometheus-compatible API:

```bash
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:

```json
{"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:

| Label | Content |
| --- | --- |
| `service` | Name of the PostgreSQL service. Filter on it when several services send metrics to the same Thanos service. |
| `host` | Node, for example `my-postgresql-1`. |
| `role` | `master` on the primary node. Only on `postgresql_*` series. |
| `datname` | Database, on per-database series. |
| `schema_name`, `table_name` | Schema and table, on per-table series. |
| `db` | Connection pool, on `pgbouncer_*` series. |
| `application_name`, `sync_state` | Replication consumer, on `postgresql_pg_stat_replication_*` series. |
| `cloud` | `exoscale-` followed by the zone, for example `exoscale-ch-gva-2`. |
| `service_type` | `pg`. |

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

| Prefix | Covers |
| --- | --- |
| `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](https://community.exoscale.com/product/dbaas/service-specific/postgresql/reference/metrics/index.md). List every metric
name a Thanos service holds with:

```bash
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

| Question | PromQL |
| --- | --- |
| Connections open | `sum by (service) (postgresql_pg_stat_activity_conn_count{service="my-postgresql"})` |
| Disk used, in percent | `max by (service) (disk_used_percent{service="my-postgresql", path="/var/lib/pgsql"})` |
| Transaction ID age against `autovacuum_freeze_max_age` | `max by (service, datname) (postgresql_transactions_txns / postgresql_transactions_freeze_limit)` |
| Tables served least from cache | `min by (service, table_name) (postgresql_pg_statio_user_tables_cache_hit_ratio{service="my-postgresql"})` |
| Standby replication lag, in bytes | `max by (service, application_name) (postgresql_pg_stat_replication_replication_flush_lag_bytes{service="my-postgresql", application_name!="pghoard"})` |
| Commits per second | `rate(postgresql_pg_stat_database_xact_commit{service="my-postgresql"}[5m])` |
| Queries per second through a pool | `rate(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](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/avoid-transaction-id-wraparound/index.md)
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](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/visualize-in-grafana/index.md#add-the-metrics-from-thanos).

## 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

```bash
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

- [Monitor a Managed PostgreSQL service](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/monitor-your-service/index.md)
- [Service metrics](https://community.exoscale.com/product/dbaas/service-specific/postgresql/reference/metrics/index.md)
- [Send logs to Managed OpenSearch](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/send-logs-to-opensearch/index.md)
- [Visualize a service in Managed Grafana](https://community.exoscale.com/product/dbaas/service-specific/postgresql/how-to/visualize-in-grafana/index.md)
- [Managed Thanos](https://community.exoscale.com/product/dbaas/service-specific/thanos/index.md)

