Created
February 9, 2012 10:40
-
-
Save Surgo/1779194 to your computer and use it in GitHub Desktop.
Monitoring Apache2.x from zabbix etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export HOME=/etc/zabbix/externalscripts/ | |
result=0 | |
if [ "$1" == "CPULoadUser" ] ; then | |
load=`/usr/sbin/apache2ctl status | /bin/grep "CPU load" | /usr/bin/awk '{print $3}'` | |
result=${load:1} | |
elif [ "$1" == "CPULoadSystem" ] ; then | |
load=`/usr/sbin/apache2ctl status | /bin/grep "CPU load" | /usr/bin/awk '{print $4}'` | |
result=${load:1} | |
elif [ "$1" == "CPULoadPercentage" ] ; then | |
load=`/usr/sbin/apache2ctl status | /bin/grep "CPU load" | /usr/bin/awk '{print $8}'` | |
result=${load:0:${#load}-1} | |
elif [ "$1" == "RequestPerSecond" ] ; then | |
result=`/usr/sbin/apache2ctl status | /bin/grep "requests/sec" | /usr/bin/awk '{print $1}'` | |
elif [ "$1" == "BytePerSecond" ] ; then | |
result=`/usr/sbin/apache2ctl status | /bin/grep "B/second" | /usr/bin/awk '{multiplier=1;if (substr($5,1,1)!="B") multiplier*=1024; if (substr($5,1,1)=="M") multiplier*=1024; if (substr($5,1,1)=="G") multiplier*=1024*1024; print $4*multiplier}'` | |
elif [ "$1" == "BytePerRequest" ] ; then | |
result=`/usr/sbin/apache2ctl status | /bin/grep "B/request" | /usr/bin/awk '{multiplier=1;if (substr($8,1,1)!="B") multiplier*=1024; if (substr($8,1,1)=="M") multiplier*=1024; if (substr($8,1,1)=="G") multiplier*=1024*1024; print $7*multiplier}'` | |
elif [ "$1" == "BusyWorker" ] ; then | |
result=`/usr/sbin/apache2ctl status | /bin/grep "requests currently being processed," | /usr/bin/awk '{print $1}'` | |
elif [ "$1" == "IdleWorker" ] ; then | |
result=`/usr/sbin/apache2ctl status | /bin/grep "idle workers" | /usr/bin/awk '{print $6}'` | |
elif [ "$1" == "WaitingForConnection" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "WaitingForConnection" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "StartingUp" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "StartingUp" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "ReadingRequest" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "ReadingRequest" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "SendingReply" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "SendingReply" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "Keepalive" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "Keepalive" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "DNSLookup" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "DNSLookup" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "ClosingConnection" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "ClosingConnection" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "Logging" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "Logging" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "GracefullyFinishing" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "GracefullyFinishing" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "IdleCleanup" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "IdleCleanup" | /usr/bin/awk '{print $3}'` | |
elif [ "$1" == "OpenSlot" ] ; then | |
result=`/usr/sbin/apache2ctl status | /usr/bin/awk -f /etc/zabbix/externalscripts/check_worker.awk | /bin/grep "OpenSlot" | /usr/bin/awk '{print $3}'` | |
fi | |
echo $result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/zabbix/externalscripts/check_worker.awk | |
BEGIN { | |
Mode="start"; | |
Key="_SRWKDCLGI."; | |
Description[0]="WaitingForConnection"; | |
Description[1]="StartingUp"; | |
Description[2]="ReadingRequest"; | |
Description[3]="SendingReply"; | |
Description[4]="Keepalive"; | |
Description[5]="DNSLookup"; | |
Description[6]="ClosingConnection"; | |
Description[7]="Logging"; | |
Description[8]="GracefullyFinishing"; | |
Description[9]="IdleCleanup"; | |
Description[10]="OpenSlot"; | |
for (Position = 0 ; Position <= 10 ; Position++) | |
Value[Position] = 0; | |
} | |
{ | |
if (Mode=="start") { | |
if (/ idle workers/) | |
Mode="Processing"; | |
} | |
else if (Mode=="Processing") { | |
if (/Scoreboard Key:/) | |
Mode="End"; | |
else | |
for (Post = 0; Post <= length;Post++) { | |
Slot=index(Key, substr($0, Post, 1)); | |
if (Slot > 0) | |
Value[Slot-1]+=1; | |
} | |
} | |
} | |
END { | |
for ( Position = 0 ; Position <= 10 ; Position++) | |
print Description[Position] " : " Value[Position]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment