By the wind had left maple, Source: Reprinted from SEOUL Author: Qiu Li ring
With the increasingness of Linux applications, there is a large number of web servers using the Linux operating system. In order to fully measure the network operation, you need more detailed and more accurate measurements for network status. The formulation of the SNMP protocol provides strong support for Internet measurements. MRTG (Multirouter Traffic Grapher, MRTG) is a typical network traffic statistical tool based on SNMP. It consumes a small system resource, so there are many plug-in programs that are also attached to MRTG. It obtains its traffic information from the device via the SNMP protocol, and displays the traffic load to the user in a very intuitive form of the HTML document containing the JPEG format.
working principle
The network server's total traffic (total number of data transfer data transfer), CPU usage, and special services (such as Squid's proxy service), etc., the package transfer rate (or traffic) is a matter that network managers must pay attention to. Because when the CPU usage of the host is too high, the system may present an unstable state, which requires that which service is to stop our information. Therefore, network management, it is necessary to understand the traffic status of our host, and the flow rate is limited or increase bandwidth.
We can be from MRTG's homepage:
Http://www.mrtg.org/ Download MRTG software. At the website:
Http://www.stat.ee.ethz.ch/mrtg/ You can get the output result of the MRTG traffic monitoring map. An example is shown in Figure 1.
Figure 1 Output result of the MRTG flow monitoring
MRTG is written in Perl and uses ZLIB, GD, and PNG and other functions (ZLIB used to compress the chart, GD is used to draw charts). The server already contains the following software: Perl (Perl-5.0xx or more), ZLIB (Zlib-1.1.3-XX or more), GD (GD-1.3.xx or more), libpng and apache.
You can use rpm to confirm them:
RPM -QA | GREP Perl
RPM -QA | GREP ZLIB
RPM -QA | GREP GD
RPM -QA | GREP LIBPNG
In addition, since the MRTG outputs a chart in the format of HTTP, Apache must be installed. Hereinafter, we use the preset Apache path to install the chart of the MRTG output for / usr / local / apache / htdocs path. To pay attention, if there is no Apache, although you can still force MRTG, you can't display charts.
Install MRTG
Since the MRTG is required to be required through the SNMP Communication Protocol, there is a need to install the corresponding software on Linux, which is usually installed for the installation of UCD-SNMP.
1. Download UCD-SNMP-4.2.1.tar.gz, MRTG-2.9.17.tar.gz.
2. Install UCD-SNMP-4.2.1.tar.gz.
[root @ TSAI / root] #CD / USR / local / src
[root @ Tsaisrc] #CP /Root/ucd-snmp-4.2.1.tar.gz
[root @ Tsaisrc] #tar -zxvfucd-snmp-4.2.1.tar.gz
[root @ Tsaisrc] #CD UCD-SNMP-4.2.1
[root@tsaiucd-snmp-4.2.1] # ./configure-prefix=/usr/local/snmp
[root@tsaiucd-snmp-4.2.1] # Make
[root@tsaiucd-snmp-4.2.1] # makeinstall
3. Start UCD-SNMP.
You can start automatically on /etc/rc.d/rc.local directly below the shell, or directly on /etc/rc.d/rc.local. 4. installation.
[root @ TSAI / root] # CD / usr / local / src
[root @ Tsaisrc] # CP / root / mrtg-2.9.17.tar.gz.
[root @ Tsaisrc] # TAR-ZXVFMRTG-2.9.17.tar.gz
[root @ Tsaisrc] # cdmrtg-2.9.17
[root@tsaimrtg-2.9.17] # ./configure-prefix=/usr/local/mrtg-2
> - with-gd = / usr / incrude
> - with-GD-LIB = / usr / lib
> - with-gd-inc = / usr / include
> - with-PNG = / usr / incrude
> - with-zlib = / usr / incrude
[root@tsaimrtg-2.9.17] # make; MakeInstall
[root@tsaimrtg-2.9.17] # mkdir / usr / local / apache / htdocs / mrtg
(Please note that here is related to your WWW homepage, please set it according to your system, in addition, because we need to set network traffic, CPU usage, in MRTG, build two subdirectories, compare Easy to manage.)
[root@tsaimrtg-2.9.17] # mkdir / usr / local / apache / htdocs / mrtg / net
[root@tsaimrtg-2.9.17] # cpimages / * / usr / local / apache / htdocs / mrtg / net
Now we have installed the MRTG system correctly.
Detect network card traffic
It is very simple to use MRTG to make a picture, as long as a few small steps can automatically monitor traffic. First, a parameter item (preset is mrtg.cfg), then modify the MRTG.cfg parameter item, then execute the three parameter files directly, then use the MRTG program to directly produce it into the home page, You can check the chart.
The method of setting the MRTG is as follows:
[root@tsaimrtg-2.9.17] # CD / usr / local / mrtg-2 / bin
[root @ tsaibin] #. / cfgmaker -
Output = / usr / local / apache / htdocs / mRTG / NET / MRTG.CFG
> public@vbird.adsldns.org
[root @ TSAIBIN] # vi / usr / local / apache / htdocs / mrtg / net / mrtg.cfg
However, due to the MRTG.cfg set by the program, there is a problem, so, please modify the following three lines into your own style.
Workdir: / usr / local / apache / htdocs / mrtg / net /
Options [_]: GrowRight, BITS
Language: GB2312
[root @ tsaibin] # ./mrtg/usr/local/apache/htdocs/mrtg/net/mrtg.cfg
Start testing your parameters, you can do three times, you can work normally, but if you have any questions, you need to change MRTG.cfg, and then do it until there is no error.
[root @ tsaibin] # ./indexmaker
> - OUTPUT = / usr / local / apache / htdocs / mrtg / net / index.html> - Title = Vbird host traffic statistics table
> /usr/local/apache/htdocs/mrtg/net/mrtg.cfg
The above program is Indexmaker is in the production of the home page. An index.html file will be automatically output.
/ usr / local / apache / htdocs / mrtg / net
Note: Publicns.org is in public @ vbird. Adsldns.org, public is a meaning of its meaning (one code in the preset search in SNMP). If the dynamic DNS name of the host is Your.Domain.name, you must write into public @ Your. Domain.name.
After setting up five minutes, you can start testing. Then you can access the address through your browser.
Http://192.168.0.1/mrtg/, select the appropriate interface address to see traffic information. If you want to generate a similar
Http://www.stat.ee.thz.ch/mrtg/ Information, you need to edit your own index.html document, store in / var / www / html / mrtg directory, content is an interface description and the interface Graphic chart of day statistics.
Detect CPU load
When you detect the CPU load, you need to use an additional plug-in, which is the SysStat.
1. Download and install Sysstat-4.0.2-1.i386.rpm:
$ rpm-ivhsysstat-4.0.2-1.i386.rpm
2. Write a plug-in program
You can apply the / usr / bin / sar program generated after the SYSSTAT suite for the plug-in program, or use BASH to write a small program that monitors the CPU. Examples are as follows:
[root @ tsaicpu] # Vimrtg.cpu
--- Program start ----
#! / bin / bash
# This program is used to detect a small plug-in program for the CPU.
# 1. Start using SAR to monitor the USER and SYSTEM load rate of CPU
CPUUSR = `/ usr / bin / sar-u13 | grepaverage | awk '{print $ 3}'`
Cpusys = `/ usr / bin / sar-u13 | grepaverage | awk '{print $ 5}'`
Uptime = `/ usr / bin / uptime | awk '{print $ 3" "$ 4" "$ 5}'`
# 2. List four data (the first two are numbers)
Echo $ CPUUSR
Echo $ CPUSYS
Echo $ uptime
echovbird.adsldns.org (here you write your host name)
---- The program ends ----
[root @ tsaicpu] # chmod755mrtg.cpu (set to be executable)
[root @ tsaicpu] #. / mrtg.cpu (test to see if you can see)
2.0
5.4
1DAY, 22: 30,
vbird.adsldns.org
3. Start setting the MRTG parameter item, the method is as follows:
[root @ tsaicpu]
# vi mrtg.cfg.cpu
---- Program start ----
### GlobalConfigOptions
### TogetBitsInsteadofbytesandgraphs growthingtotheright
Workdir: / usr / local / apache / htdocs / mrtg / CPU /
Language: GB2313TARGET
[localhost]: `/ usr / local / apache / htdocs / mrtg / cpu / mrtg.cpu`
MaxBytes [localhost]: 100
Options [Localhost]: Gauge, NOPERCENT, GROWRIGHT
YLEGEND [Localhost]: cpuloading (%)
Shortlegend [localhost]:%
Legendo [LocalHost]: CPU user load;
Legendi [LocalHost]: CPU pure system load;
Title [localhost]: CPU? T ??? v
PageTop [localhost]:
After this, you will start executing the parameters, pay attention, do three times:
/ usr / local / MRTG-2
/bin/mrtg/usr/local/apache/htdocs/mrtg/cpu/mrtg.cfg.cpu
4. Write to / etc / crontab:
* / 2 **** root / usr / local / MRTG-2
/bin/mrtg/usr/local/apache/htdocs/mrtg/cpu/mrtg.cfg.cpu> ///dev/null 3,01
This is OK, directly
Http: //your.host.domain/mrtg/cpu/localhost.html.
Let's talk about SAR. Basically, SAR can be used to detect a lot of things, for example: SAR- U 1 5, a CPU is measured every second, a total of five sub-averages; SARR 3 3, see an entity and virtual internal deposit every three seconds, Three after three times.
We mainly introduce the preparation of MRTG installation, start installation, detecting network card traffic, detecting CPU loads. In fact, MRTG has many functions, I hope the readers will further excavate.