Does anyone have any examples of what a postgres_exporter.yml file is supposed to look like?

1,194 views
Skip to first unread message

Christian Sanchez

unread,
May 7, 2024, 4:24:18 PM5/7/24
to Prometheus Users
Hello, all.

I've started to learn Prometheus and found out about the postgres_exporter. I'd like to include metrics from the PostgreSQL server I have running on Google Cloud.

I don't understand how to actually build out the postgres_exporter.yml file. The prometheus-community GitHub repository doesn't seem to have examples of building this file out.

Maybe I am not reading the README in the repo that well, but I'd like to see some examples of the exporter file.

When running the Prometheus container, this is where I'm expecting to see the exporter query options (see attachment)


I am running Prometheus and the Postgres Exporter through Docker Compose.
Here is my docker-compose.yml file:
version: '3'
services:
prometheus:
image: prom/prometheus
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
ports:
- 9090:9090

postgres-exporter:
image: prometheuscommunity/postgres-exporter
volumes:
- "./postgres_exporter.yml:/postgres_exporter.yml:ro"
ports:
- 9187:9187
environment:
DATA_SOURCE_NAME: "postgresql://my-user:my-pa...@host.docker.internal:5432/my-database?sslmode=disable"


Here is my prometheus.yml file:
global:
scrape_interval: 45s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'postgresql_exporter'
static_configs:
- targets: ['host.docker.internal:5432']


SCR-20240507-lwkc.png

Ben Kochie

unread,
May 7, 2024, 4:27:41 PM5/7/24
to Christian Sanchez, Prometheus Users
The postgres_exporter queries configuration is deprecated, you don't need it to monitor postgres servers anymore.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/71ef99c5-706c-420a-829e-0679680ee807n%40googlegroups.com.

Brian Candler

unread,
May 8, 2024, 2:11:46 AM5/8/24
to Prometheus Users
- job_name: 'postgresql_exporter'
static_configs:
- targets: ['host.docker.internal:5432']

One problem I can see is that you're trying to get prometheus to scrape the postgres SQL port. If you go to the Prometheus web UI and look at the Status > Targets menu option, I think you will see it's currently failing.  Or run the query "up == 0".

You need to change it to scrape prometheus exporter: that is port 9187, not port 5432.

However, before you get around to configuring prometheus, I suggest you first make sure that postgres-exporter itself is working properly, by scraping it manually:

curl x.x.x.x:9187/metrics

(or inside the exporter container you could try curl 127.0.0.1:9187/metrics, but that depends if the container has a "curl" binary)

Once you're able to do that (which may also require adjusting your postgres_exporter.yml and/or pg_hba.conf, then move on to configuring postgres.

Brian Candler

unread,
May 8, 2024, 4:38:20 AM5/8/24
to Prometheus Users
...then move on to configuring prometheus I meant.
Reply all
Reply to author
Forward
0 new messages