码迷,mamicode.com
首页 > 移动开发 > 详细

nagios的check_http使用

时间:2016-07-13 23:34:22      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:虚拟主机   service   command   监控   动态   

check 的使用,在安装后nagios plugins 后会产生N多check开头的文件。
    就这是这些脚本的使用
   那么对于apache如果只是监控端口80 并不能说明apache就正常,比如动态或者虚拟主机。其中一个网页down了但也不会报警。
  于是就应该对check_tcp!80 进行修改
  其修改commends.cfg  添加:
define command{
        command_name    check_http
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$ -w $ARG2$ -c $ARG3$
        }
修改services.cfg 
define service{
        host_name               aabbcc
        service_description     check-http
        check_command           check_http!3     # 3 timeout  --超时值
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
这样就OK 了。如果你要改一些选项的,在nagios/libexec 目录 ./check_http --help
根据参数改就好了。
 
在这里如果使用check_http!3   nagios返回的是code值HTTP OK HTTP/1.1 200 OK - 66598 bytes in 0.013 seconds     200 刚为正常
如果你进行测试修改一下,就会报其它的错。
check_tcp!80 只返回ping 值
 
 
另一个脚本check_mem    使用方法一样。我只贴出脚本内容了。保存的时候记得chmod +x 
# Script to check real memory usage
# L.Gill 02/05/06 - V.1.0
# ------------------------------------------
# ########  Script Modifications  ##########
# ------------------------------------------
# Who    When      What
# ---    ----      ----
# LGill  17/05/06  "$percent" lt 1% fix - sed edits dc result beggining with "."
#
#
#!/bin/bash
USAGE="`basename $0` [-w|--warning]<percent free> [-c|--critical]<percent free>"
THRESHOLD_USAGE="WARNING threshold must be greater than CRITICAL: `basename $0` $*"
calc=/tmp/memcalc
percent_free=/tmp/mempercent
critical=""
warning=""
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# print usage
if [[ $# -lt 4 ]]
then
        echo ""
        echo "Wrong Syntax: `basename $0` $*"
        echo ""
        echo "Usage: $USAGE"
        echo ""
        exit 0
fi
# read input
while [[ $# -gt 0 ]]
  do
        case "$1" in
               -w|--warning)
               shift
               warning=$1
        ;;
               -c|--critical)
               shift
               critical=$1
        ;;
        esac
        shift
  done
# verify input
if [[ $warning -eq $critical || $warning -lt $critical ]]
then
        echo ""
        echo "$THRESHOLD_USAGE"
        echo ""
        echo "Usage: $USAGE"
        echo ""
        exit 0
fi
# Total memory available
total=`free -m | head -2 |tail -1 |gawk ‘{print $2}‘`
# Total memory used
used=`free -m | head -2 |tail -1 |gawk ‘{print $3}‘`
# Calc total minus used
free=`free -m | head -2 |tail -1 |gawk ‘{print $2-$3}‘`
# normal values
#echo "$total"MB total
#echo "$used"MB used
#echo "$free"MB free
# make it into % percent free = ((free mem / total mem) * 100)
echo "5" > $calc # decimal accuracy
echo "k" >> $calc # commit
echo "100" >> $calc # multiply
echo "$free" >> $calc # division integer
echo "$total" >> $calc # division integer
echo "/" >> $calc # division sign
echo "*" >> $calc # multiplication sign
echo "p" >> $calc # print
percent=`/usr/bin/dc $calc|/bin/sed ‘s/^\./0./‘|/usr/bin/tr "." " "|/usr/bin/gawk {‘print $1‘}`
#percent1=`/usr/bin/dc $calc`
#echo "$percent1"
if [[ "$percent" -le  $critical ]]
        then                echo "CRITICAL - $free MB ($percent%) Free Memory"
                exit 2
fi
if [[ "$percent" -le  $warning ]]        then
                echo "WARNING - $free MB ($percent%) Free Memory"                exit 1
fi
if [[ "$percent" -gt  $warning ]]
        then
                echo "OK - $free MB ($percent%) Free Memory"                exit 0
fi
 

本文出自 “7464112” 博客,谢绝转载!

nagios的check_http使用

标签:虚拟主机   service   command   监控   动态   

原文地址:http://7474112.blog.51cto.com/7464112/1826124

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!