avojak / pihole-influxdb-monitor

Export Pi-hole statistics to InfluxDB 2.x
MIT License
24 stars 6 forks source link

Max retries exceeded with PiHole url #12

Closed lenkeybalis closed 1 month ago

lenkeybalis commented 1 month ago

Dear Maintainer,

I use the docker-compose base setup. The pihole-exporter is running with PiHole server on the same server.

version: "3.9"
services:
  pihole-influxdb:
    image: avojak/pihole-influxdb:latest
    container_name: pihole-influxdb
    restart: unless-stopped
    environment:
      - "PIHOLE_ALIAS=pihole"
      - "PIHOLE_ADDRESS=http://192.168.0.30:80"
      - "PIHOLE_TOKEN=***********************************"
      - "PIHOLE_NUM_TOP_ITEMS=25"
      - "PIHOLE_NUM_TOP_CLIENTS=25"
      - "INFLUXDB_ADDRESS=https://*********************"
      - "INFLUXDB_ORG=influxdata"
      - "INFLUXDB_TOKEN=***************************************"
      - "INFLUXDB_BUCKET=pihole"

There are the following errors In the log :

pihole-influxdb  | 20:00:23 [ERROR] [pihole] Error connecting to http://192.168.0.30:80: HTTPConnectionPool(host='192.168.0.30', port=80): Max retries exceeded with url: /admin/api.php?summaryRaw&topItems=25&topClients=25&getForwardDestinations&getQueryTypes&auth=dd3ce459b1285a539966dc39                                                                  6bbbaa2d6ac2a002f7b3f36256d9fb3ce0e983e8 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7d969d798920>, 'Connectio                                                                  n to 192.168.0.30 timed out. (connect timeout=30.0)'))
pihole-influxdb  | 20:00:53 [ERROR] [pihole] Error connecting to http://192.168.0.30:80: HTTPConnectionPool(host='192.168.0.30', port=80): Max retries exceeded with url: /admin/api.php?overTimeData10mins&auth=dd3ce459b1285a539966dc396bbbaa2d6ac2a002f7b3f36256d9fb3ce0e983e8 (Caused by Con                                                                  nectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7d969d47eba0>, 'Connection to 192.168.0.30 timed out. (connect timeout=30.0)'))

I checked the connection from the same machine via cUrl.

$ curl -v http://192.168.0.30/admin/api.php?overTimeData10mins&auth=**************************************
[1] 757581
root@lcloud-bastion:~/pihole-exporter-to-influx2# *   Trying 192.168.0.30:80...
* Connected to 192.168.0.30 (192.168.0.30) port 80 (#0)
> GET /admin/api.php?overTimeData10mins HTTP/1.1
> Host: 192.168.0.30
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< Set-Cookie: PHPSESSID=95fkskkn7i1mtqrcfa8ddjnf5v; path=/; HttpOnly; SameSite=Strict
< Content-type: application/json
< X-Pi-hole: The Pi-hole Web interface is working!
< X-Frame-Options: DENY
< X-XSS-Protection: 0
< X-Content-Type-Options: nosniff
< Content-Security-Policy: default-src 'self' 'unsafe-inline';
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: same-origin
< Accept-Ranges: bytes
< Content-Length: 2
< Date: Sun, 09 Jun 2024 20:36:49 GMT
< Server: lighttpd/1.4.63
<
* Connection #0 to host 192.168.0.30 left intact

The connection is working fine. Did you observe this kind of problem in the past or it would be a specific problem only for me?

Thank you so much for your help!

Regards, Balazs

lenkeybalis commented 1 month ago

I checked with native python scrip based execution. It seems to be working fine without issue. So maybe there will be the problem with my docker configuration or setup.

(pihole-exporter) blenkey@lcloud-bastion:~/pihole-influxdb-monitor$ python3 pihole-influxdb.py --pihole-alias "pihole" --pihole-address "http://192.168.0.30" --pihole-token "***" --pihole-num-top-items 25 --pihole-num-top-clients 25 --influxdb-address "https://influxdb" --influxdb-org "influx" --influxdb-token "----------" --influxdb-bucket "pihole" 21:29:15 [INFO] ================== Configuration ================== 21:29:15 [INFO] Pi-holes: pihole http://192.168.0.30 (Auth token provided) 21:29:15 [INFO] Poll interval: 60 seconds 21:29:15 [INFO] InfluxDB address: https://influxdb 21:29:15 [INFO] InfluxDB org: influxdata 21:29:15 [INFO] InfluxDB token: ** 21:29:15 [INFO] InfluxDB bucket: pihole 21:29:15 [INFO] InfluxDB verify SSL: True 21:29:15 [INFO] =================================================== 21:29:15 [INFO] Starting... 21:29:15 [INFO] [pihole] Queried successfully in 24ms 21:29:17 [INFO] [pihole] Wrote to InfluxDB successfully in 2418ms

lenkeybalis commented 1 month ago

Now I found the issue I needed to use this option in the docker-compose.yaml file.:

network_mode: "host"

root@lcloud-bastion:~/pihole-exporter-to-influx2# docker compose up WARN[0000] /root/pihole-exporter-to-influx2/docker-compose.yaml: version is obsolete [+] Running 0/1 ⠙ Container pihole-influxdb Recreated 0.2s Attaching to pihole-influxdb pihole-influxdb | 19:38:23 [INFO] ================== Configuration ================== pihole-influxdb | 19:38:23 [INFO] Pi-holes: pihole http://192.168.0.30 (Auth token provided) pihole-influxdb | 19:38:23 [INFO] Poll interval: 60 seconds pihole-influxdb | 19:38:23 [INFO] InfluxDB address: https://influxdb pihole-influxdb | 19:38:23 [INFO] InfluxDB org: influx pihole-influxdb | 19:38:23 [INFO] InfluxDB token: ** pihole-influxdb | 19:38:23 [INFO] InfluxDB bucket: pihole pihole-influxdb | 19:38:23 [INFO] InfluxDB verify SSL: True pihole-influxdb | 19:38:23 [INFO] =================================================== pihole-influxdb | 19:38:23 [INFO] Starting... pihole-influxdb | 19:38:23 [INFO] [pihole] Queried successfully in 30ms pihole-influxdb | 19:38:24 [INFO] [pihole] Wrote to InfluxDB successfully in 151ms