We have PRTG Probe Server and most of time CPU usage hits to more than %90 thanks to that service. Is there any way restart to service automatically when CPU usage hit to %90?
Restart service automatically if service is using >%90 cpu
Votes:
0
3 Replies
Votes:
0
Hello Erol,
- Use the probe's existing Probe Health sensor
- Set a limit in channel that monitor's probe service's cpu load so that the sensor goes to error when surpassing 90%.
- For restarting the service you can use "ServiceRestart" executable from here with an Execute Program Notification.
(Of course you could as well use a script of your own as well for restarting the service.)
Kind regards,
Erhard
Created on Jun 18, 2019 8:48:44 AM by
Erhard Mikulik [Paessler Support]
Last change on Jun 18, 2019 12:19:29 PM by
Erhard Mikulik [Paessler Support]
Votes:
0
Hello Erhard,
Thank you for your suggestion. I want to use script if it is possible. I wrote simple PowerShell script but it is not working. I am using JobTrigger not sure is it true or not. Just want to restart automatically. Do you have advice? Also, how can I use "ServiceRestart" Should I just start to exe, can you give little bit more information? Thank you, Here is my source code :
$peridiocallyChecks = { # Check if logging source is available, if not add it if (!(Get-EventLog -Source "CPU supervision" -LogNameApplication)){ New-EventLog -LogName Application -Source "CPU supervision" } $cpuUsage = [double] (Get-Counter '\Processor(_Total)\% Processor Time' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue) if ($cpuUsage -gt 80) { Write-EventLog -LogName "Application" -Source "CPU supervision" -EntryType Information -EventId 1 -Message "CPU usage is $cpuUsage. Going to stop service" Stop-Service "PRTG Probe Service" # Some cooldown time for the service to shutdown Start-Sleep -Seconds 10 Start-Service "PRTG Probe Service" Write-EventLog -LogName "Application" -Source "CPU supervision" -EntryType Information -EventId 1 -Message "Restarted service" } Get-EventLog -Source "CPU supervision" -LogName Application } # Trigger every hour $trigger = New-JobTrigger -Once -At "17/05/2019 0am" -RepetitionInterval (New-TimeSpan -Hour 12) - RepetitionDuration ([TimeSpan]::MaxValue) Register-ScheduledJob -Name "CPUCheck" -Trigger $trigger -Scriptblock $peridiocallyCheck
Created on Jun 18, 2019 12:11:09 PM
Last change on Jun 18, 2019 1:28:13 PM by
Erhard Mikulik [Paessler Support]
Votes:
0
Hi Erol,
Ok, so the script actually does everything, checking the load and then trying to do the restart. I would recommend to simply use the existing "Probe Health" sensor as it already checks for the probe service's cpu consumption and reduce the script only to the portion that restarts the service. Does the code portion for restarting the service work by itself when running it manually? If not, maybe some coding forum is better suited for helping you out or you use the aforementioned executable alternatively.
Kind regards,
Erhard
Add comment