ActiveXperts Network Monitor
Monitor servers, workstations, devices and applications in your network

Quicklinks


Monitor CPU Usage on Linux using an SSH Secure Shell Script

The following script can be used in ActiveXperts Network Monitor to check CPU usage on a remote LINUX machine:

#################################################################################
# ActiveXperts Network Monitor  - shell script checks
# © 1999-2008, 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/ssh/
#################################################################################

#!/bin/sh

# Macro definitiions
Max=$1
TotalPS=0

# Validate number of arguments
if [ $# -ne 1 ] ; then
  echo "UNCERTAIN: Invalid number of arguments - Usage: cpu_load "
  exit 1
fi

# Check the CPU usage
for PSID in `ps uax | awk '{if ($3 > 0) {print $3} }'`
do
  TotalPS=`echo "$TotalPS $PSID" | awk '{ print $1 + $2 }'`
done

# Check if the CPU usage good or bad is
st=$(echo "$TotalPS < $Max" | bc)
if [ $st -eq 1 ] ; then
  echo "SUCCESS: CPU usage is [$TotalPS%], maximum allowed=[$1%] DATA:$TotalPS%   $loaddelta"
else
  echo "ERROR: CPU usage is [$TotalPS%], maximum allowed=[$1%] DATA:$TotalPS%   $loaddelta"
fi