- 用rrdtool create命令创建一个rrdtool的数据库,并且有rrdtool update命令更新它;
- 用rrdtool graph命令画图。
1 # !/ bin / bash
2
3 # create a rrd file
4
5 rrdfile = loadavg.rrd
6 STEP = 2
7 HEARTBEAT = 4
8 now = `date +% s`
9
10 if [ ! - f $rrdfile ]
11 then
12 rrdtool create $rrdfile -- start $now -- step $STEP \
13 DS:loadavg5:GAUGE:$HEARTBEAT:U:U \
14 DS:loadavg10:GAUGE:$HEARTBEAT:U:U \
15 DS:loadavg15:GAUGE:$HEARTBEAT:U:U \
16 RRA:MAX: 0.5 : 3 : 3600
17 else
18 echo " $rrdfile already exists, remove it "
19 fi
20
21 TEMPLATE_STR = " loadavg5:loadavg10:loadavg15 "
22
23 while :
24 do
25 loadavg5 = `cat / proc / loadavg | awk ' {print $1} ' `
26 loadavg10 = `cat / proc / loadavg | awk ' {print $2} ' `
27 loadavg15 = `cat / proc / loadavg | awk ' {print $3} ' `
28 rrdtool update $rrdfile \
29 -- template $TEMPLATE_STR \
30 N:$loadavg5:$loadavg10:$loadavg15
31
32 sleep $STEP
33 done
34
2
3 # create a rrd file
4
5 rrdfile = loadavg.rrd
6 STEP = 2
7 HEARTBEAT = 4
8 now = `date +% s`
9
10 if [ ! - f $rrdfile ]
11 then
12 rrdtool create $rrdfile -- start $now -- step $STEP \
13 DS:loadavg5:GAUGE:$HEARTBEAT:U:U \
14 DS:loadavg10:GAUGE:$HEARTBEAT:U:U \
15 DS:loadavg15:GAUGE:$HEARTBEAT:U:U \
16 RRA:MAX: 0.5 : 3 : 3600
17 else
18 echo " $rrdfile already exists, remove it "
19 fi
20
21 TEMPLATE_STR = " loadavg5:loadavg10:loadavg15 "
22
23 while :
24 do
25 loadavg5 = `cat / proc / loadavg | awk ' {print $1} ' `
26 loadavg10 = `cat / proc / loadavg | awk ' {print $2} ' `
27 loadavg15 = `cat / proc / loadavg | awk ' {print $3} ' `
28 rrdtool update $rrdfile \
29 -- template $TEMPLATE_STR \
30 N:$loadavg5:$loadavg10:$loadavg15
31
32 sleep $STEP
33 done
34
1 # !/ bin / bash
2
3 rrdfile = loadavg.rrd
4 PIC = loadavg.png
5
6 rrdtool graph $PIC \
7 -- title " System Load Average " \
8 -- vertical - label " Load Average " \
9 -- color " BACK#CCCCCC " \
10 -- color " CANVAS#CCFFFF " \
11 -- color " SHADEB#9999CC " \
12 -- height 200 \
13 -- width 400 \
14 -- slope - mode \
15 -- alt - autoscale \
16 -- lower - limit \
17 DEF:max_loadavg5 = $rrdfile:loadavg5:MAX \
18 DEF:max_loadavg10 = $rrdfile:loadavg10:MAX \
19 DEF:max_loadavg15 = $rrdfile:loadavg15:MAX \
20 LINE1:max_loadavg5#0000FF:loadavg5 \
21 LINE1:max_loadavg10#00FF00:loadavg10 \
22 LINE1:max_loadavg15#FF0000:loadavg15 \
23 COMMENT: " Last update\: $(date '+%Y-%m-%d %H\:%M\:%S' -r $rrdfile) "
24
2
3 rrdfile = loadavg.rrd
4 PIC = loadavg.png
5
6 rrdtool graph $PIC \
7 -- title " System Load Average " \
8 -- vertical - label " Load Average " \
9 -- color " BACK#CCCCCC " \
10 -- color " CANVAS#CCFFFF " \
11 -- color " SHADEB#9999CC " \
12 -- height 200 \
13 -- width 400 \
14 -- slope - mode \
15 -- alt - autoscale \
16 -- lower - limit \
17 DEF:max_loadavg5 = $rrdfile:loadavg5:MAX \
18 DEF:max_loadavg10 = $rrdfile:loadavg10:MAX \
19 DEF:max_loadavg15 = $rrdfile:loadavg15:MAX \
20 LINE1:max_loadavg5#0000FF:loadavg5 \
21 LINE1:max_loadavg10#00FF00:loadavg10 \
22 LINE1:max_loadavg15#FF0000:loadavg15 \
23 COMMENT: " Last update\: $(date '+%Y-%m-%d %H\:%M\:%S' -r $rrdfile) "
24