Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fivetime opened this issue Mar 3, 2021 · 6 comments

Comments

@fivetime
Copy link

fivetime commented Mar 3, 2021

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

@samhocevar
Copy link
Owner

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

@fivetime
Copy link
Author

fivetime commented Mar 5, 2021

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

@fivetime
Copy link
Author

fivetime commented Mar 6, 2021

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
Copy link
Author

fivetime commented Mar 6, 2021

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
Copy link
Author

fivetime commented Mar 6, 2021

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.

@lyda
Copy link

lyda commented May 30, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants