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 total traffic of the network server (total number of data transfer data transfer), CPU usage, and special services (such as Squid's proxy service), etc., the package transmission rate (or traffic) is a matter that the network management must pay . 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 download the MRTG software from the homepage of MRTG: http://www.mrtg.org. At 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. Installing MRTG Since the MRTG is required by the SNMP communication protocol, the corresponding software is required on Linux, which is usually installed with UCD-SNMP software. 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/2/
> - with-gd = / usr / incrude /
> - with-GD-LIB = / usr / lib /
> - with-gd-inc= / usr / include /
> - with-PNG = / usr / include /
> - with-zlib = / usr / incrude
[root@tsaimrtg-2.9.17] # make; MakeInstall
[root@tsaimrtg-2.9.17] # mkdir / usr / local / apache / htdocs / mrtg (note,
Here is the placement location of your WWW homepage, please set it according to your system, in addition, due to us
You need to set network traffic, CPU usage, so in MRTG, establish two subdirectories, easier 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. The detection network card traffic should be used to use MRTG to make a simple map, and the traffic can be automatically monitored as long as a few small steps. 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] # ./indexmake quiz-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 http://192.168.0.1/mrtg/ by the browser, select the appropriate interface address to see traffic information. If you want to generate information similar to http://www.stat.ee.thz.ch/mrtg/, you need to edit an index.html document yourself, store it in / var / www / html / mrtg directory, content is Interface Description and Graphic of Day Statistics of the Interface. When the CPU load detects 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. Writing a plug-in program 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: GB2313
Target [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]: