caseyscarborough / qbittorrent-exporter

A prometheus exporter for qBittorrent.
82 stars 11 forks source link

qBittorrent exporter doesn't export data after qBittorrent was stopped #8

Closed martabal closed 2 years ago

martabal commented 2 years ago

Start qBittorrent then qBittorrent-exporter, stop qBittorrent and then restart qBittorrent. Ater the restart qBittorrent-exporter doesn't resume.

17:45:35.842 [ERROR] qbittorrent.exporter.handler.QbtHttpHandler - An error occurred calling API
qbittorrent.api.ApiException: Could not make GET request to http://xxx.xxx.xxx.xxx:xxxx/api/v2/torrents/info
at qbittorrent.api.ApiClient.getRequest(ApiClient.java:137) ~[qbittorrent-exporter.jar:?]
at qbittorrent.api.ApiClient.getRequest(ApiClient.java:145) ~[qbittorrent-exporter.jar:?]
at qbittorrent.api.ApiClient.getTorrents(ApiClient.java:108) ~[qbittorrent-exporter.jar:?]
at qbittorrent.exporter.handler.QbtHttpHandler.handleRequest(QbtHttpHandler.java:40) [qbittorrent-exporter.jar:?]
at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:104) [undertow-core-2.2.16.Final.jar:2.2.16.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:387) [undertow-core-2.2.16.Final.jar:2.2.16.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEventWithNoRunningRequest(HttpReadListener.java:256) [undertow-core-2.2.16.Final.jar:2.2.16.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:136) [undertow-core-2.2.16.Final.jar:2.2.16.Final]
at io.undertow.server.protocol.http.HttpReadListener.handleEvent(HttpReadListener.java:59) [undertow-core-2.2.16.Final.jar:2.2.16.Final]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) [xnio-api-3.8.6.Final.jar:3.8.6.Final]
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) [xnio-api-3.8.6.Final.jar:3.8.6.Final]
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89) [xnio-nio-3.8.6.Final.jar:3.8.6.Final]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591) [xnio-nio-3.8.6.Final.jar:3.8.6.Final]
Caused by: java.io.IOException: HTTP/1.1 header parser received no bytes
at jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:586) ~[java.net.http:?]
at jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:123) ~[java.net.http:?]
at qbittorrent.api.ApiClient.getRequest(ApiClient.java:126) ~[qbittorrent-exporter.jar:?]
... 12 more
Caused by: java.io.IOException: HTTP/1.1 header parser received no bytes
at jdk.internal.net.http.common.Utils.wrapWithExtraDetail(Utils.java:348) ~[java.net.http:?]
at jdk.internal.net.http.Http1Response$HeadersReader.onReadError(Http1Response.java:675) ~[java.net.http:?]
at jdk.internal.net.http.Http1AsyncReceiver.checkForErrors(Http1AsyncReceiver.java:302) ~[java.net.http:?]
at jdk.internal.net.http.Http1AsyncReceiver.flush(Http1AsyncReceiver.java:268) ~[java.net.http:?]
at jdk.internal.net.http.common.SequentialScheduler$LockingRestartableTask.run(SequentialScheduler.java:205) ~[java.net.http:?]
at jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:149) ~[java.net.http:?]
at jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230) ~[java.net.http:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.io.EOFException: EOF reached while reading
at jdk.internal.net.http.Http1AsyncReceiver$Http1TubeSubscriber.onComplete(Http1AsyncReceiver.java:596) ~[java.net.http:?]
at jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:640) ~[java.net.http:?]
at jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:845) ~[java.net.http:?]
at jdk.internal.net.http.SocketTube$SocketFlowTask.run(SocketTube.java:181) ~[java.net.http:?]
at jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230) ~[java.net.http:?]
at jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:303) ~[java.net.http:?]
at jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:256) ~[java.net.http:?]
at jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:774) ~[java.net.http:?]
at jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:957) ~[java.net.http:?]
at jdk.internal.net.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:253) ~[java.net.http:?]
at jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:979) ~[java.net.http:?]
at jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:934) ~[java.net.http:?]
at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?]
at jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:934) ~[java.net.http:?]
17:45:35.839 [INFO] qbittorrent.exporter.handler.QbtHttpHandler - Beginning prometheus metrics collection...
caseyscarborough commented 2 years ago

Thanks for the report @martabal. qBittorrent needs to be up for qbittorrent-exporter to call the qBittorrent API, so requests to qbittorrent-exporter will fail if qBittorrent is down (with these exceptions in the log). It will resume normally once qBittorrent is back up.

Is your suggestion that qbittorrent-exporter should continue to export data (perhaps adding a qbittorrent_up flag) when qBittorrent is down? As of now I am using the "return a 500 response" approach listed in the Prometheus "failed scrapes" documentation.

On a side note, your issue also made me realize that qbittorrent-exporter will fail to start when qBittorrent is down. I opened #9 for that issue which I will resolve.

martabal commented 2 years ago

Yes, it is perfectly normal to wait for qBittorrent to be up and running again. My suggestion is that qbittorrent-exporter restarts to export data when qBittorrent is up.

caseyscarborough commented 2 years ago

@martabal that is how it currently works - if qBittorrent restarts, the exporter will continue normally when qBittorrent comes back up.

The header parser received no bytes in the error message sounds like it's something on the qBittorrent side.

If you can provide the following info I can look into the problem:

martabal commented 2 years ago

I am using qbittorrent v4.4.1and qbittorrent-exporter v1.3.1

martabal commented 2 years ago

After further investigations, here is the error message i get when i restart qbittorrent :

qbittorrent.api.ApiException: An error occurred calling http://xxx.xxx.xxx.xxx:xxxx/api/v2/torrents/info: (403) Forbidden

Maybe it is an error with the authentication ?

caseyscarborough commented 2 years ago

Okay, good find. I'm running 4.4.0. The authentication relies on an "auth cookie" returned from the initial login, but maybe restarting qBittorrent in 4.4.1 now invalidates that cookie.

I will try to reproduce this. I think a simple fix would be just getting a new auth cookie if a 403 is returned, but either way I will get this fixed. 👍

caseyscarborough commented 2 years ago

@martabal This has been fixed in 1.3.2 and a new image is available on DockerHub (make sure to repull your image if you're using the latest tag).

martabal commented 2 years ago

I tested it and it works perfectly. Thank you so much!