MRTG and Rrdtools

Source: Internet
Author: User
Tags compact time zones rrd rrdtool snmp mrtg

MRTG may have been used by many people, but that is already n long ago, and now many idc,isp in the country are still using this, because we have a Linux scientist, in Linux work n long, I have a little light, learned a lot of things, now to introduce a rrdtools tool. The diagram made out of this is very classic. Rrdtools is also the author of Mrtg, so can be used in combination can also be used alone, if used alone will write some scripts, here I will only introduce MRTG and rrdtools combination of methods.

0. Configure the server SNMP service that needs to collect information (the default is that the machine is already installed, if it is not installed by itself)
#vi/etc/snmp/snmpd.conf

On the third line join
Rocommunity Public
Public is the recognized name of SNMP, the default is this, must be replaced by other names, here for convenience I still use this. (Will be scanned by hackers if not changed)

#/ETC/RC.D/INIT.D/SNMPD Start//Startup service

1. radhat9.0 installation, select System Tools and network tools within system management during installation
2. Download # wget ftp://rpmfind.net/linux/redhat/9/en....81-88.i386.rpm//One will have a plug-in Perl, will be used, and the library initialization will be used
3. Download # wget ftp://rpmfind.net/linux/redhat/9/en....17-13.i386.rpm//can also be installed with the source code, but this simple to use him

If you are using a new version, follow the installation prompts to download the appropriate package

5. # wget ftp://rpmfind.net/linux/freshrpms/r...5-1.fr.i386.rpm

6. Installation
# RPM-IVH perl-cgi-2.81-88.i386.rpm
# RPM-IVH mrtg-2.9.17-13.i386.rpm
# RPM-IVH rrdtool-1.0.45-1.fr.i386.rpm

7. MRTG Data acquisition: The following configurations need to be modified in mrtg.cfg to save MRTG collected data into the RRD library
#vi/etc/mrtg/mrtg.cfg//RPM installation, the default configuration file is here, you can put it
Workdir:/var/www/html/mrtg///place where the library files are stored
Options[_]: growright,bits
LANGUAGE:GB//language, you can choose gb2312 and many other kinds
#Refresh: 300//The parameters below can be selected for opening, temporarily shielding
#writeExpires: Yes
#RunAsDaemon: Yes
#Interval: 5
Logformat:rrdtool//initialization with RRDtool
Pathadd:/usr/bin
libadd:/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi///perl Installation path

###################################################
Down is the information of the server you are going to collect, for example, to collect traffic information for a Windows

TARGET[202.103.***.***_16777219]: 16777219[email protected]***.***:
SETENV[202.103.***.***_16777219]: mrtg_int_ip= "202.103.***.***" mrtg_int_descr= "202.103.***.***"
MAXBYTES[202.103.***.***_16777219]: 12500000
TITLE[202.103.***.***_16777219]: Traffic analysis for 16777219--Changsha
PAGETOP[202.103.***.***_16777219]: #######################################################

Execute CRONTAB-E Join

*/2 * * * * mrtg/etc/mrtg/mrtg.cfg

By the end of this MRTG configuration, MRTG will sample every 2 minutes and save the data to the RRD database

How to know how to collect client information can be used in the following ways:
# cfgmaker--output=/etc/mrtg/mrtg.cfg [email protected]***.***
This method is to output the client information directly into the MRTG.CFG

In general we can do this:
# cfgmaker [Email protected]***.***
Output on the screen, and then copy the required information to the MRTG.CFG, the generally available port without comments (#), just copy that part of the line.

can also write their own collection of information plug-in program
You can use the/usr/bin/sar program created after installing the Sysstat kit to write a plug-in program, or you can write a small program that monitors the CPU using bash. Examples are as follows:

#vi cpu.sh
***************************************************************
#!/bin/sh
Cpuusr= '/usr/bin/sar|grep Average|awk ' {print$3} '
cpusys= '/usr/bin/sar|grep Average|awk ' {print$5} '
Uptime= '/usr/bin/uptime | awk ' {print $ ' "$4" "$ $"
Echo $CPUUSR
Echo $cpusys
Echo $UPtime
Echo yourdomain

******************************************************************
* For file content, do not appear in SH

# chmod 755 cpu.sh (set as executable)
#/etc/mrtg/cpu.sh (test see executable No)
Output:
2.0
5.4
1day,22:30,
YourDomain

Start setting the MRTG parameter entry by doing the following:
# VI Cpu.cfg
************************************************************************

Workdir:/var/www/html/mrtg/
Options[_]: growright,bits
Language:gb
maxbytes[localhost]:100
Options[localhost]:gauge,nopercent,growright
#Refresh: 300
#writeExpires: Yes
#RunAsDaemon: Yes
#Interval: 5
Logformat:rrdtool
Pathadd:/usr/bin
libadd:/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/

########### #添加部分 ###############
Target[localhost]: '/etc/mrtg/cpu.sh '
Ylegend[localhost]: cpuloading (%)
Shortlegend[localhost]:%
Legendo[localhost]: CPU User;
Legendi[localhost]: CPU System;
Title[localhost]: 99_cpu
Pagetop[localhost]:99_cpu

**************************************************************************
After that, start executing the parameter entry, noting that you want to perform more than three times:
# mrtg/etc/mrtg/cpu.cfg

Write to/etc/crontab:
*/5 * * * * mrtg/etc/mrtg/cpu.cfg
This will be OK, direct the web point to the address can be seen.

You can also write other information, such as disk applications, memory applications and so on, the method is similar, not introduced.

So far, Rrdtools began to work, you can write some scripts to generate pictures, writing methods can see Rrdtools, the following I would like to introduce another classic plug-in, you can not write to generate images, and can be grouped management.


8. routers.cgi

To be able to display our traffic analysis diagram in a Web page, we also need to download routers.cgi, a CGI file written in Perl,
Download http://edlink.esc18.net/downloads/mrtg/from here,

You need to install GD first
Http://www.cpan.org/authors/id/L/LD., the latest version is 2.06,
This version requires GD
Http://www.boutell.com/gd/http/gd-2 ... 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;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 won't work with earlier versions.
For earlier versions of LIBGD, use GD version 1.41.

Where is LIBGD installed? [/usr/lib]/usr/local/gd/lib

Choose the features that match how LIBGD was built:
Build JPEG support? [y] Y//Where input is required
Build FreeType support? [y] n//Where input is required
Build XPM support? [y] n//Where input is required

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//execute this command will ask you to answer a series of questions, please fill in according to your system situation truthfully

Attempts to install the routers2.cgi package, located in
The current directory. It'll 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, your may also has line editing
and history capability.
Default answers is in square brackets before the prompt.
Continue [Yes]?
Checking Perl Libraries ...
Rrds Library found correctly.
Warning:you does not have the GD Perl libraries installed correctly.
Routers2.cgi'll still run, but the Compact Summary display won't work.
Download the GD libraries from cpan.org if required.
NT Users should use of PPM to collect GD from ActiveState.
UNIX users should note that they need the GD.PM Perl library in addition to
The LIBGD.A C Library.
Continue [y]?
Warning:you don't have the Time::zone library installed.
This isn't a big problem, so don ' t worry.
This is only being a potential problem if you is using multiple time zones and
Your operating system does not support the TZ environment variable.
If you wish to obtain the package, visit cpan.org
Warning:you don't have the NET::SNMP library installed.
This library is required if you wish the routingtable extension.
Routers2.cgi'll run correctly without this package, however.
If you wish to obtain the package, visit cpan.org

Finding out about YOUR SYSTEM

0. Attempting to identify your OS and Web server ...
-I Think you is running under UNIX.
-I Think you has Apache installed in
/etc/httpd/conf//apache installation of the place

1. WEB Server Document root directory.
This is the base document directory of your Web server.
Document root [/var/www/html]? Web site Home Directory

2. Web Server CGI directory.
This is the directory where your Web server keeps the CGI scripts.
CGI directory [/var/www/cgi-bin/]? Web site CGI Directory

3. MRTG install directory.
The directory where your MRTG configuration files are kept
MRTG Config directory? /ETC/MRTG//Your MRTG configuration file is stored in

4. MRTG config files.
The wildcarded filename format for your MRTG configuration files.
Use a ' * ' to mean ' any characters '-for example, ' *.cfg ' or ' */*.conf '.
MRTG files [*.cfg]? Format of the MRTG configuration file (suffix)

5. RRD Database directory.
The. The directory where your. rrd files are kept
RRD directory [/var/www/html/mrtg/]? The place where the RRD library is stored is set in your MRTG config file.

6. Perl executable.
This is the full pathname of where the Perl executable file is kept.
Perl executable [/usr/bin/perl]? Default

7. routers2.cgi configuration file
This is the file that would hold the routers2.cgi configuration. Unless
There is a reason to move it, stick with the default.
If This file already exists, I'll ask before overwriting it!
Configuration file [/var/www/html/mrtg/routers2.conf]? /var/www/html/mrtg/routers2.conf
Your plug-in script configuration file storage location
Asking OPTIONS
1. Net::snmp does not appear to be installed. Extensions disabled.
If you subsequently install NET::SNMP and then you can enable the extensions
In the routers2.conf file.

2. GD does not appear to be installed. This was required for the compact
Summary. If you intend to install it later, answer YES.
Otherwise, Answer NO.
Activeate Compact Summary screen [no]? Yes//Need GD

3. How big should 1K and 1M is? The ' Usebigk ' parameter from the
routers2.conf file. You have three options-' yes ', ' no ' and ' mixed '.
Yes, 1k=1024, 1m=1024x1024
No, 1k=1000, 1m=1000x1000
Mixed, 1k=1024, 1m=1024x1000 (dont ask)
' usebigk ' option [mixed]? Yes//Select flow calculation method

4. Can I attempt to send a email to the author to let him know the
Software has been installed? This would only give your routers.cgi version,
Perl version, and Operating System version.
Can I Mail [yes]?

Installing software

Perl is:/usr/bin/perl
MRTG Files:/etc/mrtg/*.cfg
RRD Files:/var/www/html/mrtg/
DOC Root:/var/www/html
CGI Bin:/var/www/cgi-bin/
Config File:/var/www/html/mrtg/routers2.conf
Extensions:inactive
Compact page:enabled
' Usebigk ': Yes
Mail Steve:yes
Other options can is set later by modifying the Config file
Continue [Yes]?
WARNING:/var/www/html/mrtg/routers2.conf already exists!
Overwrite existing file [No]? Yes
Creating/var/www/html/mrtg/routers2.conf ...
No mail::send available, trying sendmail instead.
/usr/sbin/sendmail:invalid Option--U
/usr/sbin/sendmail returned code 0. Looks like I cant send a email after all.


* * Complete * *

You should now is able to run the software, although your may need to
Make sure your Web server running.
To access the frontend, point your favourite web browser at the URL:
http://netcool2/cgi-bin/routers2.cgi

See Http://www.cheshire.demon.co.uk/pub/wishlist for information on
How to say ' thanks ' for this free software.

* Apache users should make sure this mod_expires is loaded and enabled
* Apache should also is configured with ' Allowoverride:all ' for the directory
/var/www/html/graphs
* Apache users should not use Mod_perl or speedycgi for this script.
* Wish to tighten the rights granted on the graphs directory
/var/www/html/graphs//Picture Output location

To this your installation completed, if the interface is not the same as above, you also have some of the required packages are not installed, you can follow the prompts to install, The most common ones such as libpng-devel-1.2.2-16.i386.rpm,libjpeg-devel-6b-26.i386.rpm are not installed.

If the installation passes, you can access the "http://Ip/cgi-bin/routers of your machine ... Stupid poke condylar Bran to treat 鐾 agent?

You can modify the routers2.conf file directly later if you want to modify the configuration of routers2.

MRTG and Rrdtools

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.