Hello,
I'm using a script to capture the TX and RX bytes for all my router interfaces (ports and VLANs), but can't seem to get it to work. I got the idea of the following script from the forum mentioned below and then tried adjusting it to my needs: viewtopic.php?t=37708
I get the concept, its pretty simple.."Get the respective information for many interfaces as you can, but once you reach the variable limit, flush it down in a text file. Then create another text file and continue where you left off." So not really sure what I'm missing here, perhaps mixing global with local variables is causing the issue?
:global time ([/system clock get time]);
:global hour [:pick $time 0 2];
:global min [:pick $time 3 5];
:global sec [:pick $time 6 8];
:global stamp ($hour . "_" . $min . "_" . $sec);
:global id ([/system identity get name]);
:global numports 100;
:global name " ";
:global rx " ";
:global tx " ";
:global line "Interface Name, Avg RX Byte, Avg TX Byte";
:global line2 "";
:global filenumber 1;
:global buffer;
:foreach INTERFACE in=[/interface find] do={
# record te parameters
:set name [/interface get $INTERFACE name];
:set rx [/interface get $INTERFACE rx-byte];
:set tx [/interface get $INTERFACE tx-byte];
# assemble them into a line
:set line ($line . "\n" . $name . "," . $rx . "," . $tx);
# add the buffer length and the string length
:local newLength ([:len $buffer] + [:len $line]);
# check if the buffer would now be larger than the variable size limit
:if($newLength > 4095) do={
# it is. write out the current line buffer (without the latest line)
# first construct the file name
:local fileName ($id . "_BW_" . $stamp . "_" . $filenumber . ".txt");
# create the file as it doesn't exist yet
/file print file=$fileName;
delay 2s;
# write the buffer into it
/file set $fileName contents="$buffer";
# increase the file number
:set $fileNumber ($fileNumber + 1);
# reset the line buffer to just the last line that hasn't been written to a file yet
:set buffer ($name . "," . $rx . "," . $tx);
} else= {
# variable size limit would not be exceeded. add line to buffer
:set $buffer ($buffer . $line);
}
}
# write out the last buffer
:local fileName ($id . "_BW_" . $stamp . "_" . $filenumber . ".txt");
/file print file=$fileName;
/file set $fileName contents="$buffer";