Chinaunix首页 | 论坛 | 博客
  • 博客访问: 508068
  • 博文数量: 173
  • 博客积分: 4112
  • 博客等级: 上校
  • 技术积分: 1577
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-26 10:12
文章分类

全部博文(173)

文章存档

2012年(1)

2010年(172)

我的朋友

分类: 系统运维

2010-04-13 14:00:35

[背景]DBA的要求,每隔一天给它们绘一张交换机总出口的流量,根据上次的开发,我觉得那太麻烦,就玩了下RRD模块,发现功能不错,今天就献给大家 了。通过这个案例大家也能开发出自己满意的脚本(DBA们的要求是以后每隔3小时,其实做法差不多!)。看下文:
[过程]
#!/usr/bin/perl -w
#Author Jacky
#Date   2008/12/31

use strict;
use RRDs;
my $error;
my $starttime=`date -j -v -1d "+%s"`;  #在这里可以改成date -j -v -30M "+%s"(即每隔30分钟获取一张图片)
chomp($starttime);
my $endtime=`date -j "+%s"`;
chomp($endtime);
my $path="/usr/local/share/cacti/rrdimg/";
my($averages,$xsize,$ysize )=RRDs::graph('/usr/local/share/cacti/rrdimg/tel01.png',
                               '--imgformat','PNG',
                               '-s', $starttime,
                               '-e',$endtime,
                               '--title','GZ-CSO-Tel1 - Traffic',
                               '--rigid',
                               '--base','1000',
                               '--height','120',
                               '--width','500',
                               '--alt-autoscale-max',
                               '--lower-limit','0',
                               '--vertical-label','bits per second',
                              
                               'DEF:in=/usr/local/share/cacti/rrdimg/xxx_xxx_xxx_xxx_traffic_in_72.rrd:traffic_in:AVERAGE',
                               'DEF:out=/usr/local/share/cacti/rrdimg/xxx_xxx_xxx_xxx_traffic_in_72.rrd:traffic_out:AVERAGE',
                               
                               'CDEF:cdefin=in,8,*',
                               'CDEF:cdefout=out,8,*',
                               'AREA:cdefin#00CF00:Inbound',
                               'GPRINT:cdefin:LAST: Current\:%8.2lf %s',
                               'GPRINT:cdefin:AVERAGE:Average\:%8.2lf %s',
                               'GPRINT:cdefin:MAX:Maximum\:%8.2lf %s\n',
                               'LINE1:cdefout#002A97:Outbound',
                               'GPRINT:cdefout:LAST:Current\:%8.2lf %s',
                               'GPRINT:cdefout:AVERAGE:Average\:%8.2lf %s',
                               'GPRINT:cdefout:MAX:Maximum\:%8.2lf %s\n'
);

if ( $error = RRDs::error ) {
    print "rrdtool fetch failed: \"$error\"\n";
    exit 1;
}
再结合crontab,在指定的时间运行.如:
59 23 * * * /usr/bin/perl /usr/local/share/cacti/rrdimg/rrdimg.pl  > /dev/null 2>&1
每 天晚上23点59分绘一张满意的图出来,哈哈。。。。
[结论]这个脚本可以完全替代了我第一篇cacti开发的文章,以后,我还会用此类脚本写出 几张图的合并。希望大家能用得上......
阅读(593) | 评论(0) | 转发(0) |
0

上一篇:Cacti Memcached 监控

下一篇:Cacti 备份

给主人留下些什么吧!~~