louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
55.74k stars 5.01k forks source link

Postgres connection timeout #4705

Closed stuzer05 closed 4 months ago

stuzer05 commented 4 months ago

📑 I have found these related issues/pull requests

Tried to setup PostgreSQL with custom port but getting connection timout

postgresql://root:root@127.0.0.1:4743/postgres
postgres://root:root@127.0.0.1:4743/postgres

🛡️ Security Policy

Description

No response

👟 Reproduction steps

Add PostgreSQL

👀 Expected behavior

Successful ping

😓 Actual Behavior

connect ETIMEDOUT 127.0.0.1:4743

🐻 Uptime-Kuma Version

latest docker

💻 Operating System and Arch

debian

🌐 Browser

firefox

🖥️ Deployment Environment

📝 Relevant log output

No response

CommanderStorm commented 4 months ago

Could you add details about your environment and what you are trying to monitor? You forgot to fill out most of the form which makes it hard to provide actionable help.

In particular: what docker-network are you using? Where is the posters container in relation to uptime Kuma?

stuzer05 commented 4 months ago

I try to monitor postgresql database using these DSN's (redacted host) with custom postgresql port. But gitea can't reach the database and throws connect ETIMEDOUT <ip>:4743 error

postgresql://root:root@<ip>:4743/postgres
postgres://root:root@<ip>:4743/postgres
CommanderStorm commented 4 months ago

But gitea can't reach the database and throws connect ETIMEDOUT <ip>:4743 error

This is Uptime Kuma, not gitea.

Also, you did not answer the questions I asked of you:

Could you add details about your environment and what you are trying to monitor? You forgot to fill out most of the form which makes it hard to provide actionable help.

In particular:

  • what docker-network are you using?
  • Where is the postgres container in relation to uptime Kuma?

[!TIP] In case you did not know: docker has more than one network type with only some of them allowing access to the local network and some not even allowing access to remote networks

stuzer05 commented 4 months ago

what docker-network are you using?

I run Uptime Kuma in default network as all the containers like so

docker run -d \
  --label=com.centurylinklabs.watchtower.enable=true \
  --restart=unless-stopped \
  -p 127.0.0.1:3001:3001 \
  -v uptime-kuma:/app/data \
  --name uptime-kuma \
  louislam/uptime-kuma:latest

Uptime Kuma can see MariaDB but not postgres with the same docker container options

docker run -d \
  --restart=unless-stopped \
  -p 4742:3306 \
  -p 127.0.0.1:33060:33060 \
  -v mariadb-data:/var/lib/mysql \
  -e MARIADB_ROOT_PASSWORD=root \
  --name mariadb \
  mariadb:latest

docker run -d \
  --restart=unless-stopped \
  -v postgres:/var/lib/postgresql/data \
  -e POSTGRES_USER=root \
  -e POSTGRES_PASSWORD=root \
  -p 4743:5432 \
  --name postgres \
  postgres

Where is the postgres container in relation to uptime Kuma?

On the same host, all the docker commands are above. MariaDB works with Uptime Kuma mysql://root:root@example.com:4742 but postgres doesn't postgresql://root:root@example.com:4743/postgres

chakflying commented 4 months ago

Not sure if this is the cause but it may have to do with the listening address you have configured for the postgres instance.

https://stackoverflow.com/questions/48341164/how-to-make-postgres-docker-accessible-for-any-ip-remotely

stuzer05 commented 4 months ago

postgres is accessible from anywhere, I've checked that. I suspect Kuma doesn't support custom port

CommanderStorm commented 4 months ago

I have tried to reproduce your example from above and Uptime Kuma and MariaDB cannot communicate. => please provide further details about your environment and how to create it reliably (including what you put at example.com in the connection strings)

I think this is because of your docker-network configuration and that the -p.

When I put them into the same network, everything works as expected:

version: '3.8'

services:
  uptime-kuma:
    image: louislam/uptime-kuma:latest
    ports:
      - "127.0.0.1:3001:3001"
  mariadb:
    image: mariadb:latest
    ports:
      - "4742:3306"
    environment:
      - MARIADB_ROOT_PASSWORD=root
  postgres:
    image: postgres
    ports:
      - "4743:5432"
    environment:
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root

image

stuzer05 commented 4 months ago

I found out that ufw was the problem. Postgres port wasn't allowed in firewall. Kuma and postgres are running on the same host. But I used a domain name in dsn for postgresql. However, for some reason, I can connect to postgres in dbeaver from by home.