CPU效能監控發送即時告警,DeviceAverageLoadThreshold設定為CPU平均用量超過40%,送出Slack告警通知
/system scheduler
add interval=5m name=CPUOverloadCheck on-event=":local ScriptName \"CPUOverloadCheck\";\r\
\n:local ScriptRunning [system script job find where script=\$ScriptName];\r\
\n:if (\$ScriptRunning) do={\r\
\n :log info \"The script \$ScriptName cannot be run, the script is already running (Change the NumberOfMeasurements to redu\
ce the script)\";\r\
\n} else={\r\
\n /system script run \$ScriptName;\r\
\n}" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup
/system script
add dont-require-permissions=yes name=CPUOverloadCheck owner=wallacelocal policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":local DeviceAverageLoadThreshold 40;\r\
\n:local NumberOfMeasurements 5;\r\
\n:local Time [/system clock get time];\r\
\n:local Date [/system clock get date];\r\
\n:local Load 0;\r\
\n:local Message \"\";\r\
\n:for Measurement from=1 to=\$NumberOfMeasurements do={\r\
\n :local CPULoad [/system resource get cpu-load];\r\
\n :set Load (\$Load + \$CPULoad);\r\
\n :set Message (\$Message . [:tostr \$CPULoad] . \"% \");\r\
\n :delay 5s;\r\
\n}\r\
\n:local AverageCPULoad (\$Load / \$NumberOfMeasurements);\r\
\nif (\$AverageCPULoad > \$DeviceAverageLoadThreshold) do={\r\
\n :log warning \"Average CPU load = \$AverageCPULoad%\";\r\
\n :set Message \"CPU utilization exceeded \$DeviceAverageLoadThreshold% threshold. Result of \$NumberOfMeasurements times C\
PU load measurements: \$Message\";\r\
\n :local MessageText \"CPU Average Overload \$AverageCPULoad%. \$Message\";\r\
\n\t/tool fetch mode=https url=\"https://hooks.slack.com/services/AAAZ0S4ZZ/B5EJGGGER/3427P7uGAGAbiYC\" http-method=p\
ost http-data=\"payload={\\\"text\\\": \\\"\$MessageText\\\",\\\"channel\\\":\\\"circuit-alert\\\",\\\"username\\\":\\\"\$[/sy\
stem identity get name]\\\",\\\"icon_url\\\":\\\"https://spy-family.net/assets/img/special/episode11/01.png\\\"}\"\r\
\n}"
0 回應:
張貼留言