Chinaunix首页 | 论坛 | 博客

OPS

  • 博客访问: 508129
  • 博文数量: 117
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1210
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-05 14:50
个人简介

hellow 运维

文章分类

全部博文(117)

文章存档

2019年(1)

2018年(1)

2017年(45)

2016年(38)

2015年(32)

我的朋友

分类: 系统运维

2016-07-18 15:09:57

1.在client的httpd.conf中添加如下

 vim /alidata/server/httpd/conf/httpd.conf

    SetHandler server-status
    Allow from 127.0.0.1
    Order deny,allow
    Deny from all

ExtendedStatus On 

如果你有rewrite规则,则需要在.htaccess中加上一条,如下:

RewriteCond %{REQUEST_URI} !server-status需要写在index.php之前
sudo vim /alidata/www/jds.jince.com/.htaccess
# ThinkPHP Rewrite规则

   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_URI} !server-status
   RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
 

#禁止显示目录列表
Options -Indexes
2,重加载ache配置
Check uptime并重启

给脚本执行权限

sudo chmod +x /etc/zabbix/scripts/check_apache.sh 

4.将userparameter_apache.conf放入client的/etc/zabbix/zabbix_agentd.d,内容如下:

sudo vim /etc/zabbix/zabbix_agentd.d/userparameter_apache.conf
UserParameter=zapache[*],/bin/bash /etc/zabbix/scripts/check_apache.sh $1 

5.重启agentd

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

测试

sudo sh /etc/zabbix/scripts/check_apache.sh CPULoad
2.06619 

修改权限

sudo  chown zabbix.zabbix /tmp/zapache-http___localhost_server-status_auto.* 

文件如下:

-rw-r--r-- 1 zabbix zabbix       440 Mar 17 14:29 zapache-http___localhost_server-status_auto.cache
-rw-r--r-- 1 zabbix zabbix         0 Mar 17 14:29 zapache-http___localhost_server-status_auto.ts 

6.在zabbix server 中创建Template App Apache service模板,添加items, 关联需要监控的apache主机即可


[root@mysql scripts]# cat apache.sh
#!/bin/bash
curl_cmd=`which curl`
wget_cmd=`which wget`
cache="/tmp/apache_status.txt"
touch $cache
ping_cmd=`ps aux| grep httpd| grep -c grep | wc -l`
function usage()
{
    echo "zapache version: $zapachever"
    echo "usage:"
    echo "  $0 [] TotalAccesses                 - Check total accesses."
    echo "  $0 [] TotalKBytes                   - Check total KBytes."
    echo "  $0 [] CPULoad                       - Check CPU load."
    echo "  $0 [] Uptime                        - Check uptime."
    echo "  $0 [] ReqPerSec                     - Check requests per second."
    echo "  $0 [] BytesPerSec                   - Check Bytes per second."
    echo "  $0 [] BytesPerReq                   - Check Bytes per request."
    echo "  $0 [] BusyWorkers                   - Check busy workers."
    echo "  $0 [] IdleWorkers                   - Check idle workers."
    echo "  $0 [] version                       - Version of this script."
    echo "  $0 [] ping                          - Check if Apache is up."
    echo "  $0 [] WaitingForConnection          - Check Waiting for Connection processess."
    echo "  $0 [] StartingUp                    - Check Starting Up processess."
    echo "  $0 [] ReadingRequest                - Check Reading Request processess."
    echo "  $0 [] SendingReply                  - Check Sending Reply processess."
    echo "  $0 [] KeepAlive                     - Check KeepAlive Processess."
    echo "  $0 [] DNSLookup                     - Check DNSLookup Processess."
    echo "  $0 [] ClosingConnection             - Check Closing Connection Processess."
    echo "  $0 [] Logging                       - Check Logging Processess."
    echo "  $0 [] GracefullyFinishing           - Check Gracefully Finishing Processess."
    echo "  $0 [] IdleCleanupOfWorker           - Check Idle Cleanup of Worker Processess."
    echo "  $0 [] OpenSlotWithNoCurrentProcess  - Check Open Slots with No Current Process."
}


if [ 1 -eq 1 ]; then
     curl="`which curl`"
    if [ "$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 "" > "$cache"
    rval=$?
    if [ $rval != 0 ]; then
        echo "ZBX_NOTSUPPORTED"
        exit 1
    fi
fi
case "$1" in
'version')
      echo "1.5"
      exit 0
    ;;
'ping')
     if [ $ping_cmd > 1 ];then
        echo "1"
     else
        echo "0"
     fi
     ;;
'TotalAccesses')
     value="`awk '/^Total Accesses:/ {print $3}' < \"$cache\"`"
    ;;
'TotalKBytes')
    value="`awk '/^Total kBytes:/ {print $3}' < \"$cache\"`"
   ;;
'CPULoad')
    value="`awk  -F"." '/^CPULoad:/ {print $2}' < \"$cache\"`"
    ;;
'Uptime')
    value="`awk '/^Uptime:/ {print $2}' < \"$cache\"`"
    ;;
'ReqPerSec')
    value="`awk -F"." '/^ReqPerSec:/ {print $2}' < \"$cache\"`"
    ;;
'BytesPerSec')
    value="`awk '/^BytesPerSec:/ {print $2}' < \"$cache\"`"
    ;;
'BytesPerReq')
    value="`awk '/^BytesPerReq:/ {print $2}' < \"$cache\"`"
    ;;
'BusyWorkers')
    value="`awk '/^BusyWorkers:/ {print $2}' < \"$cache\"`"
    ;;
'IdleWorkers')
    value="`awk '/^IdleWorkers:/ {print $2}' < \"$cache\"`"
    ;;
'WaitingForConnection')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "_" }; { print NF-1 }'`"
    ;;
'StartingUp')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "S" }; { print NF-1 }'`"
    ;;
'ReadingRequest')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "R" }; { print NF-1 }'`"
    ;;
'SendingReply')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "W" }; { print NF-1 }'`"
    ;;
'KeepAlive')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "K" }; { print NF-1 }'`"
    ;;
'DNSLookup')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "D" }; { print NF-1 }'`"
    ;;
'ClosingConnection')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "C" }; { print NF-1 }'`"
    ;;
'Logging')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "L" }; { print NF-1 }'`"
    ;;
'GracefullyFinishing')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "G" }; { print NF-1 }'`"
    ;;
'IdleCleanupOfWorker')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "I" }; { print NF-1 }'`"
    ;;
'OpenSlotWithNoCurrentProcess')
    value="`awk '/^Scoreboard:/ {print $2}' < \"$cache\" | awk 'BEGIN { FS = "." }; { print NF-1 }'`"
    ;;
*)
    usage
    exit 1;;
esac
    echo "$value"

阅读(1680) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~