Use Mrtg to monitor network traffic (for Linux)

Source: Internet
Author: User
Tags time zones rrd rrdtool squid proxy mrtg
Article title: use Mrtg to monitor network traffic (for Linux ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
  
Although mrtg has been used to monitor the traffic of network devices, I still want to write an article about this. Mrtg is a powerful software, in addition to traffic monitoring, you can also monitor the server's CPU usage efficiency, SQUID proxy server traffic statistics, and server NIC traffic. this article will only discuss how to use Mrtg to monitor the port traffic of the vSwitch and vro.
  
   Basic Environment
  
RedHat Linux7.3 + built-in Mrtg2.9.17 + Apache 1.3.27 + RRDTools 1.0.41 + routers2.cgi version2.11
  
Mrtg
  
First install RedHat7.3 and check whether the Mrtg software is installed. of course, you can also download the source code for installation. here, we use the RPM package that comes with RedHatLinux to save time, run the following command to check:
  
# Rpm-qa | grep mrtg
  
If the output is:
  
Mrtg-2.9.17-3
  
It indicates that mrtg has been installed. If no output is obtained, install this software on your CD.
  
Apache
  
Next, download Apache. the specific compilation process will not be detailed. no matter how you compile it, please remember to compile the mod_expries module, because the following routers2.cgi requires this module to regularly refresh the page. the following are common parameters for compiling apache. the installation directory is/usr/local/apache. compilation supports all built-in modules:
  
#./Configure -- enable-module = most -- enable-shared = max
  
   Install configurations
  
The mrtg package is associated with httpd, so as long as the system's built-in mrtg package is installed, it will certainly install the built-in apache, run the following command to remove the apache startup that comes with the system, and use the following command to start the compiled apache:
  
# Chkconfig -- level 345 httpd on
  
# Cp/usr/local/apache/bin/apachectl/etc/init. d/httpd
  
#/Etc/init. d/httpd start
  
# Mkdir/usr/local/apache/htdocs/mrtg
  
RRDTools
  
Download the latest version from here. the current stable version is 1.4.1. The first purpose of RRDTools is to use the third-party frontend tool routers of mrtg. cgi can also reduce the burden on the server and increase work efficiency. if this software is not used, mrtg will sample each 5 minutes and generate a daily, weekly report for each port, monthly and annual traffic analysis charts. after using this software, mrtg will save the sample data to the rrd database every five minutes, but will not generate a traffic analysis diagram, which reduces the server load.
  
# Tar zxvf rrdtool-1.0.41.tar.gz
  
# Cd rrdtool-1.0.41
  
#./Configure -- prefix =/usr/local/rrdtools
  
# Make; make install; make site-perl-install
  
Installation complete
  
   Mrtg data collection
  
# Mkdir/usr/local/apache/htdocs/mrtg/conf
  
# Producer maker -- output =/usr/local/apache/htdocs/mrtg/conf/2948. conf public@10.1.1.1
  
Modify 2948. conf and modify 8th behaviors
  
WorkDir:/usr/local/apache/htdocs/mrtg/2948
  
Add:
  
Options [_]: bits
Language: GB2312
LogFormat: rrdtool
PathAdd:/usr/local/rrdtool/bin
LibAdd:/usr/local/rrdtool/lib/perl
  
Add/usr/bin/mrtg in row 881
  
  
  
Execute crontab-e to join
  
*/5 * mrtg/usr/local/apache/htdocs/mrtg/conf/2948. conf
  
By now, the mrtg configuration has basically ended. mrtg samples data every 5 minutes and saves the data to the rrd database.
  
Routers. cgi
  
To display our traffic analysis diagram on the web page, we also need to download routers. cgi: a cgi file written in perl. download it from here. you need to first install the perl module of GD. The latest version is 2.06. this version requires a version later than 2.01 of GD, therefore, we also need to install the latest GD version. the installation steps are as follows:
  
# Tar zxvf gd-2.0.11.tar.gz
  
# Cd gd-2.0.11
  
#./Configure -- prefix =/usr/local/gd; make install
  
# Tar zxvf GD-2.0.6.tar.gz
  
# Cd GD-2.0.6
  
# Perl Makefile. PL
  
NOTICE: This module requires libgd 2.0.5 or higher.
It will NOT work with earlier versions.
For earlier versions of libgd, use GD version 1.41.
  
Where is libgd installed? [/Usr/lib]/usr/local/gd/lib
  
Please choose the features that match how libgd was built:
Build JPEG support? [Y] y
Build FreeType support? [Y] n
Build XPM support? [Y] n
  
If you experience compile problems, please check the @ INC, @ LIBPATH and @ LIBS
Arrays defined in Makefile. PL and manually adjust, if necessary.
  
Writing Makefile for GD
  
# Make; make install
  
# Tar zxvf routers2-v2.11.tar.Z
  
# Cd routers2-v2.11
  
# Perl install. pl: After you execute this command, you will be asked to answer a series of questions. please enter the correct information based on your system situation.
  
This program attempts to install the routers2.cgi package, located in
The current directory. It will attempt to identify system settings,
But you must confirm the locations guessed, or give the correct
Information.
At any point, you can answer quit to abort the installation.
Depending on your Perl implementation, you may also have line editing
And history capability.
Default answers are in square brackets before the prompt.
Continue [yes]?
Checking Perl libraries...
RRDs library found correctly.
GD libraries found correctly.
WARNING: You do not have the Time: Zone library installed.
This is not a big problem, so dont worry.
This will only be a potential problem if you are using multiple time zones and
Your operating system does not support the TZ environment variable.
If you wish to obtain this package, visit CPAN.org
WARNING: You do not have the Net: SNMP library installed.
This library is required if you want to use the routingtable extension.
Routers2.cgi will run correctly without this package, however.
If you wish to obtain this package, visit CPAN.org
  
FINDING OUT ABOUT YOUR SYSTEM
  
0. Attempting to identify your OS and web server...
-I think you are running under UNIX.
-I think you have Apache installed in
/Usr/local/apache/conf
  
1. Web server document root directory.
This is the base document directory of your web server.
Document root [/usr/local/apache/htdocs]?
  
2. Web server CGI directory.
This is the directory where your web server keeps the CGI scripts.
CGI directory [/usr/local/apache/cgi-bin/]?
  
3. MRTG install directory.
This is the directory where your MRTG configuration files are kept
MRTG config directory? /Usr/local/apache/htdocs/mrtg/conf
  
4. MRTG config files.
This is the wildcarded filename format for your MRTG configuration files.
Use a * to mean any characters-for example, *. cfg or */*. conf.
MRTG files [*. cfg]? *. Conf
  
5. RRD Database directory.
This is the directory where your. rrd files are kept
RRD directory [/usr/local/apache/htdocs/mrtg/2948]?
  
6. Perl executable.
This is the full pathname of where the Perl executable file is kept.
Perl executable [/usr/local/bin/perl]?
  
7. routers2.cgi configuration file
This is the file that will hold the routers2.cgi configuration. Unless you
Have a reason to move it, stick with the default.
If this file already exists, I will ask before overwriting it!
Configuration file [/usr/local/apache/htdocs/mrtg/2948/routers2.conf]?
  
ASKING OPTIONS
1. Net: SNMP does not appear to be installed. Extensions disabled.
If you subsequently install Net: SNMP, then you can enable the extensions
In the routers2.conf file.
  
GD Perl Library is detected.
2. The Compact Summary pages will be enabled.
  
3. How big shoshould 1 K and 1 M be? This is the usebigk parameter from
Routers2.conf file. You have three options-yes, no and mixed.
Yes-> 1 K = 1024, 1 M = 1024x1024
No-> 1 K = 1000, 1 M = 1000x1000
Mixed-> 1 K = 1024, 1 M = 1024x1000 (dont ask)
Usebigk option [mixed]? Yes
  
4. Can I attempt to send an email to the author to let him know that
Software has been installed? This will only give your routers. cgi version,
Perl version, and Operating System version.
Can I

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.