The counters are preserved even on reboot, but (obviously) the intermediate values between two updates are lost if the device is rebooted.
example code
/ip firewall layer7-protocol
{
:if ( ([:len [find where name="ether1-total-upload"]] = 0) or ([:len [find where name="ether1-total-download"]] = 0) ) do={
remove [find where name~"^ether1-total-(upload|download)\$"]
add name=ether1-total-upload regexp=0
add name=ether1-total-download regexp=0
}
:local tupid [find where name="ether1-total-upload"]
:local tdnid [find where name="ether1-total-download"]
set $tupid regex=([:tonum [get $tupid regex]] + [/interface get ether1 tx-byte])
set $tdnid regex=([:tonum [get $tdnid regex]] + [/interface get ether1 rx-byte])
/interface reset-counters ether1
}
reset stored counters code
/ip firewall layer7-protocol
{
remove [find where name~"^ether1-total-(upload|download)\$"]
add name=ether1-total-upload regexp=0
add name=ether1-total-download regexp=0
}
read current values code
/ip firewall layer7-protocol
{
:if ( ([:len [find where name="ether1-total-upload"]] = 0) or ([:len [find where name="ether1-total-download"]] = 0) ) do={
remove [find where name~"^ether1-total-(upload|download)\$"]
add name=ether1-total-upload regexp=0
add name=ether1-total-download regexp=0
}
:local tupid [find where name="ether1-total-upload"]
:local tdnid [find where name="ether1-total-download"]
:local currUpload [:tonum [get $tupid regex]]
:local currDownload [:tonum [get $tdnid regex]]
:put "Current Upload is $currUpload and current Download is $currDownload"
}