Monitoring PostgreSQL Performance using OpenTelemetry
This tutorial explains how you can use OpenTelemetry and Uptrace to monitor PostgreSQL performance. Besides using Otel Collector to monitor your PostgreSQL servers, you can also use OpenTelemetry to instrument your applications with traces, metrics, and logs.
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework hosted by Cloud Native Computing Foundation. It is a merger of OpenCensus and OpenTracing projects.
OpenTelemetry aims to provide a single standard across all types of observability signals such as OpenTemetry tracing, and OpenTelemetry metrics.
OpenTelemetry specifies how to collect and send telemetry data to backend platforms. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation.
OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.
What is OpenTelemetry Collector?
OpenTelemetry Collector is an agent that pulls telemetry data from systems you want to monitor and sends it to tracing tools using the OpenTelemetry protocol (OTLP).
You can use OpenTelemetry Collector to monitor system metrics, PostgreSQL, MySQL, Redis, and more.
Uptrace
Uptrace is an open source APM for OpenTelemetry that helps developers pinpoint failures and find performance bottlenecks. Uptrace can process billions of spans on a single server and allows to monitor your software at 10x lower cost.
You can get started with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.
OpenTelemetry PostgreSQL receiver
To start monitoring PostgreSQL with Otel Collector, you need to configure PostgreSQL receiver in /etc/otel-contrib-collector/config.yaml
using Uptrace DSN:
receivers:
otlp:
protocols:
grpc:
http:
postgresql:
endpoint: localhost:5432
transport: tcp
username: otel
password: $POSTGRESQL_PASSWORD
databases:
- otel
collection_interval: 10s
tls:
insecure: true
exporters:
otlp:
endpoint: otlp.uptrace.dev:4317
headers: { 'uptrace-dsn': '<FIXME>' }
processors:
resourcedetection:
detectors: [system]
batch:
timeout: 10s
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp]
metrics:
receivers: [otlp, postgresql]
processors: [batch, resourcedetection]
exporters: [otlp]
Don't forget to restart the service:
sudo systemctl restart otelcol-contrib
You can also check OpenTelemetry Collector logs for any errors:
sudo journalctl -u otelcol-contrib -f
Available metrics
Uptrace automatically creates the following dashboard when PostgreSQL metrics are available:
Prometheus
You can also send OpenTelemetry metrics to Prometheus using OpenTelemetry Prometheus exporter.
What's next?
Next, you can learn more about configuring OpenTelemetry Collector and check available receivers.
To start using OpenTelemetry and Uptrace, see Getting started with Uptrace.