mdlayher / rtorrent_exporter

Prometheus exporter that exposes metrics from rTorrent. MIT Licensed.
MIT License
38 stars 15 forks source link

Add support for scgi:// URL scheme. #10

Open neuroid opened 4 years ago

neuroid commented 4 years ago

Introduce SCGI transport to support direct rTorrent connections, e.g.: 1) Over TCP socket:

$ cat ~/.rtorrent.rc
network.scgi.open_port = 127.0.0.1:5000
$ rtorrent_exporter -rtorrent.addr scgi://127.0.0.1:5000

2) Over UNIX socket:

$ cat ~/.rtorrent.rc
network.scgi.open_local = /home/user/rtorrent/rpc.socket
$ rtorrent_exporter -rtorrent.addr scgi:///home/user/rtorrent/rpc.socket
neuroid commented 3 years ago

Hi @mdlayher. Any interest in merging this?

zimmertr commented 3 years ago

Is this branch worth using over master?

barnumbirr commented 3 years ago

@neuroid thanks a lot for this, shame it's not been merged upstream yet. Works great most of the time but fails when host is experiencing high network load (a few torrents leeching or seeding). Here's an excerpt from strace:

futex(0x7cd708, FUTEX_WAIT_PRIVATE, 0, NULL) = 0
epoll_pwait(5, [], 128, 0, NULL, 0)     = 0
epoll_pwait(5, [{EPOLLOUT, {u32=2544840056, u64=281473226583416}}], 128, 29998, NULL, 0) = 1
getsockopt(8, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
getpeername(8, {sa_family=AF_INET, sin_port=htons(5000), sin_addr=inet_addr("127.0.0.1")}, [112->16]) = 0
futex(0x4000046548, FUTEX_WAKE_PRIVATE, 1) = 1
getsockname(8, {sa_family=AF_INET, sin_port=htons(40936), sin_addr=inet_addr("127.0.0.1")}, [112->16]) = 0
setsockopt(8, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(8, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(8, SOL_TCP, TCP_KEEPINTVL, [30], 4) = 0
setsockopt(8, SOL_TCP, TCP_KEEPIDLE, [30], 4) = 0
write(8, "26:CONTENT_LENGTH\000203\0SCGI\0001\0,<?"..., 233) = 233
read(8, 0x40001e8000, 4096)             = -1 EAGAIN (Resource temporarily unavailable)
futex(0x7cd708, FUTEX_WAIT_PRIVATE, 0, NULL) = 0
epoll_pwait(5, [{EPOLLIN|EPOLLOUT|EPOLLRDHUP, {u32=2544840056, u64=281473226583416}}], 128, 0, NULL, 0) = 1
epoll_pwait(5, [{EPOLLOUT, {u32=2544840056, u64=281473226583416}}], 128, 29995, NULL, 0) = 1
getsockopt(8, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
getpeername(8, {sa_family=AF_INET, sin_port=htons(5000), sin_addr=inet_addr("127.0.0.1")}, [112->16]) = 0
futex(0x4000046948, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x4000047148, FUTEX_WAKE_PRIVATE, 1) = 1
getsockname(8, {sa_family=AF_INET, sin_port=htons(40938), sin_addr=inet_addr("127.0.0.1")}, [112->16]) = 0
setsockopt(8, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(8, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(8, SOL_TCP, TCP_KEEPINTVL, [30], 4) = 0
setsockopt(8, SOL_TCP, TCP_KEEPIDLE, [30], 4) = 0
write(8, "26:CONTENT_LENGTH\000204\0SCGI\0001\0,<?"..., 234) = 234
read(8, 0x400029d000, 4096)             = -1 EAGAIN (Resource temporarily unavailable)
futex(0x7cd708, FUTEX_WAIT_PRIVATE, 0, NULL) = 0
epoll_pwait(5, [], 128, 0, NULL, 0)     = 0
epoll_pwait(5, [{EPOLLOUT, {u32=2544840056, u64=281473226583416}}], 128, 29999, NULL, 0) = 1
getsockopt(8, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
getpeername(8, {sa_family=AF_INET, sin_port=htons(5000), sin_addr=inet_addr("127.0.0.1")}, [112->16]) = 0
futex(0x4000046548, FUTEX_WAKE_PRIVATE, 1) = 1
getsockname(8, {sa_family=AF_INET, sin_port=htons(40940), sin_addr=inet_addr("127.0.0.1")}, [112->16]) = 0
setsockopt(8, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(8, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
setsockopt(8, SOL_TCP, TCP_KEEPINTVL, [30], 4) = 0
setsockopt(8, SOL_TCP, TCP_KEEPIDLE, [30], 4) = 0
write(8, "26:CONTENT_LENGTH\000201\0SCGI\0001\0,<?"..., 231) = 231
read(8, 0x40002a2000, 4096)             = -1 EAGAIN (Resource temporarily unavailable)
read(8, "Status: 200 OK\r\nContent-Type: te"..., 4096) = 203
futex(0x4000046548, FUTEX_WAKE_PRIVATE, 1) = 1
epoll_ctl(5, EPOLL_CTL_DEL, 8, 0x4000263bf8) = 0
close(8)                                = 0

Both rtorrent/rutorrent work just fine during that time, even though rutorrent is a bit slow to respond.

zimmertr commented 3 years ago

I recently emailed the maintainer of this repo and part of his response contained the following:

I actually haven't used the rtorrent exporter in a few years now and was tempted to archive the project since it's languished and folks are adding big PRs that I can't actually verify. Apologies that I can't be more helpful.

Might be worth forking with your changes.