Nagios Plugin-monitor network speed

Source: Internet
Author: User

#! /Bin/bash
Progname = 'basename $0'
Version = "version 1.0"
Author = "2013.02.05, www.mangocity.com"

St_ OK = 0
St_wr = 1
St_cr = 2
St_uk = 3

Interval = 10
Url = "http://mirrors.163.com/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso"

Print_version (){
Echo "$ version $ Author"
}

Print_help (){
Print_version $ progname $ version
Echo "$ progname is a Nagios plugin to monitor download speed"
Echo "use of wget download URL File"
Echo "when using optional warning/critical thresholds all values limit t"
Echo "usage parameters :"
Echo ""
Echo "$ progname [-I/-- interval] [-u | -- url] [-W/-- warning] [-C/-- Critical]"
Echo ""
Echo "Options :"
Echo "-- interval |-I )"
Echo "defines the download file times"
Echo "propose set <5 second and> 10 second"
Echo "default is: 5 second"
Echo ""
Echo "-- URL |-u )"
Echo "sets URL page"
Echo "defautl is: http://mirrors.163.com/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso"
Echo "Please set fastest URL"
Echo ""
[Root @ uat04 ~] #./Check_speed.sh-W 500-C 450
Warning-speed: 489 | 'speed' = 489
[Root @ uat04 ~] #./Check_speed.sh-W 600-C 500
OK-speed: 744 | 'speed' = 744
[Root @ uat04 ~] #./Check_speed.sh-W 600-C 500
OK-speed: 652 | 'speed' = 652
[Root @ uat04 ~] #./Check_speed.sh-W 800-C 700
Critical-speed: 18 | 'speed' = 18
[Root @ uat04 ~] #./Check_speed.sh-W 800-C 700
Critical-speed: 622 | 'speed' = 622
[Root @ uat04 ~] # Vi./check_speed.sh
#! /Bin/bash
Progname = 'basename $0'
Version = "version 1.0"
Author = "2010.11.17, www.nginxs.com"

St_ OK = 0
St_wr = 1
St_cr = 2
St_uk = 3

Interval = 10
Url = "http://mirrors.163.com/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso"

Print_version (){
Echo "$ version $ Author"
}

Print_help (){
Print_version $ progname $ version
Echo "$ progname is a Nagios plugin to monitor download speed"
Echo "use of wget download URL File"
Echo "when using optional warning/critical thresholds all values limit t"
Echo "usage parameters :"
Echo ""
Echo "$ progname [-I/-- interval] [-u | -- url] [-W/-- warning] [-C/-- Critical]"
Echo ""
Echo "Options :"
Echo "-- interval |-I )"
Echo "defines the download file times"
Echo "propose set <5 second and> 10 second"
Echo "default is: 5 second"
Echo ""
Echo "-- URL |-u )"
Echo "sets URL page"
Echo "defautl is: http://mirrors.163.com/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso"
Echo "Please set fastest URL"
Echo ""
Echo "-- warning |-W )"
Echo "sets a warning level for download speed. defautl is: off"
Echo ""
Echo "-- Critical |-C )"
Echo "sets a critical level for download speed. defautl is: off"
Exit $ st_uk
}

While test-n "$1"; do
Case "$1" in
-- Help |-h)
Print_help
Exit $ st_uk
;;
-- URL |-U)
Url = $2
Shift
;;
-- Interval |-I)
Interval = $2
Shift
;;
-- Warning |-W)
Warn = $2
Shift
;;
-- Critical |-C)
Crit = $2
Shift
;;
*)
Echo "unknown argument: $1"
Print_help
Exit $ st_uk
;;
Esac
Shift
Done

Val_wcdiff (){
If [$ {warn}-lt $ {crit}]
Then
Wcdiff = 1
Fi
}

Get_speed (){
Wget-B $ URL>/dev/null
Sleep $ Interval
BS = "'cat wget-log | tail-N20 | awk '{print $8}' | SED's/K // '| awk' {sum + = $1}; end {print sum }''"
Speed = 'echo $ Bs/19 | bc'
Killall wget
Rm centos *
Rm wget-Log
}
Do_output (){
Output = "Speed: $ {speed }"
}
Do_perfdata (){
Perfdata = "'speed' =$ {speed }"
}

If [-n "$ warn"-a-n "$ crit"]
Then
Val_wcdiff
If ["$ wcdiff" = 1]; then
Echo "Please adjust your warning/critical thresholds. The critical must be lower than the warning level! "
Exit $ st_uk
Fi
Fi

Get_speed
Do_output
Do_perfdata

If [-n "$ warn"-a-n "$ crit"]; then
If [$ speed-Le $ warn-A $ speed-GT $ crit]; then
Echo "WARNING-$ output | $ perfdata"
Exit $ st_wr
Elif [$ speed-lt $ crit]; then
Echo "critical-$ output | $ perfdata"
Exit $ st_cr
Else
Echo "OK-$ output | $ perfdata"
Exit $ st_ OK
Fi
Else
Echo "OK-$ output | $ perfdata"
Exit $ st_ OK
Fi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.