What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Restart service automatically if service is using >%90 cpu

Votes:

0

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?

automatically prtg restart

Created on Jun 17, 2019 1:10:31 PM



3 Replies

Votes:

0

Hello Erol,

  1. Use the probe's existing Probe Health sensor
  2. Set a limit in channel that monitor's probe service's cpu load so that the sensor goes to error when surpassing 90%.
  3. 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

Created on Jun 19, 2019 11:36:55 AM by  Erhard Mikulik [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.