I am running 6 scripts, each running on its own schedule. I noticed many times they are not running on schedule. When I manually run one of these for a test, I get this error:
system is busy (12)
This does not happen every time the script is run. Is scripting only able to run one thread at a time? Any ideas?
My scripts are monitoring latency and packet loss then recording by logging error if they cross certain thresholds. The first 3 scripts are running flood-ping of 1 packet to different IP addresses every 10 seconds (I call these “probe” scripts). The other 3 analyze the statistics gathered by the first 3 every 4 minutes (I call these “analyze” scripts).
No matter if you open one or more winbox / ssh /telnet.
The system (also on 6.17) can do only one flood-ping at the same time.
If you try to launch multiple flood, system is busy (12) occour.
system is busy (12) = function already used on another session
You can see “system is busy (12)” only on CLI (console / telnet / SSH) , because on winbox simply not work, and on script on default do not leave any log.
# Variables - ipsla1
:global ipsla1;
:local name ipsla1;
:local response -1;
:local target 8.8.8.8;
:local pingSize 1200;
#Variables derived from stored settings
:local currentIndex
:local livesKept
:local currentStat
#Ping target and gather latest statistic
/tool flood-ping $target count=1 size=$pingSize do=\
{
:set response $"avg-rtt";
};
#Get stored Index
:set currentIndex [/ip proxy access get [find comment="Current Index - $name"] dst-port];
:set currentStat [/ip proxy access find (method="$name" and dst-host="$currentIndex")];
:set livesKept [/ip proxy access get [find comment="Current Index - $name"] dst-host];
#Check if no response
:if ($response = 0) do=\
{
/ip proxy access set $currentStat dst-port=9999 dst-address=$target;
} \
else=\
{
/ip proxy access set $currentStat dst-port=$response dst-address=$target;
};
#Increment index to next (set back to start if at end)
:if ($currentIndex>=$livesKept) do=\
{
:set currentIndex 1;
} else=\
{
:set currentIndex ($currentIndex+1);
};
/ip proxy access set [/ip proxy access find comment="Current Index - $name"] dst-port=$currentIndex
Here is the “analyze” script:
#User set variables
#Variable for storing up/down status of ipsla (if this variable is edited, make sure to edit checks at the end of this script)
:global ipsla1
##Name (must match the name used in createStorageVariables script
:local ipslaName ipsla1;
#Number of previous statistics to calculate loss/latency averages on
:local checkNumStats 100;
#Threshold for when latency will cause monitor to be down status
:local latencyThreshold 500;
#Threshold for when packet loss will cause monitor to be down status (this variable is a percentage)
:local lossThreshold 15;
#Variables derived from stored settings
:local livesKept [/ip proxy access get [find comment="Current Index - $ipslaName"] dst-host];
:local currentStatLatency;
:local currentIndex [/ip proxy access get [find comment="Current Index - $ipslaName"] dst-port];
#Decrease current index by one since current index is pending update but currentindex-1 is the most recently updated
:if ($currentIndex=1) do=\
{
:set currentIndex ($livesKept);
} else=\
{
:set currentIndex ($currentIndex-1);
};
:local startIndex $currentIndex;
:local totalLatency 0;
:local avgLatency;
:local percentLoss;
:local received 0;
:local lost 0;
:local polledIp;
#Go through loop as many times as necessary to gather each statistic that will be calucalted upon
:for i from=1 to=($checkNumStats) do=\
{
#### Store latency of current statistic
:set currentStatLatency [/ip proxy access get [find (method="$ipslaName" and dst-host="$currentIndex")] dst-port];
#### Check if value is flagged with 9999 (ping timed out)
:if ($currentStatLatency=9999) do={:set lost ($lost+1);} else=\
{
######## If not timed out, add latency to total
# :put $currentStatLatency
:set received ($received+1);
:set totalLatency ($totalLatency+$currentStatLatency);
};
####Check if index is at the end of the statistic list, reset to beginning if necessary
:if ($currentIndex=1) do=\
{
:set currentIndex ($livesKept);
} else=\
{
:set currentIndex ($currentIndex-1);
};
};
:set polledIp [/ip proxy access get [find (method="$ipslaName" and dst-host="$currentIndex")] dst-address];
:set percentLoss (($lost*100) / (($received+$lost)));
:if ($received=0) do=\
{
:set avgLatency 0;
} else=\
{
:set avgLatency ($totalLatency/$received);
};
#Log statistics
:log info "Ran $ipslaName analyze script, checked last $checkNumStats poll(s) on $polledIp"
:log info "Average Latency: $avgLatency";
:log info "Percent loss: $percentLoss (lost: $lost, Received $received)";
#Add whatever checks on latency and percent loss down here along with actions
:if (($percentLoss>$lossThreshold) || ($avgLatency>$latencyThreshold)) do=\
{
:if (($ipsla1)!="down") do=\
{
:set ipsla1 "down"
:log error ("$ipslaName is down");
:log error ("Packet Loss: $percentLoss Average Latency: $avgLatency");
};
} else=\
{
:if (($ipsla1)="down") do=\
{
:log error ("$ipslaName is back up");
};
:set ipsla1 "up";
};