Example of Zabbix monitoring Apache_status status

Source: Internet
Author: User
Tags curl touch

1. Add the following in the client's httpd.conf

sudo vim/alidata/server/httpd/conf/httpd.conf
<Location/server-status>
SetHandler Server-status
Allow from 127.0.0.1
Order Deny,allow
Deny from all
</Location>
Extendedstatus on
If you have a rewrite rule, you need to add a clause to the. htaccess, as follows:

Rewritecond%{request_uri}!server-status need to be written before index.php
sudo vim/alidata/www/jds.jince.com/.htaccess
# thinkphp Rewrite rules
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewritecond%{request_uri}!server-status
Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]
</IfModule>
#禁止显示目录列表
Options-indexes
2, Reload Apache configuration
Check Uptime and restart Apache

SUDO/ETC/INIT.D/HTTPD configtest after no error
SUDO/ETC/INIT.D/HTTPD Graceful
You can use the Curl 127.0.0.1/server-status test
3, create directories and scripts on the Zabbix-agent

sudo mkdir/etc/zabbix/scripts
sudo vim/etc/zabbix/scripts/check_apache.sh
Put check_apache.sh into the/etc/zabbix/scripts of the client

#! /bin/bash
#
# Name:zapache
#
# Checks Apache activity.
#
# Author:alejandro Michavila
# Modified for scoreboard Values:murat Koc, murat@profelis.com.tr
# Modified for using also as external Script:murat Koc, murat@profelis.com.tr
# Modified for outputting usage or Zbx_notsupported:alejandro Michavila
# Modified to does cacheing for performance, dmitry.frolov@gmail.com
#
# version:1.5
#

Zapachever= "1.5"
Rval=0
Value= ""
cache_seconds= "30"
["$TMPDIR"] | | Tmpdir=/tmp
function usage ()
{
echo "Zapache version: $zapachever"
echo "Usage:"
echo "$ [<url>] Totalaccesses-check total accesses."
echo "$ [<url>] Totalkbytes-check total Kbytes."
echo "$ [<url>] cpuload-check CPU load."
echo "$ [<url>] Uptime-check Uptime."
echo "$ [<url>] Reqpersec-check requests per second."
echo "$ [<url>] Bytespersec-check Bytes per second."
echo "$ [<url>] Bytesperreq-check Bytes per request."
echo "$ [<url>] Busyworkers-check busy workers."
echo "$ [<url>] idleworkers-check idle workers."
echo "$ [<url>] Version-version of this script."
echo "$ [<url>] Ping-check if Apache is up."
echo "$ [<url>] Waitingforconnection-check waiting for Connection processess."
echo "$ [<url>] Startingup-check starting up processess."
echo "$ [<url>] Readingrequest-check Reading Request processess."
echo "$ [<url>] Sendingreply-check sending Reply processess."
echo "$ [<url>] Keepalive-check KeepAlive processess."
echo "$ [<url>] Dnslookup-check dnslookup processess."
echo "$ [<url>] Closingconnection-check Closing Connection processess."
echo "$ [<url>] Logging-check Logging processess."
echo "$ [<url>] Gracefullyfinishing-check gracefully finishing processess."
echo "$ [<url>] Idlecleanupofworker-check Idle Cleanup of Worker processess."
echo "$ [<url>] Openslotwithnocurrentprocess-check Open slots with No current Process."
}

########
# Main #
########

if [[$# = 1]];then
#Agent Mode
Status_url= "Http://localhost/server-status?auto"
Case_value= "$"
elif [[$# = 2]];then
#External Script Mode
Status_url= "$"
Case "$STATUS _url" in
http://*|https://*);;
* status_url= "http://$STATUS _url/server-status?auto";;
Esac
Case_value= "$"
Else
#No Parameter
Usage
Exit 0
Fi

Case "$CASE _value" in
' Version ')
echo "$zapachever"
Exit 0;;
Esac

cache_prefix= "Zapache-${status_url//[^a-za-z0-9_-]/_}"
cache= "$TMPDIR/$cache _prefix.cache"
cache_ timestamp_check= "$TMPDIR/$cache _prefix.ts"
# This assumes the touch from Coreutils
touch-d "@$ (' Date +%s '-($cache _ seconds-1)) "" $cache _timestamp_check

If ["$cache"-ot "$cache _timestamp_check"] then
    curl= "' which curl '"
    I f ["$curl"]; Then
        fetch_url_cmd= "$curl--insecure--silent--location"
     Else
        wget= "' which wget '"
         if ["$wget"]; Then
            fetch_url_cmd= "$wget-- No-check-certificate--quiet-o-"
        else
             echo "zbx_notsupported"
             exit 1
        fi
    fi

$fetch _url_cmd "$STATUS _url" > "$cache"
Rval=$?
If [$rval!= 0]; Then
echo "Zbx_notsupported"
Exit 1
Fi
Fi

Case "$CASE _value" in
' Ping ')
If [!-S "$cache"-o "$cache"-ot "$cache _timestamp_check"]; Then
echo "0"
Else
echo "1"
Fi
Exit 0;;
Esac

if! [-S "$cache"]; Then
echo "Zbx_notsupported"
Exit 1
Fi

Case "$CASE _value" in
' Totalaccesses ')
Value= "' awk '/^total accesses:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Totalkbytes ')
Value= "' awk '/^total kbytes:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Cpuload ')
Value= "' awk '/^cpuload:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Uptime ')
Value= "' awk '/^uptime:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Reqpersec ')
Value= "' awk '/^reqpersec:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Bytespersec ')
Value= "' awk '/^bytespersec:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Bytesperreq ')
Value= "' awk '/^bytesperreq:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Busyworkers ')
Value= "' awk '/^busyworkers:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Idleworkers ')
Value= "' awk '/^idleworkers:/ {print $} ' < \ ' $cache \ ' "'
Rval=$?;;
' Waitingforconnection ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' _ '}; {Print NF-1} ' "
Rval=$?;;
' Startingup ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' S '}; {Print NF-1} ' "
Rval=$?;;
' Readingrequest ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' R '}; {Print NF-1} ' "
Rval=$?;;
' Sendingreply ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' W '}; {Print NF-1} ' "
Rval=$?;;
' KeepAlive ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' K '}; {Print NF-1} ' "
Rval=$?;;
' DNSLookup ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' D '}; {Print NF-1} ' "
Rval=$?;;
' Closingconnection ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' C '}; {Print NF-1} ' "
Rval=$?;;
' Logging ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' L '}; {Print NF-1} ' "
Rval=$?;;
' Gracefullyfinishing ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' G '}; {Print NF-1} ' "
Rval=$?;;
' Idlecleanupofworker ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = ' I '}; {Print NF-1} ' "
Rval=$?;;
' Openslotwithnocurrentprocess ')
Value= "' awk '/^scoreboard:/ {print $} ' < \ ' $cache \ ' | awk ' BEGIN {FS = '. '}; {Print NF-1} ' "
Rval=$?;;
*)
Usage
Exit 1;;
Esac

If ["$rval"-eq 0-a-Z "$value"]; Then
Rval=1
Fi

If ["$rval"-ne 0]; Then
echo "Zbx_notsupported"
Fi

echo "$value"
Exit $rval

#
# End Zapache
To execute permissions on a script

sudo chmod +x/etc/zabbix/scripts/check_apache.sh
4. Put userparameter_apache.conf into the/etc/zabbix/zabbix_agentd.d of the client, as follows:

sudo vim/etc/zabbix/zabbix_agentd.d/userparameter_apache.conf
Userparameter=zapache[*],/bin/bash/etc/zabbix/scripts/check_apache.sh $
5. Restart Agentd

/etc/init.d/zabbix-agent restart
$ sudo/etc/init.d/zabbix-agent Restart
Test

sudo sh/etc/zabbix/scripts/check_apache.sh cpuload
2.06619
Modify Permissions

sudo chown zabbix.zabbix/tmp/zapache-http___localhost_server-status_auto.*
The documents are as follows:

-rw-r--r--1 Zabbix Zabbix 440 Mar 14:29 Zapache-http___localhost_server-status_auto.cache
-rw-r--r--1 Zabbix Zabbix 0 Mar 14:29 zapache-http___localhost_server-status_auto.ts
6. Create the template App Apache service template in Zabbix server, add items, and associate the Apache host that needs to be monitored




The Apache service monitoring can be referenced as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.