Gnuplot graphical monitoring of network traffic using shell matching drawing tools

Source: Internet
Author: User

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

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.