MiguelNdeCarvalho / speedtest-exporter

Speedtest Exporter made in python using the official speedtest bin
https://docs.miguelndecarvalho.pt/projects/speedtest-exporter/
GNU General Public License v3.0
194 stars 56 forks source link

Healthcheck failures #216

Open bergpb opened 5 months ago

bergpb commented 5 months ago

Hello, first thanks for this awesome project.

I was running this project for a while in my homelab and works fine, but the application starts to show a healthcheck error. I've tested with older images (until v3.5.0) and the healthcheck still failing.

Here the log output:

docker run -d -p 9798:9798 miguelndecarvalho/speedtest-exporter:v3.5.4
2a18ceedb1c350a77fcaf19099a411df0839cd227d45d92222da4511ed7c5e63

docker logs -f 2a18                                   
level=INFO datetime=2024-05-18 13:50:15,885 Starting Speedtest-Exporter on http://localhost:9798

{"Status":"unhealthy","FailingStreak":3,"Log":[{"Start":"2024-05-18T10:50:45.647089904-03:00","End":"2024-05-18T10:50:45.707512386-03:00","ExitCode":1,"Output":"Connecting to localhost:9798 ([::1]:9798)\nwget: can't connect to remote host: Connection refused\n"},{"Start":"2024-05-18T10:51:15.708851162-03:00","End":"2024-05-18T10:51:15.799501015-03:00","ExitCode":1,"Output":"Connecting to localhost:9798 ([::1]:9798)\nwget: can't connect to remote host: Connection refused\n"},{"Start":"2024-05-18T10:51:45.800123117-03:00","End":"2024-05-18T10:51:45.855748254-03:00","ExitCode":1,"Output":"Connecting to localhost:9798 ([::1]:9798)\nwget: can't connect to remote host: Connection refused\n"}]}

Docker environment info:

docker info                                           
Client: Docker Engine - Community
 Version:    26.1.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Using a custom healthcheck configuration pointing to 0.0.0.0 instead of localhost works fine:

docker inspect --format '{{json .Config.Healthcheck }}' fda
{"Test":["CMD-SHELL","wget --no-verbose --tries=1 --spider http://0.0.0.0:9798/"],"Interval":30000000000,"Timeout":15000000000,"StartPeriod":60000000000,"Retries":3}

docker inspect --format '{{json .State.Health }}' fda
{"Status":"healthy","FailingStreak":0,"Log":[{"Start":"2024-05-18T11:25:31.440087371-03:00","End":"2024-05-18T11:25:31.506016765-03:00","ExitCode":0,"Output":"Connecting to 0.0.0.0:9798 (0.0.0.0:9798)\nremote file exists\n"},{"Start":"2024-05-18T11:26:01.507290157-03:00","End":"2024-05-18T11:26:01.590485589-03:00","ExitCode":0,"Output":"Connecting to 0.0.0.0:9798 (0.0.0.0:9798)\nremote file exists\n"},{"Start":"2024-05-18T11:26:31.591690522-03:00","End":"2024-05-18T11:26:31.678995386-03:00","ExitCode":0,"Output":"Connecting to 0.0.0.0:9798 (0.0.0.0:9798)\nremote file exists\n"},{"Start":"2024-05-18T11:27:01.679600908-03:00","End":"2024-05-18T11:27:01.761742513-03:00","ExitCode":0,"Output":"Connecting to 0.0.0.0:9798 (0.0.0.0:9798)\nremote file exists\n"},{"Start":"2024-05-18T11:27:31.762580276-03:00","End":"2024-05-18T11:27:31.81281502-03:00","ExitCode":0,"Output":"Connecting to 0.0.0.0:9798 (0.0.0.0:9798)\nremote file exists\n"}]}

Also, I've installed curl to check if this issue happens with it too, but looks like only happens with wget command:

/app # wget http://localhost:9798
Connecting to localhost:9798 ([::1]:9798)
wget: can't connect to remote host: Connection refused
/app # curl http://localhost:9798
<h1>Welcome to Speedtest-Exporter.</h1>Click <a href='/metrics'>here</a> to see metrics./app #

If this is an issue that happens with other users too, I can open a PR changing the healthcheck address in Dockerfile.

Also can be similar to this one: #212

nikkopt commented 5 months ago

Yep i'm having the same problem

pablittus commented 4 months ago

Same issue, same test and same results.

SeimusS commented 3 months ago

Same problem,

For time being I did create an image from the running container adjusting the health-check.

docker inspect --format '{{json .Config.Healthcheck }}' speedtest
{"Test":["CMD-SHELL","wget --no-verbose --tries=1 --spider http://localhost:${SPEEDTEST_PORT:=9798}/"],"Timeout":10000000000}

docker container commit --change='HEALTHCHECK --timeout=10s CMD wget --no-verbose --tries=1 --spider http://0.0.0.0:${SPEEDTEST_PORT:=9798}/' speedtest miguelndecarvalho/speedtest-exporter:latest

docker compose up -d

docker inspect --format '{{json .Config.Healthcheck }}' speedtest
{"Test":["CMD-SHELL","wget --no-verbose --tries=1 --spider http://0.0.0.0:${SPEEDTEST_PORT:=9798}/"],"Timeout":10000000000}

Hopefully your PR gets thru.

Regards, S.

jbyers commented 2 months ago

For those running from docker-compose, healthcheck can also be overriden similar to https://github.com/MiguelNdeCarvalho/speedtest-exporter/issues/216#issuecomment-2211278303:

    healthcheck:
      test: "wget --no-verbose --tries=1 --spider http://0.0.0.0:9798/"
      timeout: 10s