Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy postgres_exporter on the Docker and connect to prometheus

I have a server on Debian 8 where docker is installed. The approach is needed in containers. The container is installed postgres 9.6. I want to set up data collection of the pg_stat_statements table in prometheus via postgres_exporter from PostgreSQL, and then look at the graph via grafana. Deployment grafana and Prometheus did according to the instructions:

$ git clone https://github.com/stefanprodan/dockprom
$ cd dockprom
$ docker-compose up -d

In prometheus.yml added:

- job_name: 'postgres-exporter'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9187']

But I have problem with postgres-exporter: Prometheus targets status

Took this export statistics for PostgreSQL: link. I tried to deploy to docker with different ports, but Prometheus did not want to connect to him. Tell me, please, how properly install and deploy?

like image 538
AlexV Avatar asked Dec 01 '25 13:12

AlexV


1 Answers

If you want to scrape only postgresdb metrics ,you can just use docker commands instead of docker-compose

sudo docker run --name postgres-exporter -e DATA_SOURCE_NAME="postgresql://<postgresdb_user_name>:<postgres_db_password>@<postgres_vm_ip>:<postgresdb_port>/?sslmode=disable" -p 9187:9187 wrouesnel/postgres_exporter

For me the full command I executed was

sudo docker run --name postgres-exporter -e DATA_SOURCE_NAME="postgresql://postgres:[email protected]:5432/?sslmode=disable" -p 9187:9187 wrouesnel/postgres_exporter

Then added scraping point in prometheus.yml file

- job_name: postgres_100031
  static_configs:
  - targets: ['10.0.0.31:9187']

Restart Prometheus service

like image 56
Manju N Avatar answered Dec 04 '25 06:12

Manju N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!