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[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]: <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 [email protected]***.***
这种方法是直接输出客户端信息到mrtg.cfg中

一般情况我们可以这样:
# cfgmaker [email protected]***.***
输出在屏幕上,然后把需要的信息拷贝到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文件。

时间: 2024-10-05 04:40:31

mrtg 和 rrdtools的相关文章

windows上mrtg监控linuxcpu 内存

*网上95%都是linux安装mrtg来做监控,windows来做监控机的很少,即使用也是轻轻点水很肤浅,下面是我亲自在windows上安装mrtg来做监控机的实验,并且也已经开始运行在企业当中.mrtg的特点就是一目了然,配置也相对简单,不需要数据库,它与rrdtools.Nagios没有好坏之分,看你需要用什么了. *在windows系统上安装mrtg,监控linux机器(只要把此搞懂了,在linux安装mrtg监控其他机器就更简单了) 一.准备安装环境 1. MRTG, 2. Active

在RedHa上安装MRTG监控网卡流量

http://os.51cto.com/art/201103/252149.htm 2011-03-30 15:05 张微波 phpchina 字号:T | T 在RedHa上安装MRTG监控网卡流量:MRTG是一个监控网络链路流量负载的工具软件,通过snmp协议得到设备的流量信息,以非常直观的形式显示流量负载.本文讲述的是在RedHa上安装MRTG监控网卡流量 AD:51CTO 网+ 第十二期沙龙:大话数据之美_如何用数据驱动用户体验 在RedHat9上安装调试MRTG监控本机网卡流量 系统环

mrtg监控交换机路由器流量以及nagios报警

1.交换机开启snmp协议 2.安装mrtg yum -y install mrtg 3.配置mrtg (1)创建配置文件,若有多个交换机,可对每个交换机创建相应的配置文件 mkdir -p /usr/local/mrtg cfgmaker -output=/usr/local/mrtg/switch.cfg [email protected]交换机IP 此时生成的switchw.cfg配置文件,记录着所监控交换机的型号,所有正在使用的端口,vlan,当前的速率等信息. 这点需要赞一下,不用我们

MRTG FOR WINDOWS 安装指南

MRTG(Multi Router Traffic Grapher),通常讲是一个监控网络链路流量负载的开源软件,它可以从所有运行SNMP协议的设备上(包括服务器.路由器.交换机等)抓取信息.事实上它不仅可以监控网络设备,任何其它的支持SNMP协议的设备都可以做为MRTG的监控对象,并自动生成包含PNG图形格式的HTML文档,通过HTTP 方式显示给用户. 官方的安装指导:http://mrtg.cs.pu.edu.tw/doc/mrtg-nt-guide.en.html 准备安装环境 安装之前

MRTG Monitoring with ESXi Hosted Guest Return ‘interface is commented * has no ifSpeed property’

MRTG Monitoring with ESXi Hosted Guest Return ‘interface is commented * has no ifSpeed property’ Recently at a network, I migrated the mikrotik base RB configuration to esxi base VM guest. Everything went fine, this Mikrotik have snmp configured, and

MRTG 安装部署手册

本来准备上微软的SCOM 演示下system center2016的,顺便下一个windows 2016 RS1 5G的文件,2个小时过去了,还有2小时看样子绝对要过夜啊.然后搜了下其他开源的,发现了这货. Overview 然后找了老牌监控软件MRTG, 全程Multi Router Traffic Grapher,主要是通过监控网络设备上的SNMP或者其他SNMP的设备来进行绘图,但是路由只是一个开始,当然现在看起来也是一个结束 https://oss.oetiker.ch/mrtg/pub

mrtg监控总结

perl cfgmaker [email protected] -global "WorkDir: C:\www\mrtg" -output mrtg.cfgEcho RunAsDaemon:yes>>mrtg.cfgEcho Interval:5>>mrtg.cfg Perl indexmaker mrtg.cfg>>c:\www\mrtg\index.htmPerl mrtg -logging=mrtg.log mrtg.cfg Windows

linux(CentOS)下Mrtg的安装詳解

linux(CentOS)下Mrtg的安装詳解 MRTG非常強大,他可以監控你的服務器的一舉一動,並且用web方式呈現給你,告訴你網絡,cpu,內存,硬盤等使用狀況,但是配置起來這個軟件實在是非常麻煩. 爲了安裝這個軟件且將其配置好,我上網查了兩天資料,最後整理總結了這一份完整的出來,分享給大家,希望對大家有用.如要轉載請注明出處www.7di.net 一.前期準備(1)MRTG需要以SNMP服务为基础,所以请确保你的系统已经启用了此服务,修改SNMP的配置:#vi /etc/snmp/snmp

mrtg监控网络流量简单配置

Mrtg服务器搭建(监控网络流量) [日期:2012-07-03] 来源:Linux社区  作者:split_two [字体:大 中 小] [实验环境] 监控机:Red Hat linux 5.3  IP:10.10.10.2/24 监控机的操作窗口为绿色字体 被监控机:Red Hat linux 5.3  IP:10.10.10.10/24 操作为白色字体 [实验目的] 监控网络流量 [实验步骤] 1.监控机上需要安装3个软件包,net-snmp(安装一个网管协议).mrtg(此次监控软件).