Solved [help] How to reset the statistics counters for a network interface?

How can I reset/clear the statistics counters (total traffic) of a network interface without restarting it? I want to reset the traffic counter daily on a ppp(8) tun(4) interface, so I can see if I'm above or below my proposed daily average (WWAN, highspeed volume is limited). pppctl /var/run/pppctl.tun0 clear physical does not reset the total traffic counter.

Thx in advance.
 
I think running ifconfig ifX down followed by ifconfig ifX up should work but i guess you don't want to do that. I know it's not an exact solution but how about setting up a cron job that runs at midnight and saves the counters somewhere (say /var/run/ifX_base.recv / /var/run/ifX_base.send) and writing a little script to calculate the deltas in relation to the current values?
 
I think running ifconfig ifX down followed by ifconfig ifX up should work but i guess you don't want to do that.
I already did before I asked -- it does not reset the total counter; I didn't expect that & think it's reasonable not to do so.
I know it's not an exact solution but how about setting up a cron job that runs at midnight and saves the counters somewhere (say /var/run/ifX_base.recv / /var/run/ifX_base.send) and writing a little script to calculate the deltas in relation to the current values?
Yes, but my wish was to avoid that... I'd like to have something like ifconfig tun0 clear stats
 
I'm using vnstat(1) to keep track of my internet usage on specific card. But I don't think it works for you. You only want to reset ppp and tun traffic on a specific card, not the whole shebang. Anyway, this is my little script, maybe it works for somebody. Alerts: it's very unprofessional and noob-oriented. It's too descriptive! But I like it. It was one of my first attempts to write script in shell.


Bash:
#!/bin/sh

echo -n "4: stat ... "
read foobar
vnstat -y

echo -n "3: remove ... "
read foobar
vnstat --remove --force -i bge0
service vnstat stop
rm -fr /var/lib/vnstat/vnstat.db
service vnstat start

echo -n "2: stat ... "
read foobar
vnstat -y

echo -n "1: restart ... "
read foobar
service vnstat restart

echo -n "0: stat ... "
read foobar
vnstat -y
 
Can you provide details? AFAIK vnstat supports tun(4) interfaces.
The problem with my solution: it resets the whole network interface. mjollnir needs something specific. I don't think it is possible to partially reset the traffic with vnstat. Am I wrong?
[EDIT] For example I think he doesn't want to reset its LAN traffic (internal network), let's say the traffic between two PC which one of them share same NIC for internet usage.
 
Thx to @all for your valuable hints! Clearly, it's up to the monitor to solve this issue. After a quick RTFM vnstat(1) I think it can provide me with a per-day/week/month view of traffic on any interface. If not, I'll use one of the many network monitors. Oh I want to have such as a desktop widget...
 
  • Like
Reactions: a6h
The problem with my solution: it resets the whole network interface. mjollnir needs something specific. I don't think it is possible to partially reset the traffic with vnstat. Am I wrong?
[EDIT] For example I think he doesn't want to reset its LAN traffic (internal network), let's say the traffic between two PC which one of them share same NIC for internet usage.

As I understood, the problem here is to reset the tun interface to obtain the daily network traffic volume, otherwise there is only a total. vnstat provides these daily statistics, retrievable anytime during the day, down to a 5 minute resolution. Furthermore, one of vnstat features is: "months can be configured to follow billing period "
 
Back
Top