metalmatze / transmission-exporter

Prometheus exporter for Transmission metrics, written in Go.
MIT License
99 stars 40 forks source link

Crashing on load #3

Closed wywywywy closed 6 years ago

wywywywy commented 6 years ago

Hi,

I am using Transmission 2.92, and my copy of transmission-exporter is compile with Go 1.9, inside of a LXC container (not Docker).

Basically as soon as I go to :19091/metrics, the exporter just crashes.

2018/01/18 01:55:36 starting transmission-exporter
2018/01/18 01:55:39 failed to get session: Post 192.168.1.88/transmission/rpc: unsupported protocol scheme ""
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x6b100a]

goroutine 33 [running]:
main.(*SessionCollector).Collect(0xc42013cc40, 0xc420128480)
        /root/go/src/github.com/metalmatze/transmission-exporter/cmd/transmission-exporter/session_collector.go:135 +0xca
github.com/metalmatze/transmission-exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func2(0xc420122290, 0xc420128480, 0x8f8ba0, 0xc42013cc40)
        /root/go/src/github.com/metalmatze/transmission-exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:382 +0x61
created by github.com/metalmatze/transmission-exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).Gather
        /root/go/src/github.com/metalmatze/transmission-exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:380 +0x2e1

It looks like it doesn't understand the RPC, but the webUI works fine so I think the RPC must be working fine as well? The IP is definitely in the RPC whitelist.

Any ideas please?

Thanks.

metalmatze commented 6 years ago

2018/01/18 01:55:39 failed to get session: Post 192.168.1.88/transmission/rpc: unsupported protocol scheme "" If you read closely then you can see unsupported protocol scheme "". You simply need to add http or https to the beginning. :wink: Hope that helps!

wywywywy commented 6 years ago

Sorry I should mention that I already have.

This is my .env -

TRANSMISSION_ADDR=http://192.168.1.88:9091
TRANSMISSION_PASSWORD=
TRANSMISSION_USERNAME=
WEB_ADDR=:19091
WEB_PATH=/metrics

I tried putting the value in quotes too but that didn't help.

metalmatze commented 6 years ago

Are you sure that transmission is reachable at exactly that address? I have a setup where I have to use: TRANSMISSION_ADDR=https://sub.example.com/username

wywywywy commented 6 years ago

Yes my webUI address is http://192.168.1.88:9091/transmission/web/ and it work fine.

The RPC address is http://192.168.1.88:9091/transmission/rpc and it correctly gives me a 409 status code.

$ curl http://192.168.1.88:9091/transmission/rpc
<h1>409: Conflict</h1><p>Your request had an invalid session-id header.</p><p>To fix this, follow these steps:<ol><li> When reading a response, get its X-Transmission-Session-Id header and remember it<li> Add the updated header to your outgoing requests<li> When you get this 409 error message, resend your request with the updated header</ol></p><p>This requirement has been added to help prevent <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF</a> attacks.</p><p><code>X-Transmission-Session-Id: PX4ozLic4WTbSirhkhK4dBcTx0AB3ThneiCtj1byqi6NP08x</code></p>
wywywywy commented 6 years ago

Sorry I got it to work now - without the .env.

If I export env variables, it works. Using .env, it doesn't. I am not sure why as long as it works I'm happy!

Do slashes need escaping in .env?

metalmatze commented 6 years ago

Glad to hear. Can you try one more time to maybe prove a theory for this? Can you remove TRANSMISSION_USERNAME and TRANSMISSION_PASSWORD from your .env?

Maybe setting them empty fails? Or did you set them now too?

wywywywy commented 6 years ago

Hi.

So I think I know what the problem (possibly) was now. I deleted the .env file and copied from the example again, changed the IP and now it works.

I think the .env file I had was possibly corrupt or there's unicode chars there that we can't see on the console or the line feed carriage return is messed up. I am not sure how that happened, but now I can say it works 100%.

Thank you very much for making this. Sorry to have wasted your time.

metalmatze commented 6 years ago

No problem at all. Happy to help and also happy that someone uses this :smile: