jsclayton / prometheus-plex-exporter

Export metrics from your Plex Media Server
GNU Affero General Public License v3.0
117 stars 13 forks source link

Retry failed websocket connection when connecting to Plex #6

Open bnjns opened 1 year ago

bnjns commented 1 year ago

First of all, thanks so much for building this - love being able to monitor my plex server from Grafana!

I think this is related to the TODO in listener.go, but if you start the exporter before plex is ready then it fails to connect and doesn't retry, meaning you have to manually restart the exporter in order to then get metrics.

level=error msg="Get \"http://<ip>:32400/media/providers?includeStorage=1\": dial tcp <ip>:32400: connect: connection refused"
level=error msg="error in websocket processing" err="websocket: bad handshake"
level=info msg="Successfully connected" machineID= server=

I'm using Docker to run plex, the exporter, and the grafana agent. I've tried to mitigate by adding health checks to plex and configuring the exporter with a depends_on but it appears that's not enough when the computer starts up. Easily rectified with docker-compose restart exporter but I'd rather not have to remember to run this every day!

liaralabs commented 1 year ago

I faced this issue with Kubernetes as well (thanks for even bringing this up.. I couldn't figure out why I wasn't getting playback metrics). The problem is a little harder to solve here because k8s doesn't really have a concept of dependencies. If you have more than one container in a pod they are always started simultaneously and there are longstanding issues regarding this problem open on the k8s project.

Regardless, for kubernetes, I managed to fix this with a healthcheck of sorts:

        lifecycle:
          postStart:
            exec:
              command: ["/bin/sh", "-c", "if ! wget -O- --no-check-certificate 127.0.0.1:32400/web; then reboot; fi"]

This goes in the spec for the exporter container and seems to be working well. All this does is reach out the the plex server and reboot the exporter container if the plex server isn't ready yet.