пятница, 8 марта 2019 г.

A script to calculate Average CPU Load - MikroTik

A script to calculate Average CPU Load - MikroTik








# 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 5

# 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")

Комментариев нет:

Отправить комментарий

Примечание. Отправлять комментарии могут только участники этого блога.