cpu.sh - ssh script by ActiveXperts Software
cpu.sh checks CPU usage on a host.
Use cpu.sh directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select cpu.sh. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
cpu.sh script code
################################################################################# # ActiveXperts Network Monitor - Shell script checks # © 1999-2015, ActiveXperts Software B.V. # # For more information about ActiveXperts Network Monitor and SSH, please # visit the online ActiveXperts Network Monitor Shell Script Guidelines at: # http://www.activexperts.com/support/network-monitor/online/linux/ ################################################################################# # Script # cpu.sh # Description # Checks CPU usage on the computer. # Declare Parameters # 1) nMaxCpuUsage (int) - minimum allowed CPU usage (%) # Usage # cpu.sh <nMaxCpuUsage> # Sample # cpu.sh 70 ################################################################################# #!/bin/sh # Macro definitions nMaxCpuUsage=$1 nCpuLoadPercentage=0 # Validate number of arguments if [ $# -ne 1 ] ; then echo "UNCERTAIN: Invalid number of arguments - Usage: cpu <nMaxCpuUsage>" exit 1 fi # Check the CPU usage for PSID in `ps uax | awk '{if ($3 > 0) {print $3} }'` do nCpuLoadPercentage=`echo "$nCpuLoadPercentage $PSID" | awk '{ print $1 + $2 }'` done # Check if the CPU usage good or bad is st=$(echo "$nCpuLoadPercentage < $nMaxCpuUsage" | bc) if [ $st -eq 1 ] ; then echo "SUCCESS: CPU usage is [$nCpuLoadPercentage%], minimum allowed=[$1%] DATA:$nCpuLoadPercentage" else echo "ERROR: CPU usage is [$nCpuLoadPercentage%], minimum allowed=[$1%] DATA:$nCpuLoadPercentage" fi