出于尊重作者Tobi Oetiker的目的,哈哈,我们还是要简要介绍一下这个RRD的。
MRTG和RRD是同一个家族的产品。都是在产生 time-series (时间连续)的图文件(如流量,负载,温度,人数.....)。我们这里用它来产生网络流量图。
MRTG功能比较少,我们在日常使用中也希望对采集时间和采集数据进行更加灵活的表现。所以作者又开发了RRDTool。RRD的全称(Acronym for Round Robin Database)。
一起来看一下作者是如何解释的(可以跳过):
It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density. It can be used either via simple wrapper scripts (from shell or Perl) or via frontends that poll network devices and put a friendly user interface on it.
1.解压tar包
$ tar zxvf rrdtool-1.0.49.tar.gz // 解压到当前目录下
2.编译和安装
$ ./configure --prefix=/usr/local // 设定RRDTool的安装目录
$ make
$ make install
3.安装完毕后,可以看到在/usr/local中添加了一个rrd目录
4.进入到/usr/local/rrd/bin 中,敲入:
$ ./rrdtool
RRDtool 1.0.49 Copyright 1997-2004 by Tobias Oetiker
<tobi@oetiker.ch>;
Usage: rrdtool [options] command command_options
Valid commands: create, update, graph, dump, restore,
last, info, fetch, tune, resize, xport
RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)
For more information read the RRD manpages
① 通过Shell脚本,配置我们监控的端口变量,并生成.rrd的数据文档。(具体操作和含义后面会具体讲)(也有人称之为log文档)
② 由数据更新脚本(NIC_7609.sh),通过调用snmpwalk更新.rrd数据文档。
③ 数据更新脚本(NIC_7609.sh)调用绘图脚本(NIC_7609_Graph.sh)根据.rrd数据文档,重新绘图。
④ 休息300S,继续 ②
原文相关对照:
This example creates a database named target.rrd. Start time (1023654125) is specified in total number of seconds since epoch (time in seconds since 01-01-1970). While updating the database, update time is also specified. This update time MUST occur after start time and MUST be in seconds since epoch.
The step of 300 seconds indicates that database expects new values every 300 seconds. The wrapper script should be scheduled to run every step seconds so that it updates the database every step seconds.
官方英文解释是这样的:
DS (Data Source) is the actual variable which relates to the parameter on the device that has to be monitored.
语法:DS : variable_name : DST : heartbeat : min : max
① DS是关键字。
② variable_name 是在数据文档中记录对应的变量名。当每一个刷新周期到来的时候,数据文档中各变量对应的值就会被更新。这个变量对应的值在官方文档中也叫做主要数据点――PDP(Primary Data Point)。
③ DST:DS的类型,有四个可选项:COUNTER, DERIVE, ABSOLUTE, GAUGE
COUNTER will save the rate of change of the value over a step period. This assumes that the value is always increasing (difference between last two values is more than 0). Traffic counters on a router is an ideal candidate for using COUNTER as DST.
DERIVE is same as COUNTER but it allows negative values as well. If you want to see the rate of change in free diskspace on your server, then you might want to use the DERIVE data type.
ABSOLUTE also saves the rate of change but it assumes that previous value is set to 0. The difference between current and previous value is always equal to the current value. So, it stores the current value divided by step interval (300 seconds in our example).
GAUGE does not save the rate of change. It saves the actual value itself. There are no divisions/calculations. Memory consumption in a server is an ideal example of gauge.
官方原文如下:
In our example, heartbeat is 600 seconds. If database does not get a new PDP within 300 seconds, it will wait for another 300 seconds (total 600 seconds). If it doesnt receive any PDP with in 600 seconds, it will save an UNKNOWN value into database. This UNKNOWN value is a special feature of RRDTool - it is much better than to assume a missing value was 0 (zero). For example, the traffic flow counter on a router keeps on increasing. Lets say, a value is missed for an interval and 0 is stored instead of UNKNOWN. Now when next value becomes available, it will calculate difference between current value and previous value (0) which is not correct. So, inserting value UNKNOWN makes much more sense here.
⑤ min : max 记录数据的最小值和最大值
DS数值的有效范围,超出就是UN喽。也可以不限制用U
① RRA用以声明RRAs的关键字
② CF(consolidation function)合并方式,有几个可选项:AVERAGE, MINIMUM, MAXIMUM, LAST 。
上面说过了,经过一个刷新周期,会获得一个主数据点(PDP),将若干个PDPs使用合并方式(CF)合并后会产生一个合并数据点CDP(consolidated data point)。
③ xff:xfiles factor 和unkown数据有关,很多资料都取0.5
④ step:有step条PDP合并形成一条CDP
⑤ row:记录的合并数据点CDP条数。
对应官方的描述为:
RRA is the keyword to declare RRAs. The consolidation function (CF) can be AVERAGE, MINIMUM, MAXIMUM, and LAST. The concept of the consolidated data point (CDP) comes into the picture here. A CDP is CFed (averaged, maximum/minimum value or last value) from step number of PDPs. This RRA will hold rows CDPs.
1.在FreeBSD上以Port方式安装net-snmp
$ cd /usr/ports/net-mgmt/p5-SNMP
$ make install clean
会让你填一些email 操作系统的资料,直接回车就可以了。
测试snmp是否安装成功,在提示符下键入:
$ snmpwalk
No hostname specified.
Usage: snmpwalk [options...] <hostname>; {<community>;} [<objectID>;]
UCD-snmp version: 4.2.6
-h this help message.
-H Display configuration file directives understood.
-V display version number.
-v 1|2c|3 specifies snmp version to use.
SNMP Version 1 or 2c specific
……
出现以上信息表示net-snmp安装成功。
官方解释为:
Define virtual name for a data source. This name can then be used in the functions explained below. The DEF call automatically chooses an RRA which contains CF consolidated data in a resolution appropriate for the size of the graph to be drawn. Ideally this means that one data point from the RRA should be represented by one pixel in the graph. If the resolution of the RRA is higher than the resolution of the graph, the data in the RRA will be further consolidated according to the consolidation function (CF) chosen.
for p in $port #对每个端口的循环
do
DEFin="DEF:in_bytes_$p=$RRD_PATH:ifInOctets$p:AVERAGE"
DEFout="DEFut_bytes_$p=$RRD_PATH:ifOutOctets$p:AVERAGE"
CDEF="CDEF:in_bits_$p=8,in_bytes_$p,* CDEFut_bits_$p=8,out_bytes_$p,*"