[背景]

          今天我们的网络工程师在使用cacti时,想看到一天中每半个小时的平均端口流量,本可以在cacti的图中,选择时间,可工程量太大了,手工操作也太繁琐了,就想有没有什么好的方法,于是我的简单思路就出来了.......这是初稿,我想随着需求,我还要进一步完善吧!

[过程]

 rrd.pl

 #!/usr/bin/perl
print "Please input year!\n";
my $year=<>;
chomp($year);
print "Please input month(Jan,Feb,Mar...)!\n";
my $month=<>;
chomp($month);
print "Please input day!\n";
my $day=<>;
chomp($day);
print "Please input week(Mon,Tue,Wed...)!\n";
my $week=<>;
chomp($week);
my $date_time="$week $month $day 00:00:00 CST $year";
my $timestamp=`date -j -f "%a %b %d %T %Z %Y" "$date_time" "+%s"`;
$timestamp=$timestamp+0;
for(my $i=0;$i<48;$i++){
 `/bin/sh gp1.sh $i $timestamp $timestamp`;
  $timestamp=$timestamp+1800;
}

gp1.sh

#!/bin/sh
ext=$1
start_time=$2
end_time=$(( $3 + 1800 ))
/usr/local/bin/rrdtool graph $ext.png \
--imgformat=PNG \
--start=$start_time \
--end=$end_time \
--title="11.16.242.12 - Traffic - Gi0/1" \
--rigid \
--base=1000 \
--height=120 \
--width=500 \
--alt-autoscale-max \
--lower-limit=0 \
COMMENT:"From 2008/12/16 10\:00\:00 To 2008/12/16 10\:30\:00\c" \
COMMENT:"  \n" \
--vertical-label="bits per second" \
--slope-mode \
DEF:a="/usr/local/share/cacti/rra/11_16_242_12_traffic_in_103.rrd":traffic_in:AVERAGE \
DEF:b="/usr/local/share/cacti/rra/11_16_242_12_traffic_in_103.rrd":traffic_out:AVERAGE \
CDEF:cdefa=a,8,* \
CDEF:cdefe=b,8,* \
AREA:cdefa#00CF00:"Inbound"  \
GPRINT:cdefa:LAST:" Current\:%8.2lf %s"  \
GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n"  \
LINE1:cdefe#002A97:"Outbound"  \
GPRINT:cdefe:LAST:"Current\:%8.2lf %s"  \
GPRINT:cdefe:AVERAGE:"Average\:%8.2lf %s"  \
GPRINT:cdefe:MAX:"Maximum\:%8.2lf %s"

 

[结果]这样,我1天内24小时,就可以输出48张图片了........哈哈......那么只要按0..47.png点击图片,就可以看到这每半个小时的平均流量了......(为什么说是扩展开发呢,我觉得是在cacti不能满足我们需求的时候,我们自主搞得东西,所以我就叫它扩展开发喽.....不准扔鸡蛋....扔Money!)


如果想了解更多,请关注我们的公众号
公众号ID:opdevos
扫码关注

cacti扩展开发_第1张图片