Check Apache Slow Requests - Nagios Plugin

Check Apache Slow Requests - Nagios Plugin

Nagios плагин для выявления медленных запросов Apache.

Прост в установке и использовании.

Nagios плагин для выявления медленных запросов Apache.

Прост в установке и использовании.

				#!/bin/bash # # USAGE: # /check_slowrequests.sh <normal_hit_is_below_sec> <access_log> <warn> <crit> # Nagios script to get the value of slow Apache hits from access log which are executed longer then <normal_hit_is_below_sec> # # REQUIREMENTS: # Make sure that the last word of each request in your access_log is "The time taken to serve the request, in seconds." # Here is my LogFormat in httpd.conf # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T" combined # # IMPORTANT: # Probably, you may have to let nagios run this script as root or another user, which has read permission to apache access log # This is how the sudoers file looks in Debian or CentOS system: # nagios  ALL=(root) NOPASSWD:/usr/<lib or lib64>/nagios/plugins/check_slowrequests.sh # # do not forget to comment 'Defaults    requiretty' in sudoers conf if necessary # # ABOUT: # Version 1.0 # 100% GPL ~ Feel free to modif! # created by McArt <hello@mcart.ru> https://www.mcart.ru/ OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3 function usage() {    echo "Usage: ./check_slowrequests.sh <normal_hit_is_below_sec> <access_log> <warn> <crit>" } function check_arg() {    # make sure you supplied all 3 arguments    if [ $# -ne 4 ]; then       usage       exit $OK    fi } function check_accesslog() {    # make sure access log exist and we have permission to read it    if ! [ -f "$accessLog" ]; then       echo "UNKNOWN: $accessLog does not exist or user \"`whoami`\" has no permission to it"       nbsp;exit $UNKNOWN    fi } function check_warn_vs_crit() {    # make sure CRIT is larger than WARN    if [ $WARN -ge $CRIT ];then       echo "UNKNOWN: WARN value may not be greater than or equal the CRIT value"       exit $UNKNOWN    fi } function init() {    check_arg $*    check_accesslog    check_warn_vs_crit } function get_slowrequests() {    # gets nuber of slowrequests and stores it in $valueofSlowrequests    # and make sure we get a numeric output    valueofSlowrequests=0    while read line    do       currenthitTime=`echo $line | awk '{ print $NF }'`       if [ "$currenthitTime" -ge "$normalHitIsBelowSec" ];then          valueofSlowrequests=$((valueofSlowrequests+1))       fi    done < $accessLog    case "$valueofSlowrequests" in    [0-9]* )       echo "do nothing" > /dev/null       ;;    * )       echo "UNKNOWN: Could not get slowrequests from: $accessLog"       exit $UNKNOWN       ;;    esac } function check_slowrequests() {    # checks slowrequests and replies according to $CRIT and $WARN    if [ $valueofSlowrequests -lt $WARN ];then       echo "OK: Only $valueofSlowrequests hit(s) executed longer than $normalHitIsBelowSec second(s)"       exit $OK    elif [ $valueofSlowrequests -lt $CRIT ];then       echo "WARNING: $valueofSlowrequests hit(s) executed longer than $normalHitIsBelowSec second(s)"       exit $WARNING    elif [ $valueofSlowrequests -ge $CRIT ];then       echo "CRITICAL: $valueofSlowrequests hit(s) executed longer than $normalHitIsBelowSec second(s)"       exit $CRITICAL    else       echo "UNKNOWN: This error message should never occur, if it does happen anyway, get a new cup of coffee and fix the code :)"       exit $UNKNOWN    fi    } # -- Main -- # normalHitIsBelowSec=$1 accessLog=$2 WARN=$3 CRIT=$4 init $* get_slowrequests check_slowrequests exit 0
			
Файлы:
check_slowrequests.sh (3.08 КБ)

Похожие записи в блоге

Все статьи