Page 1 of 1

Script to email total bytes and reset counters

Posted: Wed May 05, 2021 3:42 pm
by kd2pm2
Anyone come up with a script that can be scheduled to go off on the 1st of the month and email me the total bytes uploaded and downloaded on the WAN port and then reset the counters?

I want to see how much data I am using with my Comcast ISP and make sure that I am staying within the limits before they start to throttle or charge me extra.

I can get the reset counters part scripted pretty easily, just not sure on how to capture the bytes and pack them into an email, if thats even possible.

Re: Script to email total bytes and reset counters

Posted: Wed May 12, 2021 8:45 pm
by jonah1810
EDIT: my script will work only on places where bytes returns "tx/rx" value. a much simpler script was shared by rextended below.

As luck would have it i made a similar script for pulling total bytes from simple queue im sure you can adapt it.
{
	:local bite
	:local ubyte
	:lotal dbyte
	:local tot
	/queue simple
	:set bite [get [find target=("10.100." . $x . "." . $i . "/32")] bytes]
	:set ubyte [:pick "$bite" 0 [find "$bite" "/" -1]]
	  :set dbyte [:pick "$bite" ([find "$bite" "/" -1]+1) 40]
	  :set tot [:tonum ($ubyte + $dbyte)]
	  }
you would need to change the first 2 lines to be for a ethernet port instead of a simple queue target. but the principle is the same. afterwards create an empty file and then set the file contents as your $tot variable. you should then be able to email that

Re: Script to email total bytes and reset counters

Posted: Wed May 12, 2021 11:19 pm
by rextended
Do not lost time with previous script.

The result is not like bytes on queue where you obtain single value like "654321/123456",
but you can obtain single value for tx and rx distinctly on format "4 567 890" bytes

assuming ether1 is your WAN:
:global totalTX [/interface ethernet get ether1 tx-bytes]
:global totalRX [/interface ethernet get ether1 rx-bytes]
to read the values

and the forum is full of example to how send mail.

Re: Script to email total bytes and reset counters

Posted: Thu May 13, 2021 1:30 am
by jonah1810
Good catch extended! I wasn't by a computer where i could check if it worked. i just assumed it was the same as other places where "bytes" is a stat. My apologies for the misinformation.

Re: Script to email total bytes and reset counters

Posted: Thu May 13, 2021 3:09 am
by rextended
Good catch extended! I wasn't by a computer where i could check if it worked. i just assumed it was the same as other places where "bytes" is a stat. My apologies for the misinformation.
no no, not apologize, thanks to try to help!