Centos CPU / Process monitoring via Cacti

cacticentos

Ive looked about but not found as yet any templates for graphing the amount of cpu and memory being used by each process on a Linux device (centos).
Has anyone come across any ?

Thanks,

Best Answer

In cacti you can try using snmpwalk but applying it to your task would be fully your work.

But you can try installing zabbix and use this script to monitor CPU-usage for several most CPU-consuming processes which consumption exceeds some threshold

#!/bin/bash
#####################################################
# topcpu
# returns names of most CPU time consuming processes
# as reported by 'top'
#####################################################
# 05-07-2010 by Jerry Lenk
# 02-11-2010 by Frater (rewrite in bash)
#
# Use at your own risk!
#####################################################

# Add lsof to /etc/sudoers (as root) with the following command
##########################
#     echo zabbix ALL = NOPASSWD: `which lsof` >> /etc/sudoers

# Add to zabbix_agentd.conf
###########################
#     echo 'UserParameter=system.topcpu[*],/usr/local/sbin/topcpu $1' >>/etc/zabbix/zabbix_agentd.conf

# Restart Zabbix
################
#     /etc/init.d/zabbix-agent restart

# Constants
nodata='.'
deflimit=4
use_lsof=1
GREP='grep --color=never -a'
DEBUG=0

# set limit to 1st argument (given from zabbix), or deflimit if not specified
lim=`echo "$1" | tr -cd '0-9.'`
[ -z "${lim}" ] && lim=${deflimit}

toptail="`top -b -d1 -n2 | ${GREP} -A1 '^ *PID ' | tail -n1`"
cpu=`echo "${toptail}"  | awk '{print $9}'`

[ ${DEBUG} -ne 0 ] && echo "Debug: \$1=$1  limit=$lim  cpu=$cpu"

if expr ${cpu} \<= ${lim} >/dev/null ; then
  echo "${nodata}"
else

  # get PID & FULL process name (it may contain more info)
  pid2=`echo "${toptail}" | awk '{print $1}'`
  procname="`ps --pid ${pid2} -o args --no-headers 2>/dev/null`"

  if [ -z "${procname}" ] ; then
    # process is not running anymore... I might as well return nothing and quit
    echo "${nodata}"
  else

    user=`echo "${toptail}" | awk '{print $2}'`
    # return CPU usage, process owner and process name
    echo "${cpu}%   ${user}:${procname}"

    if [ ${use_lsof} -ne 0 ] ; then
      # calculate the limit when it should execute lsof
      lim=$(( 2 * ${lim} + 5 ))
      [ ${lim} -gt 50 ] && lim=50
      # Run an lsof, but exclude log files, apache modules and several runtime/library directories
      expr ${cpu} \> ${lim} >/dev/null && sudo lsof -p ${pid2} -S -b -w -n -Fftn0 | ${GREP} -v '^fDEL' | ${GREP} 'tREG'  | ${GREP} -o '/.*' | tr -d '\0' | ${GREP} -vE '(log$|\.mo$|^/var/lib|^/lib|^/var/run|^/tmp|^/usr/|^/var/log/)' | sort -u | head -n7
    fi
  fi
fi

Comments, zabbix usage instructions in zabbix and modifications of this script you can find here (https://www.zabbix.com/forum/showthread.php?t=17874).