OpenWrt Forum Archive

Topic: RX Bytes reset its self?

The content of this topic has been archived on 5 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello, I was wondering if anyone might know anything about a problem ive just noticed with the downstream byte count resetting to 0. I wrote myself a little perl CGI script which would show me my bandwidth usages on my router, however when I checked it tonight I noticed that the RX Bytes (from ifconfig output) had been reset to zero, the previous downstream byte count was about 3gigs and the uptime had been about 11days, I hadn't reboot the router either.

Is the RX Bytes supposed to reset to 0 on an interface once it reaches a certain amount? I dont think it changed IP and theres no log of it talking to my ISP or anything like that for a new IP.

Can anyone help shed some light on this please?

(The error is definately the RX bytes resetting and not in the perl script since I checked with ifconfig).

Thanks

Funny, I did the same the day before yesterday (using php, not perl) smile
But no, I haven't seen a reset so far. But maybe that's because I automatically reboot the router after 24h, so I never get to exceeding 3gigs.

Has TX been resetted too (if not would be very strange...)?

That's normal because the size of the variables for those counters only allow up to 4GB. I have high traffic systems that reset several times a day. Normally it doesn't reallly matter though because what you do in your program is check if the "current" value is less than the "previous" value and if it is add 4G to it then subtract the  "previous" value from that which will give you an accurate count of bytes from the previous check to the current check. This assumes you check more often than your counters roll over.

Thanks void main, that helps me a bit,  I was just confused why it had reset. Ill go about adding something to help log it better as per your suggestion through a cron tab so that it doesnt get missed and re-gerenerate normall through the cgi when the stats page gets a hit. I shouldn't have too much problems though as 4gigs down over 11 days isnt too high usage.

Netzfetz, my TX bytes had not reset because it was only around about 1gig.

Hhhmm, while on the subject of cgi stats scripts, have either of you found a way to find out what the current link utilisation is on vlan1?

I know its possibly to read the stats output for TC which will give a break down per class but has anyone found a way for current downstream utilisation?

Hiya again smile, its slightly like that.

You see down at the bottom where it says "Inbound Current: 31.55 k"

Thats what i'm trying to find out where I can read that value, Ive searched around /proc/net and also in ifconfig but I dont seem to be able to find the reading anywhere.

Also Im not using graphs, Im just using purely textual output through my perl script which generates a web page and logs bandwidth to a file in the ram (which should only generate 1line a month all going well (hence no graph as im not really interested in when the bandwidth was used, just how much). The "current" reading would be handy to add though.

Here's how I get inbound for vlan1:

snmpget -v 1 -c public 192.168.1.1 .1.3.6.1.2.1.2.2.1.10.6

To make sure vlan1 is index 6 you can check your interface indexes with:

snmpwalk -v 1 -c public 192.168.1.1 .1.3.6.1.2.1.2.2.1.2

If you wanted it get it directly without using snmp you could:

# ifconfig vlan1 | grep "RX bytes" | cut -f2 -d: | cut -f1 -d' '

Or

# grep "vlan1:" /proc/net/dev | cut -f2 -d: | cut -f1 -d' '

ifconfig vlan1 | grep "RX bytes" | cut -f2 -d: | cut -f1 -d' '

I don't think im being too clear on what I want . . .

That is the code I currently use in order to get how many bytes have been transfered overall (plus modifications for when it resets to zero). But I'm trying to see how much of my link is being used at any one point. For instance my full link capacity is 2Megabits per second downstream, so say for instance I'm doing a download and its only going at 1Megabit /s I'm wanting to find out from the router what it thinks the current link utilisation is.

For instance if PC 1 is downloading at 1Megabit /s and PC 2 is downloading at 0.5Megabits /s then the current utilisation is 1.5Mbps, Im trying to find out where I can obtain this number from the router in order to put it onto my stats page.

Someone told me it might not be possible unless I used something like IPTraf, but that program doesnt look too friendly for writing a CGI script in order to query it, I was also hoping to do it without adding anything extra.

You are perfectly clear on what you want and the places I mention are where you get the information. You can't just grab the RX bytes once though, you have to grab it twice and figure the difference over the amount of time between the two checks. That's exactly how the graph I mentioned before does it. It polls every 5 minutes and figures the difference. xMb/s is by definition 2 variables ("x amount of data"/"y time period"). It sounds like your code is nearly complete. You just have to calculate the difference between the two RX byte captures and the time between the two captures and that will give you the rate. Divide by the number of seconds to get you the bytes/sec. Iptraf would do the same thing to calculate data rate. It might do the calculation every 1 second (or less) though, but there is no reason you can't calculate that often if you want to be able to see what your data rate is over a very small time period. That's completely up to you. There is no magical variable under /proc (that I am aware of) that shows current data rate. Mainly because there is no need for it.

Aaahh, of course. Yes that makes perfect sense and its quite easy to do smile. Thank you.

The discussion might have continued from here.