rinetd
rinetd copied to clipboard
Can you add a Http or Socket query interface for total upstream and downstream traffic?
Can you add a Http or Socket query interface for total upstream and downstream traffic?
Sure, why not! Can you give examples of software you know that do similar things, so that I don’t reinvent the wheel?
I don't find any similar software, my requirement is to query all the upstream and downstream traffic of rinetd through API.
For example: rinetd.conf configure a line of manager addr and port, and then rinetd starts udp monitoring to receive the query command. After receiving the query command, the upstream and downlink traffic data is sent to the requestor by udp.
rinetd.conf
manager 127.0.0.1:8000
command protocol:
Send udp request: stat
Respond to Json: stat: {"up": 11370, "down": 12345}
Python client example code
import socket
cli = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
cli.sendto('stat', '127.0.0.1:8000')
print(cli.recv(8000)) # You'll receive 'stat: {"up": 11370, "down": 12345}'
Linux socat program example
echo "stat" | socat - udp4-datagram:127.0.0.1:8000
The console will output stat: {"up": 11370, "down": 12345}
It is recommended to use udp protocol to provide traffic query. If you use http api, then you need to import the http framework, the program is too large, it will affect performance.
You might want to look at exposing this information via a prometheus metrics page. There's a C library for this.