成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

4nagios自定義監(jiān)測腳本

這里舉幾個例子。

為棲霞等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及棲霞網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)、棲霞網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

http連接并發(fā)監(jiān)測

在某地的雙向系統(tǒng)中,兩臺服務(wù)器有一個httpd服務(wù)器,通過負(fù)載均衡承擔(dān)4萬多的機(jī)頂盒的首頁面訪問。因此,需要監(jiān)測每臺服務(wù)器的http連接數(shù)量。對并發(fā)量關(guān)注一段時期,如果并發(fā)量在設(shè)置的值之內(nèi),則不需要進(jìn)行并發(fā)量的調(diào)整,而如果并發(fā)量比較大的話,則需要進(jìn)行調(diào)整httpd參數(shù)。

http的連接數(shù)量可以通過ps -ef | grep httpd | wc -l來獲取。Centos5版本默認(rèn)的文件打開數(shù)量為1024。對/etc/httpd/conf/httpd.conf進(jìn)行參數(shù)調(diào)整,使httpd可以承擔(dān)1000個并發(fā):

查詢默認(rèn)的服務(wù)方式:

# httpd -l

Compiled in modules:

core.c

prefork.c

http_core.c

mod_so.c

#

默認(rèn)的服務(wù)方式為prefork,調(diào)整/etc/httpd/conf/httpd.conf參數(shù)(具體含義可到網(wǎng)上查找):

<IfModule prefork.c>

StartServers 10

MinSpareServers 50

MaxSpareServers 100

ServerLimit 3000

MaxClients 3000

MaxRequestsPerChild 10000

</IfModule>

重啟httpd后,進(jìn)行并發(fā)測試:

ab -n 10000 -c 1000 http://172.16.100.190/index.htm

這里共發(fā)送10000個請求,每次發(fā)送1000個,也就是每次并發(fā)1000個,共分10次發(fā)送。

4 nagios 自定義監(jiān)測腳本

如果是并發(fā)2000,則報錯:

4 nagios 自定義監(jiān)測腳本

查詢httpd的服務(wù)方式為:

ps -ef | grep httpd | wc -l

編寫監(jiān)測腳本:

#!/bin/bash

STATE_OK=0

STATE_WARNING=1

STATE_CRITICAL=2

STATE_UNKNOWN=3

count=`ps -ef | grep httpd | wc -l`

let "count =count-2"

if [ $count -gt 800 ]; then

echo "Critical ! httpd processes is $count!|HttpCounts=$count;600;800;0"

exit $STATE_CRITICAL

elif [ $count -gt 600 ]; then

echo "Warning ! httpd processes is $count!|HttpCounts=$count;600;800;0"

exit $STATE_WARNING

elif [ 600 -gt $count ]; then

echo "Ok ! httpd processes is $count!|HttpCounts=$count;600;800;0"

exit $STATE_OK

else

echo "Unknow"

exit $STATE_UNKNOWN

fi

腳本中echo一行最后添加的“|HttpCounts=$count;600;800;0”是pnp畫圖所需,否則不能畫出圖。其中600為預(yù)警,800為嚴(yán)重告警。

TIME_WAIT監(jiān)測

默認(rèn)配置的httpd,在訪問量比較大的話,使用命令:

# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

TIME_WAIT=581

ESTABLISHED=1

SYN_RECV=1

就會有大量的time_wait??梢酝ㄟ^調(diào)整系統(tǒng)參數(shù)得到改善:

http://blog.csdn.net/sunvince/article/details/6622796

http://chembo.iteye.com/blog/1503770

這里,在/etc/sysctl.conf增加以下4個參數(shù):

net.ipv4.tcp_syncookies = 1 //這個參數(shù)如果已經(jīng)添加了的話,就不需要再次添加
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

然后執(zhí)行 /sbin/sysctl -p 讓參數(shù)生效。

繼續(xù)使用netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}',觀察到TIME_WAIT=3了。

可以根據(jù)下節(jié)中監(jiān)測物理內(nèi)存的check_mem腳本規(guī)范編寫監(jiān)測 TIME_WAIT的腳本:

#more /usr/local/nagios/libexec/check_timewait

#!/bin/bash

#netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

#TIME_WAIT 641

#ESTABLISHED 1

#SYN_RECV 1

if [ $# != 4 ];then

echo "Usage:$0 -w num1 -c num2"

exit

fi

time_wait=`netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'|grep TIME_WAIT|awk '{print $2}'`

established=`netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'|grep ESTABLISHED|awk '{print $2}'`

syn_recv=`netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'|grep SYN_RECV|awk '{print $2}'`

if [ $time_wait -gt $4 ];then

echo "Critical - TIME_WAIT=$time_wait ESTABLISHED=$established SYN_RECV=$syn_recv|TIME_WAIT=$time_wait;$2;$4;0 ESTABLISHED=$established;;; SYN_RECV=$syn_recv;;;"

exit 2

fi

if [ $time_wait -le $4 -a $time_wait -ge $2 ];then

echo "Warning - TIME_WAIT=$time_wait ESTABLISHED=$established SYN_RECV=$syn_recv |TIME_WAIT=$time_wait;$2;$4;0 ESTABLISHED=$established;;; SYN_RECV=$syn_recv;;;"

exit 1

fi

if [ $time_wait -lt $2 ];then

echo "OK - TIME_WAIT=$time_wait ESTABLISHED=$established SYN_RECV=$syn_recv |TIME_WAIT=$time_wait;$2;$4;0 ESTABLISHED=$established;;; SYN_RECV=$syn_recv;;;"

exit 0

fi

~

路由監(jiān)測

另外,由于這臺機(jī)器不能丟失一個默認(rèn)的路由,否則機(jī)頂盒無法獲取首頁面。默認(rèn)的路由也可以編寫腳本進(jìn)行監(jiān)測:

#!/bin/bash

STATE_OK=0

STATE_WARNING=1

STATE_CRITICAL=2

STATE_UNKNOWN=3

default_route=`route |grep default`

if [ "default 172.16.100.1 0.0.0.0 UG 0 0 0 bond0"x = "$default_route"x ]; then

echo "Ok! Default route is \"$default_route\"!|defaultRoute=1;0;0"

exit $STATE_OK

else

echo "Critical! Default route is \"$default_route\"!|defaultRoute=0;0;0"

exit $STATE_CRITICAL

fi

物理內(nèi)存監(jiān)測

默認(rèn)的check_swap為監(jiān)測虛擬內(nèi)存,如果要監(jiān)測物理內(nèi)存,則可以編寫以下腳本:

#cd /usr/local/nagios/libexec

#vi check_mem

#!/bin/bash

#memory

if [ $# != 4 ];then

echo "Usage:$0 -w num1 -c num2"

exit

fi

total_mem=`free -m |grep Mem|awk '{print $2}'`

free_mem=`free -m |grep Mem|awk '{print $4}'`

used_mem=`free -m |grep Mem|awk '{print $3}'`

if [ $free_mem -gt $2 ];then

echo "OK - total memory $total_mem MB used $used_mem MB free $free_mem MB|free_mem=$free_mem;$2;$4;0"

exit 0

fi

if [ $free_mem -ge $4 -a $free_mem -le $1 ];then

echo "Warning - total memory $total_mem MB used $used_mem MB free $free_mem MB|free_mem=$free_mem;$2;$4;0"

exit 1

fi

if [ $free_mem -lt $4 ];then

echo "Critical - total memory $total_mem MB used $used_mem MB free $free_mem MB|free_mem=$free_mem;$2;$4;0"

exit 2

fi

#chown -R nagios.nagios check_mem

#chmod a+x check_mem

#./check_mem -w 200 -c 100 //后面兩個參數(shù)表示剩余內(nèi)存容量,單位為兆。

網(wǎng)上還有另外一個監(jiān)測腳本也可以參考 http://www.yunvn.com/thread-5136-1-5.html :

#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 $4+$7}'`

# 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

用以下命令執(zhí)行:

# ./check_memory -w 36 -c 10

OK - 185 MB (37%) Free Memory

# ./check_memory -w 37 -c 10

WARNING - 185 MB (37%) Free Memory

# ./check_memory -w 40 -c 37

CRITICAL - 184 MB (37%) Free Memory

#

-w表示低于多少百分比就預(yù)警,-c表示低于多少百分比就嚴(yán)重告警

分享文章:4nagios自定義監(jiān)測腳本
標(biāo)題網(wǎng)址:http://jinyejixie.com/article44/iisehe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、Google、移動網(wǎng)站建設(shè)標(biāo)簽優(yōu)化、云服務(wù)器、外貿(mào)建站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)
墨竹工卡县| 宁津县| 大姚县| 汝州市| 永福县| 元阳县| 略阳县| 涪陵区| 合江县| 瑞昌市| 海门市| 定结县| 博兴县| 邯郸县| 仪陇县| 奇台县| 泗水县| 永昌县| 安图县| 鲁山县| 永仁县| 阿克| 瑞昌市| 吐鲁番市| 东至县| 湘潭市| 宜兰县| 平罗县| 嘉义市| 姚安县| 屯昌县| 新余市| 民权县| 东辽县| 广灵县| 容城县| 九寨沟县| 河源市| 滁州市| 报价| 韶关市|