1. 报错描述:
打开apache
的状态页面正常:
但是配置apache模板后,并给相应的远程主机添加apache的监控模板,发现监控项大部分都是不支持!!!
查看服务端的zabbix日志文件,发现报错,监控项显示不支持,如图:
回想一下,为了监控客户端上的apache
服务,我们在apache的配置文件中添加了一个apache状态的页面,然后使用已经定义好的模板来进行监控的,那么出问题了,那不是apache状态页面的问题就是zapache模板的问题。
而从第一张图,可以看到apache
状态页面是可以访问的,那就只可能是zapache的问题了。
2. 具体排错和解决过程
# 查看下apache监控脚本的为止
# 配置的时候放哪里,就去哪里找
[root@client ~]# ll /usr/local/bin/zapache
-rwxr-xr-x. 1 root root 6110 7月 4 15:18 /usr/local/bin/zapache
[root@client ~]# cat /usr/local/bin/zapache
#! /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 do cacheing for performance, dmitry.frolov@gmail.com
#
# Version: 1.5
#
zapachever="1.5"
rval=0
value=""
cache_seconds="60"
[ "$TMPDIR" ] || TMPDIR=/tmp
function usage()
{
echo "zapache version: $zapachever"
echo "usage:"
echo " $0 [<url>] TotalAccesses - Check total accesses."
echo " $0 [<url>] TotalKBytes - Check total KBytes."
echo " $0 [<url>] CPULoad - Check CPU load."
echo " $0 [<url>] Uptime - Check uptime."
echo " $0 [<url>] ReqPerSec - Check requests per second."
echo " $0 [<url>] BytesPerSec - Check Bytes per second."
echo " $0 [<url>] BytesPerReq - Check Bytes per request."
echo " $0 [<url>] BusyWorkers - Check busy workers."
echo " $0 [<url>] IdleWorkers - Check idle workers."
echo " $0 [<url>] version - Version of this script."
echo " $0 [<url>] ping - Check if Apache is up."
echo " $0 [<url>] WaitingForConnection - Check Waiting for Connection processess."
echo " $0 [<url>] StartingUp - Check Starting Up processess."
echo " $0 [<url>] ReadingRequest - Check Reading Request processess."
echo " $0 [<url>] SendingReply - Check Sending Reply processess."
echo " $0 [<url>] KeepAlive - Check KeepAlive Processess."
echo " $0 [<url>] DNSLookup - Check DNSLookup Processess."
echo " $0 [<url>] ClosingConnection - Check Closing Connection Processess."
echo " $0 [<url>] Logging - Check Logging Processess."
echo " $0 [<url>] GracefullyFinishing - Check Gracefully Finishing Processess."
echo " $0 [<url>] IdleCleanupOfWorker - Check Idle Cleanup of Worker Processess."
echo " $0 [<url>] OpenSlotWithNoCurrentProcess - Check Open Slots with No Current Process."
}
########
# Main #
########
if [[ $# == 1 ]];then
#Agent Mode
STATUS_URL="http://localhost/server-status?auto"
CASE_VALUE="$1"
elif [[ $# == 2 ]];then
#External Script Mode
STATUS_URL="$1"
case "$STATUS_URL" in
http://*|https://*) ;;
*) STATUS_URL="http://$STATUS_URL/server-status?auto";;
esac
CASE_VALUE="$2"
else
#No Parameter
usage
exit 0
fi
case "$CASE_VALUE" in
'version')
echo "$zapachever"
exit 0;;
esac
umask 077
# $UID is bash-specific
cache_prefix="zapache-$UID-${STATUS_URL//[^a-zA-Z0-9_-]/_}"
cache="$TMPDIR/$cache_prefix.cache"
cache_timestamp_check="$TMPDIR/$cache_prefix.ts"
# This assumes touch from coreutils
touch -d "@$((`date +%s` - ($cache_seconds - 1)))" "$cache_timestamp_check"
if [ "$cache" -ot "$cache_timestamp_check" ]; then
curl="`which curl`"
if [ "$curl" ]; then
fetch_url() { $curl --insecure --silent --location -H "Cache-Control: no-cache" "$@"; }
else
wget="`which wget`"
if [ "$wget" ]; then
fetch_url() { $wget --no-check-certificate --quiet --header "Cache-Control: no-cache" -O - "$@"; }
else
echo "ZBX_NOTSUPPORTED"
exit 1
fi
fi
fetch_url "$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 $3}' < \"$cache\"`"
rval=$?;;
'TotalKBytes')
value="`awk '/^Total kBytes:/ {print $3}' < \"$cache\"`"
rval=$?;;
'CPULoad')
value="`awk '/^CPULoad:/ {print $2}' < \"$cache\"`"
rval=$?;;
'Uptime')
value="`awk '/^Uptime:/ {print $2}' < \"$cache\"`"
rval=$?;;
'ReqPerSec')
value="`awk '/^ReqPerSec:/ {print $2}' < \"$cache\"`"
rval=$?;;
'BytesPerSec')
value="`awk '/^BytesPerSec:/ {print $2}' < \"$cache\"`"
rval=$?;;
'BytesPerReq')
value="`awk '/^BytesPerReq:/ {print $2}' < \"$cache\"`"
rval=$?;;
'BusyWorkers')
value="`awk '/^BusyWorkers:/ {print $2}' < \"$cache\"`"
rval=$?;;
'IdleWorkers')
value="`awk '/^IdleWorkers:/ {print $2}' < \"$cache\"`"
rval=$?;;
'WaitingForConnection')
value="`awk '/^Scoreboard:/ {print split($2,notused,"_")-1}' < \"$cache\"`"
rval=$?;;
'StartingUp')
value="`awk '/^Scoreboard:/ {print split($2,notused,"S")-1}' < \"$cache\"`"
rval=$?;;
'ReadingRequest')
value="`awk '/^Scoreboard:/ {print split($2,notused,"R")-1}' < \"$cache\"`"
rval=$?;;
'SendingReply')
value="`awk '/^Scoreboard:/ {print split($2,notused,"W")-1}' < \"$cache\"`"
rval=$?;;
'KeepAlive')
value="`awk '/^Scoreboard:/ {print split($2,notused,"K")-1}' < \"$cache\"`"
rval=$?;;
'DNSLookup')
value="`awk '/^Scoreboard:/ {print split($2,notused,"D")-1}' < \"$cache\"`"
rval=$?;;
'ClosingConnection')
value="`awk '/^Scoreboard:/ {print split($2,notused,"C")-1}' < \"$cache\"`"
rval=$?;;
'Logging')
value="`awk '/^Scoreboard:/ {print split($2,notused,"L")-1}' < \"$cache\"`"
rval=$?;;
'GracefullyFinishing')
value="`awk '/^Scoreboard:/ {print split($2,notused,"G")-1}' < \"$cache\"`"
rval=$?;;
'IdleCleanupOfWorker')
value="`awk '/^Scoreboard:/ {print split($2,notused,"I")-1}' < \"$cache\"`"
rval=$?;;
'OpenSlotWithNoCurrentProcess')
value="`awk '/^Scoreboard:/ {print split($2,notused,".")-1}' < \"$cache\"`"
rval=$?;;
*)
usage
exit 1;;
esac
if [ "$rval" -eq 0 -a -z "$value" ]; then
case "$CASE_VALUE" in
# Theese metrics are output only if non-zero
'CPULoad' | 'ReqPerSec' | 'BytesPerSec' | 'BytesPerReq')
value=0
;;
*)
rval=1
;;
esac
fi
if [ "$rval" -ne 0 ]; then
echo "ZBX_NOTSUPPORTED"
fi
echo "$value"
exit $rval
#
# end zapache
# STATUS_URL="http://localhost/server-status?auto"
# 看到脚本中有这么一行,尝试客户端上curl下
# 可以看到,根本就获取不了信息,那肯定有问题啊!!!
[root@client ~]# curl http://localhost/server-status?auto
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /server-status
on this server.</p>
</body></html>
# 既然都是获取apache的状态信息,那使用http://192.168.8.130/server-status替换上述的连接也是可以的。
# 即STATUS_URL="http://192.168.8.130/server-status?auto"
# 修改后保存zapache脚本文件
# 重启zabbix_agentd服务
[root@client ~]# /etc/init.d/zabbix_agentd restart
Restarting zabbix_agentd (via systemctl): [ 确定 ]
3. 验证结果
把原来的apache
模板删除掉,重新导入。并为对应的主机添加该模板。
查看最新数据:
没最新数据,刷新多几次apache
监控状态页面。然后点击“应用”。或者等一会也行。
从下图可以看到,已经有最新的监控数据了。
随便点一个图形,可以看到已经出图了。虽然只有一点点。
至此,监控远程主机的apache
服务终于成功了。