mrtg 和 rrdtools
mrtg可能很多人都用过,但那已经是n久以前的事了,现在在国内很多IDC,ISP都还用这个,因为我们这有个Linux科学家,在Linux工作n 久,我也就沾点光,学了不少东西,现在给大家介绍一个rrdtools的工具。用这个做出来的图非常经典。rrdtools也是mrtg的作者编出来的,因此可以结合使用也可以单独使用,如果单独使用就要自己写一些脚本了,这里我就只介绍mrtg和rrdtools结合用的方法。
0.配置需要采集信息的服务器snmp服务(默认为机器已经装了,如果没有自己装去)
#vi /etc/snmp/snmpd.conf
在第三行加入
rocommunity public
public是snmp的识别名,默认为这个,一定要换成其它名称,在这里为了方便我还是用这个。(不换就会被黑客扫描到)
# /etc/rc.d/init.d/snmpd start //启动服务
1。radhat9.0 安装,安装时在系统管理内选择系统工具和网络工具
2。下载 # wget ftp://rpmfind.net/linux/redhat/9/en....81-88.i386.rpm //一会有个外挂程序是perl的,会用到,而且库初始化也要用
3。下载 # wget ftp://rpmfind.net/linux/redhat/9/en....17-13.i386.rpm //也可以用源码安装,不过这个简单就用他了
如果使用新版本请按照安装提示下载相应的包
5。# wget ftp://rpmfind.net/linux/freshrpms/r...5-1.fr.i386.rpm
6。 安装
# 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数据采集:在mrtg.cfg中需要修改下列配置才能够将mrtg采集的数据保存到rrd库中
#vi /etc/mrtg/mrtg.cfg //用rpm安装,默认配置文件在这,也可以随意放
WorkDir: /var/www/html/mrtg/ //存放库文件的地方
Options[_]: growright,bits
Language: gb //语言,可以选择gb2312等好多种
#Refresh: 300 //下面的参数是可以选择开放的,先暂时屏蔽
#writeExpires: Yes
#RunAsDaemon: Yes
#Interval: 5
LogFormat: rrdtool //用rrdtool初始化
PathAdd:/usr/bin
LibAdd:/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/ //perl安装的路径
###################################################
在往下就是你要采集的服务器的信息了,例如要采集一个windows的流量信息
Target[202.103.***.***_16777219]: 16777219ublic@202.103.***.***:
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]: <H1>Traffic Analysis for 16777219 -- WAI-01</H1>
#######################################################
执行crontab -e加入
*/2 * * * * mrtg /etc/mrtg/mrtg.cfg
到此mrtg的配置基本结束,mrtg会每2分钟采样一次并将数据保存到rrd数据库中
如何知道采集客户端信息可以用以下方法:
# cfgmaker --output=/etc/mrtg/mrtg.cfg public@211.152.***.***
这种方法是直接输出客户端信息到mrtg.cfg中
一般情况我们可以这样:
# cfgmaker public@211.152.***.***
输出在屏幕上,然后把需要的信息拷贝到mrtg.cfg中,一般可用的端口前面没有注释(#),就拷那部分就行。
还可以自己编写采集信息的外挂程序
可以应用安装完sysstat套件后产生的/usr/bin/sar程序进行外挂程序的编写,也可以使用bash写一个监测CPU的小程序。示例如下:
#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 $3" "$4" "$5}'`
echo $cpuusr
echo $cpusys
echo $UPtime
echo yourdomain
******************************************************************
*为文件内容,不要在sh中出现
# chmod 755 cpu.sh(设定成可执行)
# /etc/mrtg/cpu.sh(测试看可执行否)
输出:
2.0
5.4
1day,22:30,
yourdomain
开始设定MRTG参数项,方法如下:
# 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
**************************************************************************
这之后开始执行参数项,注意,要执行三次以上:
# mrtg /etc/mrtg/cpu.cfg
写入到/etc/crontab当中:
*/5 * * * * mrtg /etc/mrtg/cpu.cfg
这样就OK了,直接将Web指向地址就可以看见了。
还可以编写其它信息,例如磁盘应用情况,内存应用情况等等发,方法类似,就不介绍了。
到此为止,rrdtools就开始工作了,你可以自己编写一些脚本生成图片,编写方法可以看rrdtools的说明,下面我要介绍另一个经典的外挂程序,你可以不用编写就能生成图像,而且可以分组管理。
8. routers.cgi
为了能在web页面中显示我们的流量分析图,我们还需要下载routers.cgi这个用perl写的cgi文件,
从这里下载http://edlink.esc18.net/downloads/mrtg/ ,
你需要首先安装GD
http://www.cpan.org/authors/id/L/LD...,最新版本是2.06,
该版本需要GD
http://www.boutell.com/gd/http/gd-2...是安装步骤如下:
# 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 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 //执行该命令后会要你回答一系列的问题,请根据你的系统情况如实填写
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.
WARNING: You do not have the GD Perl libraries installed correctly.
routers2.cgi will still run, but the Compact Summary display will not work.
Download the GD libraries from CPAN.org if required.
NT Users should use 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 do not have the Time::Zone library installed.
This is not a big problem, so don't 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 wish 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
/etc/httpd/conf //apache安装的地方
1. Web server document root directory.
This is the base document directory of your web server.
Document root [/var/www/html]? //网站主目录
2. Web server CGI directory.
This is the directory where your web server keeps the CGI scripts.
CGI directory [/var/www/cgi-bin/]? //网站cgi目录
3. MRTG install directory.
This is the directory where your MRTG configuration files are kept
MRTG config directory? /etc/mrtg //你的mrtg的配置文件存放地
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]? //mrtg配置文件的格式(后缀)
5. RRD Database directory.
This is the directory where your .rrd files are kept
RRD directory [/var/www/html/mrtg/]? //存放rrd库的地方,在你的mrtg配置文件里设的
6. Perl executable.
This is the full pathname of where the Perl executable file is kept.
Perl executable [/usr/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 [/var/www/html/mrtg/routers2.conf]? /var/www/html/mrtg/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.
2. GD does not appear to be installed. This is required for the compact
summary screen to work. If you intend to install it later, answer YES.
Otherwise, answer NO.
Activeate Compact Summary screen [no]? yes //需要GD
3. How big should 1K and 1M be? This 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 //选择流量计算方法
4. Can I attempt to send an email to the author to let him know that the
software has been installed? This will 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 be 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 an email after all.
** ALL COMPLETE **
You should now be able to run the software, although you may need to
make sure you have 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 that mod_expires is loaded and enabled
* Apache should also be configured with 'AllowOverride: All' for the directory
/var/www/html/graphs
* Apache users should NOT use mod_perl or speedycgi for this script.
* You may wish to tighten the rights granted on the graphs directory
/var/www/html/graphs //图片输出位置
到此你的安装完成,如果出现的界面跟上面的不一样,说明你还有一些需要的包没有安装上,你可以根据提示安装,最常见的如libpng-devel-1.2.2-16.i386.rpm,libjpeg-devel-6b-26.i386.rpm没有安装。
如果安装通过,就可以访问“http://你的机器的IP/cgi-bin/routers...笨戳髁糠治鐾剂�
以后如果想修改routers2的配置可以直接修改routers2.conf文件。
mrtg 和 rrdtools的更多相关文章
- 使用snmp+mrtg监控CPU、流量、磁盘空间、内存
1.安装snmp rpm -qa|grep snmp* //查看是否安装了snmpyum -y install snmp* //安装snmp #vim /etc/snmp/snmpd.confroco ...
- mrtg
centos6.5-64-minimal http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.htmlhttp://www.cnblogs.com/see7di/ar ...
- MRTG开源监控安装手册
环境要求: CentOS6以上版本 2G内存 16G存储 源码包下载:第一部分:下载,第二部分:下载 1.安装snmp: yum install -y net-snmp net-snmp-devel ...
- CentOS 6用snmp配合MRTG显示系统状态
1. 软件安装以yum的方式安装snmp/MRTG 安装SNMP(要记得安装net-snmp-utils,不然snmpwalk将不能使用)yum -y install net-snmp* 安装MRTG ...
- mrtg监控网络流量简单配置
Mrtg服务器搭建(监控网络流量) [日期:2012-07-03] 来源:Linux社区 作者:split_two [字体:大 中 小] [实验环境] 监控机:Red Hat linux 5.3 ...
- Windows server install mrtg
由于MRTG使用Perl语言编写 , 安装ActivePerl http://downloads.activestate.com/ActivePerl/releases/5.20.1.2000/Act ...
- MRTG在Windows平台的安装及使用
MRTG (Multi Router Traffic Grapher)是一款监控网络流量负载的免费软件,目前利用MRTG已经开发出了各式各样的统计系统: 1.系统资源负载统计,例如:磁盘空间.CPU负 ...
- centos Install Mrtg
安装支持软件包yum –y install gcc perl gd libpng zlib net-snmp mrtg配置snmpd编辑/etc/snmp/snmpd.conf文件备份snmpd.co ...
- Linux服务器---流量监控MRTG
MRTG MRTG可以分析网络流量,但是它必须依赖SNMP协议.将收集到的数据生成HTML文件,以图片的形式展示出来 1.安装一些依赖软件 [root@localhost bandwidthd-2.0 ...
随机推荐
- Mac terminal Javac
Mac terminal Javac Open the Terminal's vim , then write them: public class test{ public static void ...
- GridView如何将分页数据全部导出为EXCEL?
GRIDVIEW分页状态下将全部数据导出 protected void Button2_Click(object sender, EventArgs e)//按button2将gridview将数据导 ...
- MyBatis的深入原理分析之1-架构设计以及实例分析
MyBatis是目前非常流行的ORM框架,它的功能很强大,然而其实现却比较简单.优雅.本文主要讲述MyBatis的架构设计思路,并且讨论MyBatis的几个核心部件,然后结合一个select查询实例, ...
- input框取消光标颜色手机端不生效
<style> input{ color:transparent; } </style> <input value="我要隐藏光标"> //文字 ...
- Java 连接 Access数据库方式
import <a href="http://lib.csdn.net/base/java" class='replace_word' title="Java 知识 ...
- Adb 获取手机信息
adb shell getprop [ro.product.board]: [herring][ro.product.brand]: [google][ro.product.cpu.abi2]: [a ...
- cakephp文件结构
一个项目的开发会用到cakephp的那些文件呢? 如果你的项目使用cake1.3.6,那么可以参考下面的内容 根据我的经验,会涉及一下文件夹: config controllers models ...
- RESTEasy maven使用
添加依赖: <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteas ...
- python--文件I/O--11
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 一.打印到屏幕 最简单的 ...
- C#WinForm窗体事件执行次序
当 Windows Form 应用程序启动时,会以下列顺序引发主要表单的启动事件: System.Windows.Forms.Control.HandleCreated ...