Contact Info

ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom PowerShell checks.

Most of the built-in checks have a PowerShell equivalent, implemented as a PowerShell (.ps1) script file. Out-of-the-box, each PowerShell script monitors the same items as the built-in check. Feel free to modify the script.

To add a new PowerShell-based CPU monitoring check, do the following:

To customize the above monitoring check, click on the 'Edit button' next to the 'Script File' selection box. Notepad will be launched. You can now make changes to the PowerShell script.

Powershell Cpu check

Cpu.ps1 script source code

#################################################################################
# ActiveXperts Network Monitor PowerShell script, (c) ActiveXperts Software B.V.
# For more information about ActiveXperts Network Monitor, visit the ActiveXperts 
# Network Monitor web site at https://www.activexperts.com
#################################################################################
# Script
#     Cpu.ps1
# Description:
#     This script checks the cpu usage of the define processor on the define computer
# Parameters:
#     1) strComputer (string)  - Hostname or IP address of the computer you want to monitor
#     2) strCpu (string)  - Either 'cpu0' or 'cpu2' or ...
#     3) numMaxCpuUsage (number)   - Limit, in %
#     4) strAltCredentials (string, optional) - Alternate credentials
# Usage:
#     .\Cpu.ps1 '<computer>' '<CPU[0|1|2|...]>' '%' '<alt-credentials> | <>'
# Sample:
#     .\Cpu.ps1 'localhost' 'cpu0' 50
#     .\Cpu.ps1 'remotehost' 'cpu0' 50 'remotehost'
#################################################################################

# Parameters
param
  (
    [string]$strComputer,
    [string]$strCpu,
    [int]$numMaxCpuUsage,
    [string]$strAltCredentials
  )

cls

# Check paramters input
if ( ([string]$strComputer -eq "") -or 
     ([string]$strCpu -eq "") -or 
     ([int]$numMaxCpuUsage -eq "") 
   )
{
  $res = "UNCERTAIN: Invalid number of parameters - Usage: .\CPU.ps1 <computername> <CPU[0|1|2|...]> <Max_Cpu_Percent> [alt-credentials]"
  echo $res
  exit
}

# Create object
if ( [string]$strAltCredentials -eq "" )
{
  $colCpu = Get-WmiObject -ComputerName $strComputer -Class Win32_Processor
}
else
{
  $objNmCredentials = new-object -comobject ActiveXperts.NMServerCredentials
  $strLogin = $objNmCredentials.GetLogin( $strAltCredentials )
  $strPassword = $objNmCredentials.GetPassword( $strAltCredentials )
  $strPasswordSecure = ConvertTo-SecureString -string $strPassword -AsPlainText -Force
  $objCredentials = new-object -typename System.Management.Automation.PSCredential $strLogin, $strPasswordSecure
  $colCpu = Get-WmiObject -ComputerName $strComputer -Class Win32_Processor -Credential $objCredentials 
}
  
  
#################################################################################
# THE SCRIPT ITSELF
#################################################################################
 
if ( $colCpu -eq $null )
{
  $res = "UNCERTAIN: Unable to connect. Please make sure that PowerShell and WMI are both installed on the monitered system. Also check your credentials"
  echo $res
  exit
}

foreach( $objCpu in $colCpu ) 
{
  if ( $objCpu.DeviceID -eq $strCpu )
  {
    if ( $objCpu.LoadPercentage -gt $numMaxCpuUsage )
    {
      $res = "ERROR: CPU usage=[" + $objCpu.LoadPercentage + "%], maximum allowed=[" + $numMaxCpuUsage + "%] DATA:" + $objCpu.LoadPercentage
    }
    else
    {
      $res = "SUCCESS: CPU usage=[" + $objCpu.LoadPercentage + "%], maximum allowed=[" + $numMaxCpuUsage + "%] DATA:" + $objCpu.LoadPercentage
    }
    
    echo $res
    exit
  }
}

$res = "UNCERTAIN: Unable to query CPU [" + $strCpu + "] on computer [" + $strComputer + "]"
echo $res
exit