Cheers Everyone,
Since I did not find anything usefull up to now, I dug a bit into the topic. I wanted to know how much my private network pulled and pushed from and into the WWW. I wanted to know that for “today”, “this week”, this “month” and “total”. The Fritzbox resets with every restart I think and the binding resets randomly. At least that’s what I thought. It’s not random at all and I can use it to get an accurate measure. The binding uses the unsinged integer datatype for the bytes and that means that the range is at an end at 4GB. So every 4GB it resets to zero. Therefore you need a working persistence for it to get going. I use a MariaDB via JDBC. The general persistence strategy is everyUpdate. Please check the tutorial to set it up if you don’t already have.
That’s my config:
Items
Number fboxWanTotalBytesSent "WAN total bytes sent [JS(bytes.js):%s]" {fritzboxtr064="wanTotalBytesSent"} Number fboxWanTotalBytesReceived "WAN total bytes received [JS(bytes.js):%s]" {fritzboxtr064="wanTotalBytesReceived"} Number fboxBytesSentToday "WAN bytes sent today [JS(bytes.js):%s]" Number fboxBytesReceivedToday "WAN bytes received today [JS(bytes.js):%s]" Number fboxBytesSentWeek "WAN bytes sent this week [JS(bytes.js):%s]" Number fboxBytesReceivedWeek "WAN bytes received this week [JS(bytes.js):%s]" Number fboxBytesSentMonth "WAN bytes sent this month [JS(bytes.js):%s]" Number fboxBytesReceivedMonth "WAN bytes received this month [JS(bytes.js):%s]" Number fboxBytesSentTotal "WAN bytes sent total [JS(bytes.js):%s]" Number fboxBytesReceivedTotal "WAN bytes received total [JS(bytes.js):%s]"
You need the Javascript Transform addon and create a bytes.js in the transform directory:
(function formatBytes(a){
var d = 2;
e=[“B”,“KB”,“MB”,“GB”,“TB”,“PB”];
if(0==a)return"0 “+e[0];
var c=1e3;
var f=Math.floor(Math.log(a)/Math.log©);
return parseFloat((a/Math.pow(c,f)).toFixed(d))+” "+e[f];
})(input)
Sitemap
Text item=fboxBytesSentToday Text item=fboxBytesReceivedToday Text item=fboxBytesSentWeek Text item=fboxBytesReceivedWeek Text item=fboxBytesSentMonth Text item=fboxBytesReceivedMonth Text item=fboxBytesSentTotal Text item=fboxBytesReceivedTotal
rules
rule "FB Total Bytes Send" when Item fboxWanTotalBytesSent changed then var pState = fboxWanTotalBytesSent.previousState(true,"jdbc").state var cState = fboxWanTotalBytesSent.state var long previousState = Long.parseLong(pState.toString(), 10) as Number var long currentState = Long.parseLong(cState.toString(), 10) as Number var long max = Long.parseLong("4294967295", 10) as Number if(previousState > currentState) { currentState = max - previousState + currentState }else{ currentState = currentState - previousState } pState = fboxBytesSentToday.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesSentToday, previousState + currentState) pState = fboxBytesSentWeek.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesSentWeek, previousState + currentState) pState = fboxBytesSentMonth.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesSentMonth, previousState + currentState) pState = fboxBytesSentTotal.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesSentTotal, previousState + currentState) end rule "FB Total Bytes Received" when Item fboxWanTotalBytesReceived changed then var pState = fboxWanTotalBytesReceived.previousState(true,"jdbc").state var cState = fboxWanTotalBytesReceived.state var long previousState = Long.parseLong(pState.toString(), 10) as Number var long currentState = Long.parseLong(cState.toString(), 10) as Number var long max = Long.parseLong("4294967295", 10) as Number if(previousState > currentState) { currentState = max - previousState + currentState }else{ currentState = currentState - previousState } pState = fboxBytesReceivedToday.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesReceivedToday, previousState + currentState) pState = fboxBytesReceivedWeek.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesReceivedWeek, previousState + currentState) pState = fboxBytesReceivedMonth.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesReceivedMonth, previousState + currentState) pState = fboxBytesReceivedTotal.state previousState = Long.parseLong(pState.toString(), 10) as Number postUpdate(fboxBytesReceivedTotal, previousState + currentState) end rule "FB reset daily counter" when Time cron "0 0 0 * * ?" then postUpdate(fboxBytesReceivedToday, 0) postUpdate(fboxBytesSentToday, 0) end rule "FB reset weekly counter" when Time cron "0 0 0 ? * MON" then postUpdate(fboxBytesReceivedWeek, 0) postUpdate(fboxBytesSentWeek, 0) end rule "FB reset monthly counter" when Time cron "0 0 0 1 * ?" then postUpdate(fboxBytesReceivedMonth, 0) postUpdate(fboxBytesSentMonth, 0) end
Hope this helps