0

I am running a small RPi server in a remote home and I have a simcard with very limited data usage. I would like to have a file that measures cumulatively month by month (starting, for example, from the 27th of the month) the data consumption (MB) for a specific interface. I have tried different tools such as sysstat and vnstat and sar, but I have not been able to produce a binary file with the simple information of how many MB were used from - let's say - feb 27th to mar 26th (which is when the carrier starts over my data plan). Every month the file should be overwritten. I am running Debian 11.

1 Answer 1

1

vnstat should be able to provide you what you need. You'll need to write some cron job that takes a snapshot of the last month. For instance:

0 0 1 * * vnstat -m > /tmp/network_`date "+\%Y_\%m"`.log 

This job will run the midnight at the 1st of every month, and write the data into a file named /tmp/network_<year>_<month>, for instance: /tmp/network_2021_11.

If for some reason vnstat doesn't work for you, the answers to this question show various way to check the total traffic on your network interfaces. If you're willing to make some effort, you could write some script that runs every month (again, using cron) that checks the traffic, and then substracts the value from the traffic of the previous month and saves the delta somewhere. Of course you'll need to need to also save the absolute total value, so the next month could make the same calculation.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.