vergoh / vnstat

vnStat - a network traffic monitor for Linux and BSD
GNU General Public License v2.0
1.45k stars 123 forks source link

Send interface traffic result periodically to external server (URL) to avoid writing in the device #261

Closed jeorlie closed 3 months ago

jeorlie commented 5 months ago

I would like to request a feature please. Is it possible to send the traffic stats to external server via http request?

I have an EdgeRouter X where I install vnstat but I read that frequent write will increase the wear and tear of the storage which is bad. Is there a way we can send the statistics periodically to a server via http request with the following params?

download (Bytes) upload (Bytes) timestamp interface device_name

The daemon will look for a config file in /etc/vnstat/url.conf which contains following config format

external_url = http://public_ip_address/custom_url  # the public url where http post data will be send
device_name = switch_router_001_example  # user define name of the device
timeout = 60  # send stats every 60 secs

It will send the data to the external URL and wait for a basic "ok" response otherwise it will try to send again after 5 or 10 secs and if it is still a false it will stop sending and try to send again on the next schedule.

If it received an "ok" response after sending to the external URL it will then clear the statistics back to zero then record again the traffic which be sent on the next schedule.

The benefits is that if we have this option it will be increase lifespan of the storage since the logs are sent in the external server.

I'm learning C again and will take me too long to understand the code of vnstat for me to add modification. Bear with me. Thank you.

hulxv commented 5 months ago

Hey friend! I'm not the maintainer of vnstat. But, Before about 2 years, I built a tool to do something similar to what you want. you can take a look here.

vergoh commented 4 months ago

Would vnStat in that scenario be used on the router for anything else than sending the data, as in, the database wouldn't even be active? If that's the case then I suspect this sort of functionality should be achievable with not that many lines of Python for example (assuming it's supported). Using vnStat would feel like the wrong tool for doing data sending without local storage especially since vnStat doesn't currently have any networking capabilites.

The other question: what would be there on the other end receiving that data? How would you parse it, store it and present it?

I'm not familiar with the capabilities of EdgeRouter X but one thing that may be worth checking is if it support NFS mount. You could have the vnStat database on an NFS share from some other system and that way there wouldn't be any local disk wear.