Datadog Agent for PostgreSQL :: Kloudfuse Docs
Datadog Agent for PostgreSQL
Kloudfuse collects metrics and logs from self-managed PostgreSQL deployments using the Kloudfuse observability agent. The agent discovers PostgreSQL pods automatically via Kubernetes pod annotations — no separate scraper deployment is required.
Overview
The Kloudfuse observability agent (kfuse-observability-agent) is a customised Datadog agent that runs as a DaemonSet — one pod on every Kubernetes node in your cluster. It uses Datadog Autodiscovery: it continuously watches pod annotations prefixed with ad.datadoghq.com/ to find services to monitor.
When the agent finds a PostgreSQL pod with the right annotations, it:
- Resolves
%%host%%to the pod’s cluster IP and%%port%%to its port — automatically, from the pod’s own network identity. - Opens a TCP connection to PostgreSQL using the credentials in the annotation.
- Runs the built-in
postgrescheck, queryingpg_stat_statements,pg_stat_bgwriter,pg_stat_replication, andpg_stat_database. - Forwards the results to the Kloudfuse ingester as time-series metrics.
The flow for logs is similar: the agent tail-reads the PostgreSQL log output from the same pod and sends log lines to the Kloudfuse log ingestion endpoint.
Prerequisites
Enable pg_stat_statements
The postgres check depends on the pg_stat_statements extension for query-level metrics.
- Add it to
shared_preload_librariesinpostgresql.conf:shared_preload_libraries = 'pg_stat_statements'
If you manage PostgreSQL with Helm (for example, Bitnami’s postgresql chart):
postgresql:
primary:
postgresqlSharedPreloadLibraries: "pg_stat_statements"
- Restart PostgreSQL, then create the extension in each database you want to monitor:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
Create a Monitoring User
The postgres check connects using a dedicated low-privilege user. Follow Datadog’s pre-flight steps to create this user and grant the required permissions.
At minimum, the user needs:
CREATE USER kfmon WITH PASSWORD '<password>' CONNECTION LIMIT 5;
GRANT pg_monitor TO kfmon; -- PostgreSQL 10+
GRANT SELECT ON pg_stat_database TO kfmon;
GRANT SELECT ON pg_stat_statements TO kfmon;
On PostgreSQL 14+, also grant access to the statements info view:
GRANT SELECT ON pg_stat_statements_info TO kfmon;
Verify the Observability Agent Is Running
Confirm DaemonSet pods are running on the same nodes as your PostgreSQL pods:
kubectl get pods -n <kloudfuse-namespace> -l app=kfuse-observability-agent -o wide
kubectl get pods -n <postgresql-namespace> -l app.kubernetes.io/name=postgresql -o wide
Every node that runs a PostgreSQL pod must also have a healthy observability agent pod.
Configure Autodiscovery Annotations
The observability agent picks up the PostgreSQL check when your pod carries the following annotations. Add them to the pod template of your PostgreSQL Deployment, StatefulSet, or Helm chart values.
Metrics
podAnnotations:
ad.datadoghq.com/postgresql.check_names: '[