furaihan.simple-mikrotik-sc.../cpu-monitoring

32 lines
1.2 KiB
Text
Raw Normal View History

local cpuarray
local isInternetConnected
local rebootIfHigh false
set cpuarray ([/system resource get value-name=cpu-load])
2020-09-01 13:16:20 +07:00
#Change the value below to change the number of CPU load sample to average
local cpusample 20
for i from=1 to=[$cpusample -1] do={
delay 950ms;
set cpuarray ([/system resource get value-name=cpu-load],$cpuarray)
}
put $cpuarray
local totalcpuarray 0
2020-09-01 13:16:20 +07:00
#calculating the average
foreach value in=$cpuarray do={ set totalcpuarray ($totalcpuarray + $value)}
:put $totalcpuarray
local avgcpu ($totalcpuarray / [:len $cpuarray])
if ($avgcpu > 65) do={
2020-08-30 17:27:12 +07:00
:global ConnectionAvailable
$ConnectionAvailable
if ($ConnectionAvailable=true) do={
global CHATID
global BOTID
local sendToTelegram ("Mikrotik ".[/system resource get value-name=board-name]."(".[/sy id get value-name=name].") :%0A\E2\9A\A0 \E2\9A\A0 <b>CPU Load Report</b>%0AAverage: $avgcpu%25%0ACPU Samples: $cpusample%0AReboot if CPU sample show highload: $rebootIfHigh")
2020-08-29 00:52:46 +07:00
/tool fetch url="https://api.telegram.org/bot$BOTID/sendMessage\?chat_id=$CHATID&text=$sendToTelegram&parse_mode=html" keep-result=no;
} else={
log warning message="Cannot send message to telegram. is internet connected?"
}
if ($rebootIfHigh = true) do={/system reboot}
} else={
nothing
}