Restart MK if CPU load goes above 60%

As the title says, is there a quick way to do this?
I’m kinda new to MK scripting and couldn’t find a way by my self.

Thanks

I don’t think this is wise ideal. CPU load will be 100% at startup, sometimes it pops up to 100% for just a few seconds, sometimes it will be 100% when executing script. I think your router with this script will reboot very oftenly.
But if you really want to do that, here it is:

:if ([ /system resource get cpu-load ] >= 100 ) do={ /system reboot; }

You’re right, I didn’t think about that at all.
But still, is there a way to monitor CPU for a period of time and calculate the changes, if its usage is usually 80% for a period of time of 20 sec, reboot.

Any such thing?
Thanks

Please! This would be brilliant to overcome mikrotik bugs!
Currently im loosing customers because of a bug that causes my router to hit 100% and stay there.

This happens at undefined periods and MT has admitted there is a problem.

This doesn’t however help me.

If i could get a script that check usage over a period of time say 10 values, and if all values are 100% reboot!

Same issue with web-proxy. Sometimes simply crashes.

I always seem to get these outcomes with MT.

Solved!!!

Used someone elses code and modified it…

In sceduler create job that starts on start-up and runs at one second intervals…

Add code:

# Name : Average CPU Load
# Set up the scheduler to run this at a 1 second intervals (Sample Rate)
# Set info logs to echo to Terminal in System Logging

:local cpuload 0
:global cpuarray
:local arraylen 0
:local arraypos 0
:local arraytot 0
:global avgcpuload 0
:global highavgcpuload

# arraysize is the number of cpu-Load samples to keep
# Experiment with this value to incease or decrease the number of samples
# The greater the value the longer the time that the cpu-load average is calculated for.
:local arraysize 20

# Get cpu-load samples, limit cpuarray to array size
:set cpuload [/system resource get cpu-load]
:set cpuarray ( [:toarray $cpuload] + $cpuarray )
:set cpuarray [:pick $cpuarray 0 $arraysize]

# add up all values in array
:set arraypos 0
:set arraylen [:len $cpuarray]
:while ($arraypos < $arraylen) do={
:set arraytot ($arraytot + [:pick $cpuarray $arraypos] );
:set arraypos ($arraypos +1)}

# divide sum of array values by the number of values in cpuarray
:set avgcpuload ($arraytot / [:len $cpuarray])
:if ([:len $highavgcpuload] = 0) do={:set highavgcpuload $avgcpuload}
:if ([$highavgcpuload] < [$avgcpuload]) do={:set highavgcpuload $avgcpuload}

# Display results in Terminal window
:log info ("CPU Load Captures:")
:log info $cpuarray
:log info ("Array Total: $arraytot")
:log info ("Array size: $arraysize")
:log info ("CPU Load - Avg: $avgcpuload High: $highavgcpuload")

:if ($avgcpuload >= 100)  do={ /system reboot; }

This will monitor if usage stays 100% for over 20 seconds.
If so reboot!