Prometheus PostgreSQL server exporter example not working on MacOS?

故事扮演 提交于 2019-12-13 04:35:45

问题


I'd like to try out the quick start example at https://github.com/wrouesnel/postgres_exporter on a MacOS host device. In one terminal, I run a postgres image in interactive mode on the host network:

> docker run --network=host -it --rm --env POSTGRES_PASSWORD=password postgres
Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
8f91359f1fff: Pull complete 
c6115f5efcde: Pull complete 
28a9c19d8188: Pull complete 
2da4beb7be31: Pull complete 
fb9ca792da89: Pull complete 
cedc20991511: Pull complete 
b866c2f2559e: Pull complete 
5d459cf6645c: Pull complete 
cf66247ad881: Pull complete 
35e29440d9da: Pull complete 
362779251360: Pull complete 
fb82d778d08d: Pull complete 
b1f8d21ff25d: Pull complete 
6d49eb0e8dd0: Pull complete 
Digest: sha256:be456a40361cd836e0e1b35fc4d872e20e138f214c93138425169c4a2dfe1b0e
Status: Downloaded newer image for postgres:latest
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Etc/UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

waiting for server to start....2019-10-03 19:06:10.222 UTC [42] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-03 19:06:10.235 UTC [43] LOG:  database system was shut down at 2019-10-03 19:06:10 UTC
2019-10-03 19:06:10.239 UTC [42] LOG:  database system is ready to accept connections
 done
server started

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

waiting for server to shut down....2019-10-03 19:06:10.320 UTC [42] LOG:  received fast shutdown request
2019-10-03 19:06:10.322 UTC [42] LOG:  aborting any active transactions
2019-10-03 19:06:10.325 UTC [42] LOG:  background worker "logical replication launcher" (PID 49) exited with exit code 1
2019-10-03 19:06:10.325 UTC [44] LOG:  shutting down
2019-10-03 19:06:10.338 UTC [42] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2019-10-03 19:06:10.436 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-10-03 19:06:10.438 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2019-10-03 19:06:10.440 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019-10-03 19:06:10.450 UTC [51] LOG:  database system was shut down at 2019-10-03 19:06:10 UTC
2019-10-03 19:06:10.453 UTC [1] LOG:  database system is ready to accept connections

while in another terminal, I run postgres_exporter and connect it to that database:

> docker run --net=host --env DATA_SOURCE_NAME="postgresql://postgres:password@localhost:5432/postgres?sslmode=disable" wrouesnel/postgres_exporter
Unable to find image 'wrouesnel/postgres_exporter:latest' locally
latest: Pulling from wrouesnel/postgres_exporter
0d6d2d2516f9: Pull complete 
e9d7b571ef5e: Pull complete 
Digest: sha256:aeea975f0efeacb49c170f0f7c4a4000d3f0099cc33437aedd3f276e628cde1c
Status: Downloaded newer image for wrouesnel/postgres_exporter:latest
time="2019-10-03T19:09:20Z" level=info msg="Established new database connection to \"localhost:5432\"." source="postgres_exporter.go:778"
time="2019-10-03T19:09:20Z" level=info msg="Semantic Version Changed on \"localhost:5432\": 0.0.0 -> 11.5.0" source="postgres_exporter.go:1238"
time="2019-10-03T19:09:20Z" level=info msg="Starting Server: :9187" source="postgres_exporter.go:1459"

As I understand it, I should be able to go to localhost:9187 in my browser and see the exported metrics. What I get, however, is that the connection gets refused:

> curl http://localhost:9187
curl: (7) Failed to connect to localhost port 9187: Connection refused

What I suspect is that this is because, as documented at https://docs.docker.com/network/host/,

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

Is this what is causing the issue and if so, how can I adapt this quickstart example to work using Docker Desktop for Mac?

来源:https://stackoverflow.com/questions/58225609/prometheus-postgresql-server-exporter-example-not-working-on-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!