Linux 监控网络脚本.docx
《Linux 监控网络脚本.docx》由会员分享,可在线阅读,更多相关《Linux 监控网络脚本.docx(28页珍藏版)》请在冰豆网上搜索。
![Linux 监控网络脚本.docx](https://file1.bdocx.com/fileroot1/2022-11/15/72f6621e-1421-4075-9d39-09a77631b658/72f6621e-1421-4075-9d39-09a77631b6581.gif)
Linux监控网络脚本
#!
/bin/sh
#########################################################################
#
#File:
check_traffic.sh
#Description:
Nagioscheckpluginstochecknetworkinterfacetrafficin*nix.
#Language:
GNUBourne-AgainSHell
#Version:
1.1.6
#Date:
2009-02-20
#Corp.:
Chenlei
#Author:
chnl@(Ucanmsnmewiththis.)
#WWW:
#PerlVersion:
UCanfindtheperl/Net:
:
SNMPVersioninthesamesite.
#########################################################################
#Bugs:
#TheLatestVersionwillbereleasedin.
#Youcansendbugsto,
#oremailtomedirectly:
chnl@
#########################################################################
#Todo:
#Donotuseunitatperformancedata,forpnp/rrdgraphingbetter.
#AddtheHistoryperformancedatafilesupport.(maybe)
#Alsosupportthe-nargs,withinterfacenametocheckthetraffic.
#########################################################################
#ChangeLog:
#
#Version1.2.0
#2010-04-26
#ChangedefaultScalevaluefrom4to2,formorefriendlyoutput.Ifyouwantmoreexcatvalue,Ucanchangeitforyouself.
#FixtheMinIntervalcheckbugs,movethecheckbeforewritethecurrentdatatodatahistfile.
#AddtheMaxIntervalvar,defaultvalueis1800,ifthehistdatafileistooold,droptheresult.
#Fixtheforoutput"Maybe32bitcounteroverflow,becausewegotanegativevaluehere."whenchecktoofrequent.AndsetMin_Intervalto30asdefault.
#Addthe-Foptionforsimpleormoresimple(s/S)outputformat.
#Addthe-ioptionfortheindividualsuffixwiththeCF/STAT_HIST_DATAifnecessary.
#Usethe64bitcounterasdefault,whensnmpversionisv2c.Ifthesystemnotsupportit,use32bitcounterinstead.
#Gettheinterface'sIF-MIB:
:
ifSpeed,ifthetrafficvalueisbiggerthanit,dropitandoutputwithOOPSandexitwithUnkown.
#ModifytheCF_HIST_DATAfilenamefrom"/var/tmp/check_traffic_${Host}_${Interface}.hist_dat"to
#"/var/tmp/check_traffic_${Host}_${Interface}.hist_dat_${USER}_64|32"forresolving1)userand2)64/32bittransferproblemwhichmake1)thehistdatafileread/write
#errorand2)withhugeerrortrafficvalue.
#AddthefunctionfortestingTrafficJitter(Theorginalideacomefrommsnchatwihtwjks@).
#Addaoption-pN,N(from1to12)isanumberthatwecomarethistimevaluewiththeaveragevalueofpreviosNtimeswehadbeenchecked.
#Ifthevaluewecheckedthistimeisnotinourdefinedscope(a%value)with-w/-coptionspecified(suchas-w20,20-c30,30),
#wethinkthatitisatrafficjitter.
#Forthisoption,addafileforstoringthehistdatatostat:
/var/tmp/check_traffic_${Host}_${Interface}.hist_dat_${USER}_64|32_ctj_$Num"
#
#Version1.1.6
#2009-02-20
#FixsomemistakeatperfdataoutputformatwithWarningandCriticalValue.(thanksforJiangShan)
#Removetheredundantcode,mergecodefor--rangeoption.
#Writedatabeforetheexit(forthereasonofIsFirst),forthenexttimeuse.
#Whenwriteorreadfileerror,useUnknowinsteadofWarningseverity.
#Ifgetanegativenetflowortimeintervalvaluehere,exitwithunknow.
#
#Version1.1.5
#2008-09-28
#Fixbugonperfdataoutputformat;
#Fixsomespellingmistake;
#AddtheDefaultValueforUseRangeas"False";
#Version1.1.4
#2008-09-18
#Add-roptions,UseRangeinsteadofsinglevalueinwarningandcriticalThreshold;
#Thisoptionsuggestionbyzhgypg@at
#
#Version1.1.3
#2008-09-17
#SetthedefaultIntervalas12seconds;
#
#Version1.1.2
#2008-08-19
#Checkthesnmpagentsupportthe64bitcounterornot;
#Checktheinterfacestatus,ifnotOK,exitwithCriticalstatus;
#GettheinterfacenamewithInterfaceIndexValue;
#
#Version1.1.1
#2008-08-06
#Fixsomebugsinversioncompare.
#Use-6option,use64bitcounter.
#
#Version1.1.0
#2008-06-11
#Insnmpv2c,usecountersifHC*insteadofif*;
#
#Version1.0.9
#2008-04-22
#Morefriendlyoutputwhengettingsnmpinfoerror.
#
#Version1.0.8
#2008-03-31
#Correctsomespellingmistake
#
#Version1.0.7
#2008-03-28
#Ifit'sthefirsttimetotouchhist_dat,echoOKandTipsout;
#Testthehist_datcanbereadandwrite;
#UsetheVarsfor$OutPutand$PerfData
#Fixsomeoutputformat.
#
#Version1.0.6
#2008-03-25
#CorrectPerformancedataoutputwithWarningandCriticalValueofTotalandIntervalforpnpgraphing.
#
#Version1.0.5
#2008-03-24
#CorrectPerformancedataoutputforpnpgraphing.
#
#Version1.0.4
#2008-03-21
#CorrectPerformancedataoutputto"Nagiosplug-indevelopmentguidelines",
#forGraphingtheperformancedatainthewebwithPNP.
#Thestandardis:
'label'=value[UOM];[warn];[crit];[min];[max]
#
#