Page 1 of 1

Dominant Process check in Linux

Posted: Sun Feb 24, 2013 5:09 am
by oakyuz
Hi

We are using Host Monitor v9.40 on Windows 2008 R2 (x64).

I would like to define Dominant Process tests for my Linux systems. As you know, this test is implemented for Windows systems currently in HM, probably leaving this kind of things to users who are able to write shell scripts in Linux. Is there anybody who has and can share scripts which can check Dominant Process::CPU and Dominant Process::Memory in Linux systems?

Thanks.

Posted: Mon Feb 25, 2013 12:59 pm
by KS-Soft
Dominant Process::CPU

Code: Select all

#!/bin/sh

if [ $# -ge 2 ]
then
  OS=`uname`
  case $OS in
    AIX) PSLIST='ps -Ao comm,pcpu';;
    Linux) PSLIST='ps h -eo ucmd,pcpu';;
    FreeBSD) PSLIST='ps -axco command,%cpu';;
    NetBSD)  PSLIST='ps -axco command,%cpu';;
    OpenBSD) PSLIST='ps -axco command,%cpu';;
    SunOS) PSLIST='ps -eo fname,pcpu';;
    *) echo 'ScriptRes:Unknown:script is not designed for '$OS
       exit;;
  esac
  $PSLIST | awk 'BEGIN { maxusage=0; prog="" } {if ($2>maxusage) {maxusage=$2; prog=$1 }} \
    END { if (maxusage<='$1') {printf("ScriptRes:Ok:%2.2f:%s %%\n",maxusage,prog)} else {printf("ScriptRes:Bad:%2.2f:%s %%\n",maxusage,prog)} }'
else
  echo "ScriptRes:Unknown:not enough parameters specified"
fi
Dominant Process::Memory

Code: Select all

#!/bin/sh

if [ $# -ge 2 ]
then
  OS=`uname`
  case $OS in
    AIX) PSLIST='ps -Ao comm,pmem';;
    Linux) PSLIST='ps h -eo ucmd,pmem';;
    FreeBSD) PSLIST='ps -axco command,%mem';;
    NetBSD)  PSLIST='ps -axco command,%mem';;
    OpenBSD) PSLIST='ps -axco command,%mem';;
    SunOS) PSLIST='ps -eo fname,pmem';;
    *) echo 'ScriptRes:Unknown:script is not designed for '$OS
       exit;;
  esac
  $PSLIST | awk 'BEGIN { maxusage=0; prog="" } {if ($2>maxusage) {maxusage=$2; prog=$1 }} \
    END { if (maxusage<='$1') {printf("ScriptRes:Ok:%2.2f:%s %%\n",maxusage,prog)} else {printf("ScriptRes:Bad:%2.2f:%s %%\n",maxusage,prog)} }'
else
  echo "ScriptRes:Unknown:not enough parameters specified"
fi
Regards
Alex

Posted: Tue Feb 26, 2013 1:16 am
by oakyuz
Hi Alex

These scripts meet my need. Thank you very much for quick and problem-solving assistance.

Regards,
Oguzhan

Posted: Tue Feb 26, 2013 8:01 am
by KS-Soft
You are welcome :)

Regards
Alex