Awk:nagios flow monitoring Plug-in

Source: Internet
Author: User

#!/bin/awk -f#function: nagios plug-in, fine-tuning the threshold value of each network card, specifying the parameter in MB (if the monitoring period is 1 minutes, the specified parameter is 1 minutes transfer data size, non-Mbit/s) # # Usage: Server (WAN:EM1; LAN:EM2), the bandwidth is downstream: 100mbit/s, upstream: 100/3 is approximately equal to 33.3mbit/s (typically downstream one-third), the alarm threshold is calculated by 80%, nagios monitored once per minute, as follows: #接收 (upstream): 100/8*0.8*60=600 (MB) #发送 (downstream): 100/3/8*0.8*60=200 (MB) #监控所有网卡, Nrpe configured as follows: #command [check_netcount]=/usr/local/nagios/libexec/ check_netcount.awk em1 200 600 em2 600 200# Note: Because it is a NAT environment, the EM2 network card alarm parameter is exactly the same as EM1. If it is a single machine, you can specify a network card directly, in the same order: Nic name   receive threshold   Send threshold # #Date:20140929 --sndapkbegin {      #存放上一次数据的临时文件     last_f= "/var/tmp/nagios_bw.tmp"     run_f= "/proc /net/dev "     #获取当前所有网卡: Device name, receive data, send data to Data     while  (getline  Runline <run_f)  {        if  (runline ~ /:/ )  {           sub (/^ +/, "", Runline)      &Nbsp;      split (Runline,runarraytmp, ":  +|:|  + ")            rundata_r[runarraytmp[1]]= runarraytmp[2]           rundata_t[runarraytmp[1]]= runarraytmp[10]        }    }      #判断有没有临时文件     if  (System ("[ -f " Last_f "&NBSP;]")  == 0)  {         #获取上一次的接收, send data to array          while  (Getline lastline <last_f)  {             split (lastline,lastarraytmp, " ")              lastdata_r[lastarraytmp[1]]=lastarraytmp[2]             lastdata_t[lastarraytmp[1]]=lastarraytmp[3]        }          #在上一步获取旧数据后, update temporary files with new data         printf ("")  >last_f         for  (I in rundata_r)  {             print i,rundata_r[i],rundata_t[i] >>last_f         }    }     #未找到临时文件, Action: Initialize the temporary file, initialize the last received, sent array (typically executed on first run)     else {         if  (System ("touch " Last_f)  == 0)  {            for  (J in rundata_r)  {                print j,rundata_r[j],rundata_t[j] >>last _f               lastdata_r[j]=rundata_r[j]                lastdata_t[j]=rundata_t[j]            }        }         else {             print  "Critical - cat not create file:", Last_f "."             exit 2         }    }     #获取各网卡及其报警参数      for  (k=1; k<argc; k+=3)  {        monitor_r[argv [--k]] =argv[++k]        monitor_t[argv[k-=2]]=argv[k+=2]     }      #根据新数据和旧数据, calculate the amount of data generated during this inspection cycle     for  (L in rundata_r)  {         generate_r[l]=int ((Rundata_r[l]-lastdata_r[l])/1024/1024)          generate_t[l]=int ((Rundata_t[l]-lastdata_t[l])/1024/1024)      }     #计算指定监控的网卡是否达到报警阀值, update the status array     for  (m in  monitor_r)  {        if  (M in generate_r)  {            if  (generate_r[m]  >= monitor_r[m] )  {                 critical_r[m]            }             if  (generate_t[m] >=  monitor_t[m] )  {                critical_t[m]             }              #原则, only generate information and performance data for the monitored network card mapping              status=status "__" M "(" Monitor_r[m "," Monitor_t[m] "): r=" generate_r[m] "m,t=" generate_t[m] "M"             sub (/^__/, "", status)              performance=performance "" L "_r=" generate_r[m] ";" Monitor_r[m] ";" L "_t=" generate_t[m] ";" Monitor_t[m] ";"         }        else {             print  "Critical - wrong  parameter. "             exit 2        }    }      #如果状态数组都为0, then normal     if  (Length (critical_r) ==0 && length ( critical_t) ==0 )  {        print  "ok - " status "|" performance        exit 0    }     else {        print  "critical - " Status "|" performance        exit 2    }}


This article is from the "Notepad" blog, make sure to keep this source http://sndapk.blog.51cto.com/5385144/1559536

Awk:nagios flow monitoring Plug-in

Related Article

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.