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]: 16777219
ublic@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 ...
随机推荐
- iOS: UIScrollView pauses NSTimer while scrolling
StackOverflow http://stackoverflow.com/a/7059499 Question:I have a UIScrollView that has a series of ...
- 谈谈Android中的SurfaceTexture
2015.7.2更新 由于很多人要代码,我把代码下载链接放在这里了.不过还是要说一下,surfaceTexture和OpenGL ES结合才能发挥出它最大的效果,我这种写法只是我自己的想法,还有很多种 ...
- 通过tarball形式安装HBASE Cluster(CDH5.0.2)——重新编译CDH5.0.2 HADOOP点滴
本文参考博文Hadoop2.2.0遇到64位操作系统平台报错,重新编译Hadoop 由于我采用的tarball方式安装hadoop,其lib/native下根本没有内容,启动hdfs时报这个经典的na ...
- 安卓开发笔记——Broadcast广播机制(实现自定义小闹钟)
什么是广播机制? 简单点来说,是一种广泛运用在程序之间的传输信息的一种方式.比如,手机电量不足10%,此时系统会发出一个通知,这就是运用到了广播机制. 广播机制的三要素: Android广播机制包含三 ...
- 主调度器schedule
中断处理完毕后,系统有三种执行流向: 1)直 ...
- redis的其他命令
1.del del key-name 用于删除已存在的键.不存在的 key 会被忽略 返回值:被删除 key 的数量 2.DUMP DUMP key-name 用于序列化给定 key ,并返回被序列化 ...
- java字符集
在utf-8编码中,unicode(编码字符集)是utf-8(字符编码)的表现形式 http://www.cnblogs.com/hanruyue/p/5859107.html
- 第二种方式,修改python unittest的执行顺序,使用猴子补丁
1.按照测试用例的上下顺序,而不是按方法的名称的字母顺序来执行测试用例. 之前的文章链接 python修改python unittest的运行顺序 之前写的,不是猴子补丁,而是要把Test用例的类名传 ...
- git同时提交到两个仓库
有时候一个项目,希望既提交到oschina又提交到公司内网的gitlab,或者是github什么的. 使用git remote -v 查看当前git的远程仓库. 添加一个远程仓库 git remote ...
- android studio 导入第三方库的记录
android studio 导入第三方库的记录.jar包 和 库 一.jar包 1.jar包的话很简单,首先换成project模式,将你要用的jar包复制到lib下面.如图 2.然后右键选择Add ...