rinetd icon indicating copy to clipboard operation
rinetd copied to clipboard

Can you add a Http or Socket query interface for total upstream and downstream traffic?

Open fivetime opened this issue 3 years ago • 6 comments

Can you add a Http or Socket query interface for total upstream and downstream traffic?

fivetime avatar Mar 03 '21 16:03 fivetime

Sure, why not! Can you give examples of software you know that do similar things, so that I don’t reinvent the wheel?

samhocevar avatar Mar 05 '21 16:03 samhocevar

I don't find any similar software, my requirement is to query all the upstream and downstream traffic of rinetd through API.

fivetime avatar Mar 05 '21 18:03 fivetime

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}

fivetime avatar Mar 06 '21 00:03 fivetime

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}

fivetime avatar Mar 06 '21 01:03 fivetime

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.

fivetime avatar Mar 06 '21 01:03 fivetime

You might want to look at exposing this information via a prometheus metrics page. There's a C library for this.

lyda avatar May 30 '21 11:05 lyda