postgresqlenvironment-variablesprometheusgrafana

Connecting to database from prometheus_exporter


To collect Postgres metrics in prometheus, postgres_exporter is used. Containerization is not used, everything is done natively. Hardware metrics are collected in a prometheus through a job. To collect database metrics, I need to connect the prometheus_exporter to the database. Tell me how to configure the connection to the database. postgres_exporter has no configuration files. Is it possible to do this via environment variables?

prometheus.yml:

scrape_configs:
     - job_name: postgresql
        static_configs:
          - targets: ['xx.xx.xx.xx:9187']
            labels:
              alias: postgres

Solution

  • DATA_SOURCE_NAME="postgresql://user:password@host:port/dbname?sslmode=disable" Here at the end dbname is must to avoid error. For my case I found it is ok now.

    DATA_SOURCE_NAME="postgresql://grafana:p@host:192.168.1.100/postgres?sslmode=disable"