Mengintip Jumlah Apache Process dan auto mail Alert

kadang kala server bertingkah yang tak wajar dan pastinya kaget kan kalau tiba-tiba ga bisa akses sama sekali server atau bisa pun lambat banget…, hmmn salah satu box server saya mengalami hal tersebut ternyata ada 300 lebih process apache.  nah gimana cara ngintip jumlah process yang sedang jalan sebelum mencapai batas kemapuan server.

untuk menampilkan apache process anda bisa menggunakan perintah sebagai berikut :

#ps aux | grep http | grep -v “\(root\|grep\)” | wc -l

atau dengan

#ps axo ‘pid user size cmd’ | grep http | grep -v “\(root\|grep\)”

peritah tersebut akan menampilkan 4 kolom yaitu PID, Username, Ukuran, Perintah yang dijalankan

nah untuk memonitor apache process dan aotomatis memberikan alert ketika process mendekati limit yang ditentukan anda bisa menggunakan ini

#!/bin/bash

THRESHOLD=100
ADDRTO="admin@mysite.com"
SUBJECT="Apache Process Check"
LOCKFILE="/tmp/apache_process_check.lock"
LOGFILE="/var/log/apache_processes.log"

NUMHTTPD=`ps aux | grep http | grep -v "\(root\|grep\)" | wc -l`
echo "`date +'%Y-%m-%d %H:%M:%S %Z'` - ${NUMHTTPD}" >> ${LOGFILE}

if [[ ${NUMHTTPD} -gt ${THRESHOLD} ]]; then
        if [ ! -e "${LOCKFILE}" ]; then
                echo "The number of currently running httpd threads is ${NUMHTTPD}." | mail -s "${SUBJECT} - Above Threshold" ${ADDRTO}
                touch ${LOCKFILE}
        fi
else
        if [ -e "${LOCKFILE}" ]; then
                rm -f "${LOCKFILE}"
                echo "The number of currently running httpd threads is ${NUMHTTPD}." | mail -s "${SUBJECT} - Below Threshold" ${ADDRTO}
        fi
fi

Jalankan sebagai cron dalam 5 atau 10 menit.

Referensi : http://www.thingy-ma-jig.co.uk/blog/25-10-2007/the-price-of-sucess-too-many-users

Butuh Hosting ? Hosting Surabaya Directadmin Hosting

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

  1. Bash Script Monitoring sederhana dengan mail Alert

Leave a Reply

Your email address will not be published. Required fields are marked *


*

What is 15 + 10 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)