Ad Widget

Collapse

Example shell script monitoring Apache cpu & memory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tberton
    Junior Member
    Zabbix Certified Specialist
    • Jan 2008
    • 15

    #1

    Example shell script monitoring Apache cpu & memory

    Here's an example script for monitoring Apache processes, output cpu and memory usage.

    Code:
    #!/bin/sh
    PROCESSORS=`grep processor /proc/cpuinfo | wc -l`
    APACHE_PID=`cat /var/run/apache2.pid`
    PS_OUTPUT=`ps ho pcpu,pmem --ppid ${APACHE_PID} --pid ${APACHE_PID} | sed -e 's/[[:space:]]//' -e 's/[[:space:]]\+/,/g'`
    CPU=0
    MEMORY=0
    for LINE in $PS_OUTPUT
    do
            PROCESS_CPU=`echo "${LINE}" | cut -f 1 -d ','`
            PROCESS_MEMORY=`echo "${LINE}" | cut -f 2 -d ','`
            CPU=`echo |awk "{print ${PROCESS_CPU} + ${CPU}}"`
            MEMORY=`echo |awk "{print ${PROCESS_MEMORY} + ${MEMORY}}"`
    done
    
    CPU=`echo | awk "{print ${CPU}/${PROCESSORS}}"`
    echo "${CPU},${MEMORY}"
    Feel free to comment or make suggestions...
  • jeenam
    Member
    • Oct 2007
    • 43

    #2
    How about worker mode apache

    This will calculate the number of processes for prefork apache. How about a script to monitor threads for httpd.worker?

    Comment

    • dolorres
      Junior Member
      • Mar 2009
      • 1

      #3
      why so specific?

      I made a generic UserParameter to calculate cpu and memory usage

      here is for %cpu (the first argument will be the process you need info about)
      UserParameter=proc.pcpu[*],ps -C $1 -o pcpu= | awk '{cpu+=$$1}; END {print cpu}'

      try it with zabbix_get -s mytesthost -k proc.pcpu[httpd]

      and for memory, it is in Kb
      UserParameter=proc.rssmem[*],ps -C $1 -o rss= | awk '{mem+=$$1}; END {print mem}'

      as for apache stats, apache status page could be used, i saw a post somewhere about it
      Last edited by dolorres; 01-04-2009, 07:48.

      Comment

      Working...