Script to fetch interface counter data

Can anyone suggest a few quick lines for a script that resembles this:

$OUT = interface ether2 out octets counter
$IN = interface ether2 in octets counter

/tool fetch mode=http address=server.tld “src-path=poller.php?hostname=routeros&out=$OUT&in=$IN”

I’m not familiar with routeros scripting, but with a small example of how to do this, I would have what I need to complete my project.


Regards,

Try this:

:local iface "WAN"
:local ifacebytes [/interface get $iface bytes]
:local ifacepackets [/interface get $iface packets]

:put ($iface . " bytes in: " . [:pick $ifacebytes 0 [:find $ifacebytes "/"]])
:put ($iface . " bytes out: " . [:pick $ifacebytes ([:find $ifacebytes "/"] + 1) [:len $ifacebytes]])

:put ($iface . " packets in: " . [:pick $ifacepackets 0 [:find $ifacepackets "/"]])
:put ($iface . " packets out: " . [:pick $ifacepackets ([:find $ifacepackets "/"] + 1) [:len $ifacepackets]])