zabbix 3.4.4监控apache

 
一、Apache开启状态页面

[root@oneapm-test scripts]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Apr 20 2018 18:10:38
[root@oneapm-test scripts]# cat /etc/httpd/conf/httpd.conf   //httpd.conf文件增加如下内容
<Location /server-status>
      setHandler server-status
      Require all granted
</Location>
ExtendedStatus On
 
[root@oneapm-test scripts]# systemctl restart httpd  //重启httpd服务
 
访问apache状态页面
[root@oneapm-test scripts]# curl http://localhost:82/server-status?auto
Total Accesses: 28
Total kBytes: 27
Uptime: 7300
ReqPerSec: .00383562
BytesPerSec: 3.7874
BytesPerReq: 987.429
BusyWorkers: 1
IdleWorkers: 5
Scoreboard: _W____..........................................................................................................................................................................................................................................................
 
二、脚本编写
#! /bin/bash
#
# Name: zapache
#
# Checks Apache activity.
#
# 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:82/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

 

授权脚本运行权限
[root@oneapm-test scripts]# ll zapache.sh 
-rwxr-xr-x. 1 root root 6114 7月  16 13:19 zapache.sh
 
[root@oneapm-test scripts]# tail -1 ../etc/zabbix_agentd.conf
UserParameter=zapache[*],/usr/local/zabbix/scripts/zapache.sh \$1
在Zabbix服务器监控项测试
[root@Zabbix ~]# /zabbix/bin/zabbix_get  -s  172.19.47.225 -p 20050 -k 'zapache[ping]'
1
[root@Zabbix ~]# /zabbix/bin/zabbix_get  -s  172.19.47.225 -p 20050 -k 'zapache[version]'
1.5
 
三、Zabbix导入模板

服务器关联模板:

监控项图形

zabbix监控Apache的更多相关文章

  1. zabbix 监控apache

    现在是客户端 1.安装zabbix的rpm源 1 rpm -ivh http://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4 ...

  2. Zabbix 3.4.11监控 apache服务,ftp服务的配置

    一 zabbix 的安装部署 略 二监控 apache服务的配置 首先在本机下载模板:https://github.com/rdvn/zabbix-templates/archive/m aster. ...

  3. Zabbix 监控MySQL、Apache、Nginx应用监控

    zabbix对第三方应用软件的监控,主要有两个工作难点,一个是编写自定义监控脚本,另一个是在编写模板并导入zabbix web中,编写脚本这个要根据 监控需求定制即可,而编写模板文件有些难度,不过网上 ...

  4. Linux实战教学笔记51:Zabbix监控平台3.2.4(三)生产环境案例

    https://www.cnblogs.com/chensiqiqi/p/9162986.html 一,Zabbix生产环境监测案例概述 1.1 项目规划 [x] :主机分组 交换机 Nginx To ...

  5. zabbix监控阅读目录

    一.zabbix安装 点击查看:http://www.cnblogs.com/hwlong/p/5820321.html 二.解决乱码问题 点击查看:http://www.cnblogs.com/hw ...

  6. CentOS7下搭建zabbix监控(三)——Zabbix监控服务配置

    CentOS7下搭建zabbix监控(一)——Zabbix监控端配置 CentOS7下搭建zabbix监控(二)——Zabbix被监控端配置 (1).配置Zabbix监控Apache服务 主机名:yo ...

  7. zabbix监控tomcat

    服务端配置修改 编译zabbix的时候需要添加参数--enable-java --enable-java 修改zabbix_java配置文件 vim /usr/local/zabbix-2.4.6/s ...

  8. Zabbix监控和分布式部署实施方案

    最近在研究Zabbix监控,由于机房分布在多个城市,因此采用zabbix proxy做为监控方案,在每 个节点部署zabbix proxy,由zabbix proxy收集agentd数据,然后将采集到 ...

  9. Tomcat 常规配置并通过zabbix 监控 jvm状态

    一:jdk和tomcat基础 apache有两种方式运行php,一是使用模块,二是使用fastcgi nginx也可以通过fastcgi处理动态请求,也可以转发至tomcat tomcat监控主要是监 ...

随机推荐

  1. C# [LINQ] Linq Expression 获取多格式文件

    using System; using System.IO; using System.Linq; using System.Linq.Expressions; internal static str ...

  2. C++11 相关教程

    C++11 中文wiki: https://zh.wikipedia.org/zh-cn/C%2B%2B11 C++11 新特性介绍: https://www.kancloud.cn/wangshub ...

  3. springboot接收delete或者put方法体参数

    springboot默认配置了hiddenHttpMethodFilter(可以在springboot启动日志中看到) 因为hiddenHttpMethodFilter只会拦截get和post请求方式 ...

  4. python变量存储

    变量的存储 在高级语言中,变量是对内存及其地址的抽象. 对于python而言,python的一切变量都是对象,变量的存储,采用了引用语义的方式,存储的只是一个变量的值所在的内存地址,而不是这个变量的只 ...

  5. JS之代理模式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. python 语法的一些特性记录

    装饰器@符号 装饰器本质上是一个 Python 函数或类,它可以让其他函数或类在不需要做任何代码修改的前提下增加额外功能,装饰器的返回值也是一个函数/类对象.它经常用于有切面需求的场景,比如:插入日志 ...

  7. django学习系列——python和php对比

    python 和 php 我都是使用过,这里不想做一个非常理性的分析,只是根据自己的经验谈一下感想. 在web开发方面,无疑 php 更甚一筹. 从某种角度来说,php 就是专门为 web 定制的语言 ...

  8. ubuntu安装ssh-service出现无法依赖的解决

    (1)首先先确认下ubuntu系统是否已经安装ssh(通常ubuntu中默认是安装的) 通过命令进行查看:$dpkg -l | grep ssh这里我们可以看到,系统显示已经安装了openssh-cl ...

  9. centos6.5安装Mysql5.6及更改密码

    (一) centos6.5安装Mysql5.6 二进制文件安装的方法分为两种: 第一种是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件: 第二种是使用RPM或其他包进行 ...

  10. 二进制32位转十进制int

    public class BinaryToDecimal { public static int BinaryToDecimal(int binaryNumber){ int decimal = 0; ...