Network traffic monitoring tools have a lot of, such as: MRTG, Cacti, Zabbix and so on, they have their own characteristics, different focus, only for different application scenarios for a variety of special needs. In addition to network traffic monitoring tools, there are nagios such a monitoring host State tools, not only can effectively monitor Windows, Linux and UNIX host State, switch routers and other network settings, printers and so on. can also be in the system or service when the state of an exception to send e-mail or SMS alarm the first time to notify the site operators, in the state of recovery after the normal message or SMS notification functions. In addition, Nagios simple plug-in design allows users to easily expand their own service detection methods. It is precisely this that makes nagios almost omnipotent. We also often use this feature, using the shell to write various plug-ins with the use of Ngios.
Nagios, though powerful, cannot monitor network traffic as graphically as cacti. So nagios+cacti is integrated through NPC, and powerful alliances become a combination that is often used. I'll have a description of this in the following blog, which I'll skip here. Only for the use of graphical traffic will be in the learning cacti, but also to nagios and cacti integration, the cost is too high. Is there a way to customize network traffic monitoring and display it graphically? This article is using the shell with the drawing tool gnuplot to display the network traffic graphically, you can embed him into nagios or simply use it alone.
First we need to get network traffic. Run ifconfig command
Eth0 Link encap:ethernet hwaddr 00:0c:29:58:a5:d5
inet addr:192.168.0.15 bcast:192.168.0.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FE58:A5D5/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:7 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:496 (496.0 b) TX bytes:2452 (2.3 KiB)
interrupt:193 Base address:0x2000
Where RX Bytes, TX Bytes: The total number of bytes transferred, received (the Red callout part). We take it out and add it. The order is as follows:
Ifconfig | Awk-f ":" ' Nr==8{print $2+$3} ' (in this case, the result is 2948, in bytes)
We will take the value in minutes and subtract the network card traffic per minute with the sum of the previous values and import it into a text file. The format of the file is as follows:
06:01:00 2948
06:02:00 1948
06:03:00 2948
06:04:00 3948
06:05:00 1948
06:06:00 3948
........
Echo-n ' Date +%h:%m:%s ' "" >> result;echo $[' ifconfig | Awk-f ":" ' nr==8{print $2+$3} '-' awk ' {sum+=$2}end{print sum} ' result '] >>result
Echo-n ' Date +%h:%m:%s ' ">> 1; #以小时: minutes: Seconds to obtain the current system time for the format and output redirects to the result file, the-n option does not output line breaks.
awk ' {sum+=$2}end{print sum} ' result #为获得result文件中第二列所有值的和
echo $[' ifconfig | awk-f ': ' Nr==8{print $2+$3} '-' awk ' {sum+=$2}end{print sum} ' result ']>>result #将当前网卡流量减去之前统计的 Network
Card traffic sum gets the traffic of the NIC within this minute and redirects its output to the result file.
#! /bin/bash
While True;do
Echo-n ' Date +%h:%m:%s ' "" >> result;echo $[' ifconfig | Awk-f ":" ' nr==8{print $2+$3} '-' awk ' {sum+=$2}end{print sum} ' result ']>>result
Sleep 60
Done