-
简单、易上手,基本安装完了之后只要修改一下配置文件即可使用。
-
使用文本式的数据库,数据不能重复使用。
-
只能按日、周、月、年来查看数据。
-
由于MRTG本来只是用来监测网络的流量,所以只能存储两个DS(Data Source),即存储流量的输入和输出。
-
每取一次数据即需要绘图一次,浪费系统资源。
-
图像比较模糊。
-
无用户、图像管理功能。
-
没有详细日志系统。
-
无法详细了解各流量的构成。
-
只能用于TCP/IP网络,对于SAN网络流量无能为力。
-
不能在命令行下工作。
-
使用RRD(Round Robin Database)存储格式,数据等于放在数据库中,可以方便地调用。比如,将一个RRD文件中的数据与另一个RRD文件中的数据相加。
-
可以定义任意时间段画图,可以用半年数据画一张图,也可以用半小时内的数据画一张图。
-
能画任意个DS,多种图形显示方式。
-
数据存储与绘图分开,减轻系统负载。
-
能任意处理RRD文件中的数据,比如,在浏览监测中我们需要将数据由Bytes转化为bits,可以将原始数据乘8。
-
RRDTool的作用只是存储数据和画图,它没有MRTG中集成的数据采集功能。
-
在命令行下的使用非常复杂,参数极多。
-
无用户、图像管理功能。
-
首先 RRDtool 存储数据,扮演了一个后台工具的角色。但同时 RRDtool 又允许创建图表,这使得RRDtool看起来又像是前端工具。其他的数据库只能存储数据,不能创建图表。
-
RRDtool 的每个 rrd 文件的大小是固定的,而普通的数据库文件的大小是随着时间而增加的。
-
其他数据库只是被动的接受数据, RRDtool 可以对收到的数据进行计算,例如前后两个数据的变化程度(rate of change),并存储该结果。
-
RRDtool 要求定时获取数据,其他数据库则没有该要求。如果在一个时间间隔内(heartbeat)没有收到值,则会用 UNKN (unknow)代替,其他数据库则不会这样。
1
2
|
[root@node1 ~]
# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@node1 ~]
# rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
|
1
|
[root@node1 ~]
# ntpdate 202.120.2.101
|
1
|
[root@node1 ~]
# wget ftp://195.220.108.108/linux/centos/6.4/os/x86_64/Packages/rrdtool-1.3.8-6.el6.x86_64.rpm
|
1
|
[root@node1 ~]
# yum -y localinstall --nogpgcheck rrdtool-1.3.8-6.el6.x86_64.rpm
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
[root@node1 ~]
# rpm -qa | grep rrdtool
rrdtool-1.3.8-6.el6.x86_64
[root@node1 ~]
# rpm -ql rrdtool
/usr/bin/rrdcgi
/usr/bin/rrdtool
#命令行工具
/usr/bin/rrdupdate
/usr/lib64/librrd
.so.4
#下面是库文件
/usr/lib64/librrd
.so.4.0.7
/usr/lib64/librrd_th
.so.4
/usr/lib64/librrd_th
.so.4.0.7
/usr/share/man/man1/bin_dec_hex
.1.gz
#下面是帮助文档
/usr/share/man/man1/cdeftutorial
.1.gz
/usr/share/man/man1/rpntutorial
.1.gz
/usr/share/man/man1/rrd-beginners
.1.gz
/usr/share/man/man1/rrdbuild
.1.gz
/usr/share/man/man1/rrdcgi
.1.gz
/usr/share/man/man1/rrdcreate
.1.gz
/usr/share/man/man1/rrddump
.1.gz
/usr/share/man/man1/rrdfetch
.1.gz
/usr/share/man/man1/rrdfirst
.1.gz
/usr/share/man/man1/rrdgraph
.1.gz
/usr/share/man/man1/rrdgraph_data
.1.gz
/usr/share/man/man1/rrdgraph_examples
.1.gz
/usr/share/man/man1/rrdgraph_graph
.1.gz
/usr/share/man/man1/rrdgraph_rpn
.1.gz
/usr/share/man/man1/rrdinfo
.1.gz
/usr/share/man/man1/rrdlast
.1.gz
/usr/share/man/man1/rrdlastupdate
.1.gz
/usr/share/man/man1/rrdresize
.1.gz
/usr/share/man/man1/rrdrestore
.1.gz
/usr/share/man/man1/rrdthreads
.1.gz
/usr/share/man/man1/rrdtool
.1.gz
/usr/share/man/man1/rrdtune
.1.gz
/usr/share/man/man1/rrdtutorial
.1.gz
/usr/share/man/man1/rrdupdate
.1.gz
/usr/share/man/man1/rrdxport
.1.gz
/usr/share/rrdtool
|
1
2
3
4
5
6
7
8
9
10
|
[root@node1 ~]
# rrdtool -h
RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker <tobi@oetiker.ch>
Compiled Aug 21 2010 10:57:18
Usage: rrdtool [options]
command
command_options
Valid commands: create, update, updatev, graph, graphv, dump, restore,
last, lastupdate, first, 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
|
-
在Script中使用循环
-
使用crontab任务计划
1
2
3
4
5
|
rrdtool create filename
[--start|-b start
time
]
[--step|-s step]
DS:ds-name:DST:dst arguments
#最后获取的数据是PDP,更新数据时要考滤DS顺序(*把所有要更新的数据,按照DS定义的顺序用冒号格开*)
RRA:CF:cf arguments
#最后获取的数据是CDP,绘图时使用的是这些数据
|
-
DS:DS 用于定义 Data Soure 。也就是用于存放结果的变量名。DS是用来申明数据源的,也可以理解为申明数据变量,也就是你要检测的端口对应的变量名,这个参数在画图的时候还要使用的。
-
DST:DST 就是DS的类型。有 COUNTER、GUAGE、DERIVE、ABSOLUTE、COMPUTE 5种。由于网卡流量属于计数器型,所以这里应该为 COUNTER 。
-
RRA:RRA 用于指定数据如何存放。我们可以把一个RRA 看成一个表,各保存不同 interval 的统计结果。RRA的作用就是定义更新的数据是如何记录的。比如我们每5分钟产生一条刷新的数据,那么一个小时就是12条。每天就是288条。这么庞大的数据量,一定不可能都存下来。肯定有一个合并(consolidate)数据的方式,那么这个就是RRA的作用了。
-
PDP:Primary Data Point 。正常情况下每个 interval RRDtool 都会收到一个值;RRDtool 在收到脚本给来的值后会计算出另外一个值(例如平均值),这个 值就是 PDP ;这个值代表的一般是“xxx/秒”的含义。注意,该值不一定等于RRDtool 收到的那个值。除非是GAUGE ,可以看下面的例子就知道了
-
CF:CF 就是 Consolidation Function 的缩写。也就是合并(统计)功能。有 AVERAGE、MAX、MIN、LAST 四种分别表示对多个PDP 进行取平均、取最大值、取最小值、取当前值四种类型。具体作用等到 update 操作时再说。
-
CDP:Consolidation Data Point 。RRDtool 使用多个 PDP 合并为(计算出)一个 CDP。也就是执行上面 的CF 操作后的结果。这个值就是存入 RRA的数据,绘图时使用的也是这些数据
-
DS 表示这个为DS表达式
-
ds-name 数据域命名
-
DST 定义数据源的类型
-
heartbeat 有效期(heartbeat),案例里的值为'600',假设要取12:00的数据,而前后300秒里的值(11:55-12:05)经过平均或是取最大或最小都算是12:00的有效值;
-
min 允许存放的最小值,此例允许最小为0。
-
max 允许存放的最大值,最大为100000000。
-
GAUGE :GAGUE 和上面三种不同,它没有“平均”的概念,RRDtool 收到值之后字节存入 RRA 中。
-
COUNTER :必须是递增的,除非是计数器溢出。在这种情况下,RRDtool 会自动修改收到的值。例如网络接口流量、收到的packets 数量都属于这一类型。
-
DERIVE:和 COUNTER 类似。但可以是递增,也可以递减,或者一会增加一会儿减少。
-
ABSOLUTE :ABSOLUTE 比较特殊,它每次都假定前一个interval的值是0,再计算平均值。
-
COMPUTE :COMPUTE 比较特殊,它并不接受输入,它的定义是一个表达式,能够引用其他DS并自动计算出某个值。例如CODE:DS:eth0_bytes:COUNTER:600:0:U DS:eth0_bits:COMPUTE:eth0_bytes,8,* 则 eth0_bytes 每得到一个值,eth0_bits 会自动计算出它的值:将 eth0_bytes 的值乘以 8 。不过 COMPUTE 型的 DS 有个限制,只能应用它所在的 RRD 的 DS ,不能引用其他 RRD 的 DS。 COMPUTE 型 DS 是新版本的 RRDtool 才有的,你也可以用 CDEF 来实现该功能。如:CDEF:eth0_bits=eth0_bytes,8,*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node1 ~]
# rrdtool create eth0.rrd \
> --step 300 \
> DS:eth0_in:COUNTER:600:0:12500000 \
# 600 是 heartbeat;0 是最小值;12500000 表示最大值;
> DS:eth0_out:COUNER:600:0:12500000 \
# 如果没有最小值/最大值,可以用 U 代替,例如 U:U
> RRA:AVERAGE:0.5:1:600 \
# 1 表示对1个 PDP 取平均。实际上就等于 PDP 的值
> RRA:AVERAGE:0.5:4:600 \
# 4 表示每4个 PDP 合成为一个 CDP,也就是20分钟。方法是对4个PDP取平均,
> RRA:AVERAGE:0.5:24:600 \
# 同上,但改为24个,也就是24*5=120分钟=2小时。
> RRA:AVERAGE:0.5:288:730
# 同上,但改为288个,也就是 288*5=1440分钟=1天
[root@node1 ~]
# ll -h eth0.rrd
-rw-r--r-- 1 root root 41K 10月 11 10:16 eth0.rrd
|
-
AVERAGE :则结果为 (4+2+1+3)/4=2.5
-
MAX :结果为4个数中的最大值 4
-
MIN :结果为4个数中的最小值1
-
LAST :结果为4个数中的最后一个 3
1
2
|
[root@node1 ~]
# snmpget -v 2c -c public 192.168.18.201 ifInOctets.2
IF-MIB::ifInOctets.2 = Counter32: 57266195
|
1
2
|
[root@node1 ~]
# snmpget -v 2c -c public 192.168.18.201 ifInOctets.2 | sed -e 's/.*ter32: \(.*\)/\1/'
57463513
|
1
2
3
4
|
rrdtool update filename [--template|-t ds-name[:dsname]...] N|timestamp:value[:value...]
filename RRD数据库文件名称
--template|-t ds-name[:ds-name] 要更新RRD数据库中数据源的名称,其中-t指定数据源的顺序
N|timestamp:value[:value...] 时间:要更新的值
|
1
2
|
[root@node1 ~]
#rrdtool update eth0.rrd 1381467942:60723022 或
[root@node1 ~]
# rrdtool update eth0.rrd N:60723022
|
1
|
[root@node1 ~]
# rrdtool fetch eth0.rrd AVERAGE
|
1
2
3
4
5
6
7
8
9
10
|
rrdtool graph filename [option ...]
[data definition ...]
[data calculation ...]
[variable definition ...]
[graph element ...]
[print element ...]
其中的 data definiton、variable definition 、data calculation、分别是下面的格式,
DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=<
time
>][:end=<
time
>][:reduce=<CF>]
VDEF:vname=RPN expression
CDEF:vname=RPN expression
|
-
Time range : 用于控制图表的X轴显示的起始/结束时间,也包括从RRA中提取指定时间的数据。
-
Labels :用于控制 X/Y 轴的说明文字。
-
Size :用于控制图片的大小。
-
Limits :用于控制 Y 轴的上下限。
-
Grid :用于控制 X/Y 轴的刻度如何显示。
-
Miscellaneous :其他选项。例如显示中文、水印效果等等。
-
Report :数字报表
1
|
rrdtool graph filename [option ...] [data definition ...] [data calculation ...] [variable definition ...] [graph element ...] [print element ...]
|
-
filename 要绘制的图片名称
-
Time range时间范围
-
[-s|--start time] 启始时间[-e|--end time]结束时间 [-S|--step seconds]步长
-
Labels
-
[-t|--title string]图片的标题 [-v|--vertical-label string] Y轴说明
-
Size
-
[-w|--width pixels] 显示区的宽度[-h|--height pixels]显示区的高度 [-j|--only-graph]
-
Limits
-
[-u|--upper-limit value] Y轴正值高度[-l|--lower-limit value]Y轴负值高度 [-r|--rigid]
-
Data and variables
-
DEF:vname=rrdfile:ds-name:CF[:step=step][:start=time][:end=time]
-
CDEF:vname=RPN expression
-
VDEF:vname=RPN expression
1
|
[root@node1 ~]
# yum install -y mysql-server
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
[root@node1 ~]
# chkconfig mysqld on
[root@node1 ~]
# service mysqld start
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot
time
you have to copy
support-files
/mysql
.server to the right place
for
your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To
do
so, start the server,
then
issue the following commands:
/usr/bin/mysqladmin
-u root password
'new-password'
/usr/bin/mysqladmin
-u root -h node1.
test
.com password
'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which
will also give you the option of removing the
test
databases and anonymous user created by default. This is
strongly recommended
for
production servers.
See the manual
for
more
instructions.
You can start the MySQL daemon with:
cd
/usr
;
/usr/bin/mysqld_safe
&
You can
test
the MySQL daemon with mysql-
test
-run.pl
cd
/usr/mysql-test
; perl mysql-
test
-run.pl
Please report any problems with the
/usr/bin/mysqlbug
script!
[确定]
正在启动 mysqld: [确定]
[root@node1 ~]
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 2
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and
/or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and
/or
its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
|
test
|
+--------------------+
3 rows
in
set
(0.00 sec)
mysql>
|
1
2
3
4
5
6
7
8
|
[root@node1 ~]
# rrdtool create mysql.rrd --step 3 DS:mysqlselect:COUNTER:5:0:U RRA:AVERAGE:0.5:1:28800 RRA:AVERAGE:0.5:10:2880 RRA:MAX:0.5:10:2880 RRA:LAST:0.5:10:2880
[root@node1 ~]
# ll -h
总用量 620K
-rw-------. 1 root root 970 8月 17 18:50 anaconda-ks.cfg
-rw-r--r--. 1 root root 16K 8月 17 18:50
install
.log
-rw-r--r--. 1 root root 4.1K 8月 17 18:48
install
.log.syslog
-rw-r--r-- 1 root root 294K 10月 11 15:57 mysql.rrd
-rw-r--r-- 1 root root 294K 10月 10 21:53 rrdtool-1.3.8-6.el6.x86_64.rpm
|
1
2
|
[root@node1 ~]
# mysql --batch -e "show global status like 'com_select'" | awk '/Com_select/{print $2}'
5
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@node1 ~]
# vim getselect.sh
#!/bin/bash
#
while
true
;
do
SELECT=`mysql --batch -e
"show global status like 'com_select'"
|
awk
'/Com_select/{print $2}'
`
rrdtool update mysql.rrd N:$SELECT
sleep
3
done
[root@node1 ~]
# bash -n getselect.sh
[root@node1 ~]
# bash -x getselect.sh
+
true
++ mysql --batch -e
'show global status like '
\
''
com_select
'\''
'
++
awk
'/Com_select/{print $2}'
+ SELECT=10
+ rrdtool update mysql.rrd N:10
+
sleep
3
+
true
++
awk
'/Com_select/{print $2}'
++ mysql --batch -e
'show global status like '
\
''
com_select
'\''
'
+ SELECT=11
+ rrdtool update mysql.rrd N:11
+
sleep
3
+
true
++ mysql --batch -e
'show global status like '
\
''
com_select
'\''
'
++
awk
'/Com_select/{print $2}'
+ SELECT=12
+ rrdtool update mysql.rrd N:12
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@node1 ~]
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 55
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and
/or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and
/or
its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
mysql> create database testdb;
Query OK, 1 row affected (0.01 sec)
mysql> use testdb;
Database changed
mysql> create table tb1 (
id
int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name char(50) NOT NULL);
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| tb1 |
+------------------+
1 row
in
set
(0.00 sec)
mysql>
|
1
2
3
4
5
6
7
8
9
10
|
[root@node1 ~]
# vim insert.sh
#!/bin/bash
#
for
I
in
{1..200000};
do
mysql -e
"INSERT INTO testdb.tb1(name) VALUES ('stu$I')"
mysql -e
"SELECT * FROM testdb.tb1"
&>
/dev/null
done
~
[root@node1 ~]
# bash -n insert.sh
[root@node1 ~]
# bash -x insert.sh
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
[root@node1 ~]
# rrdtool fetch -r 3 mysql.rrd AVERAGE
1381478757: -nan
1381478760: -nan
1381478763: -nan
1381478766: -nan
1381478769: -nan
1381478772: -nan
1381478775: 2.7153386392e-01
1381478778: 3.2831536999e-01
1381478781: 3.2891623754e-01
1381478784: 3.2705226490e-01
1381478787: 3.2799497906e-01
1381478790: 3.2750147283e-01
1381478793: 3.2962107218e-01
1381478796: 3.3022497969e-01
1381478799: 3.3027211905e-01
1381478802: 3.3020369194e-01
1381478805: 3.2946024073e-01
1381478808: 3.2988230260e-01
1381478811: 3.2969005472e-01
1381478814: 3.2974230463e-01
1381478817: 3.3001057711e-01
1381478820: 3.3019278582e-01
1381478823: 3.3083777490e-01
1381478826: 3.3015850009e-01
1381478829: 3.2968813815e-01
1381478832: 3.3021007195e-01
1381478835: 3.2890877932e-01
1381478838: 3.2919982365e-01
1381478841: 3.2820752812e-01
1381478844: 3.2498916047e-01
1381478847: 3.2435105446e-01
1381478850: 3.2631508451e-01
1381478853: 3.2927988387e-01
1381478856: 3.3061808059e-01
1381478859: 3.3065099981e-01
1381478862: 3.3079060547e-01
1381478865: 3.2993297013e-01
1381478868: 3.2998088978e-01
1381478871: 3.3045720109e-01
1381478874: 3.3052361682e-01
1381478877: 3.3021445518e-01
1381478880: 3.3033678729e-01
1381478883: 3.3017146110e-01
1381478886: 3.2932443118e-01
1381478889: 3.2872916025e-01
1381478892: 3.2942230122e-01
1381478895: 3.3004157568e-01
1381478898: 3.3035752652e-01
1381478901: 3.3026495130e-01
1381478904: 4.2927608935e-01
1381478907: 5.6199888336e-01
1381478910: 3.2960053815e-01
1381478913: 3.3019513627e-01
1381478916: 3.3008973582e-01
1381478919: 3.3023471404e-01
1381478922: 3.3044897038e-01
1381478925: 3.3025127245e-01
1381478928: 3.2999671137e-01
1381478931: 3.2995130475e-01
1381478934: 3.3001845566e-01
1381478937: 3.3004261932e-01
1381478940: 3.2985954162e-01
1381478943: 3.2962262303e-01
1381478946: 3.3033462847e-01
1381478949: 3.3000997317e-01
1381478952: 3.3023836505e-01
1381478955: 3.2987551061e-01
1381478958: 3.3038940726e-01
1381478961: 3.3047901095e-01
1381478964: 3.2999606597e-01
1381478967: 3.3021352982e-01
1381478970: 3.2998445954e-01
1381478973: 3.3029458891e-01
1381478976: 3.3009257605e-01
1381478979: 3.3008453893e-01
1381478982: 3.2998650516e-01
1381478985: 3.3014434356e-01
1381478988: 3.2950044395e-01
|
1
2
|
[root@node1 ~]
# rrdtool graph mysql.png -s 1381478754 -t "mysql select" -v "selects/3" DEF:select3=mysql.rrd:mysqlselect:AVERAGE:step=3 LINE1:select3#FF0000:"select"
497x174
|