Sobes.tech
Middle

How do metrics from PostgreSQL get into Grafana?

sobes.tech AI

Answer from AI

Metrics from PostgreSQL are usually collected using specialized exporters, such as the PostgreSQL Exporter for Prometheus. The exporter connects to the database, gathers statistics, and provides them in a format understandable by Prometheus. Then, Prometheus periodically polls the exporter and stores the metrics. Grafana connects to Prometheus as a data source and visualizes these metrics in the form of graphs and dashboards.

Example schema:

  1. The PostgreSQL Exporter collects metrics from the database.
  2. Prometheus polls the exporter and stores the data.
  3. Grafana displays metrics from Prometheus.
# Example Prometheus configuration for PostgreSQL Exporter
scrape_configs:
  - job_name: 'postgresql'
    static_configs:
      - targets: ['localhost:9187']

Thus, data from PostgreSQL reaches Grafana through the chain exporter → Prometheus → Grafana.