码迷,mamicode.com
首页 > 系统相关 > 详细

获取CACTI RRD文件每天峰值的SHELL

时间:2016-04-24 18:56:28      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:shell   cacti   

代码如下:

url="/var/www/html/rra/150/9517.rrd
/var/www/html/rra/256/11345.rrd
/var/www/html/rra/150/9518.rrd"

fff=`echo $url | awk ‘{print NF}‘`

for((i=1;i<=3;i++))
do
criqi=`date +%s -d "2016-04-11 00:00:00"`
eriqi=`date +%s -d "2016-04-11 23:59:00"`
ccriqi=`echo "$criqi - 86400 * $i" | bc`
eeriqi=`echo "$eriqi - 86400 * $i" | bc`
dt=`date -d "1970-01-01 UTC $eeriqi seconds" +%F`

for((x=1;x<=$fff;x++))
do
uu=`echo $url | awk -v a=${x} ‘{print $a}‘`
/usr/local/rrdtool/bin/rrdtool fetch $uu MAX --start $ccriqi --end $eeriqi | sed -e ‘/^$/d‘ | grep -v "traffic_out" | awk ‘{printf "%f\n",$2}‘ | sed ‘s/\-nan/0.0000000000e+00/g‘ >> /tmp/test${x}
done

                          ff=`cat /tmp/test1 | wc -l`
                          for((n=1;n<=$ff;n++))
                           do
                                for((y=1;y<=$fff;y++))
                                do
                                tt=`cat /tmp/test${y} | sed -n ${n}p`
                                echo $tt >> /tmp/fud
                                done
                                aa=`cat /tmp/fud | awk ‘{sum+=$0}END{print sum}‘`
                                re=`echo "$aa" | awk ‘{sum=$0*8/1000000}END{printf "%.2f",sum}‘`
                                echo $re >> /tmp/testz
                                rm -rf /tmp/fud
                          done
                                td=`cat /tmp/testz | sort -nr |  sed -n 1p`
                                if [ `echo "$td > 1000"|bc` -eq 1 ];then
                                tpt=`echo "scale=3;$td / 1000" | bc | awk ‘{printf "%.2f",$0}‘`
                                echo $tpt"G" $dt
                                echo "$tpt"G" $dt" >> /root/qz.txt
                                else
                                echo $td"M" $dt
                                echo "$td"M" $dt" >> /root/qz.txt
                                fi

for((b=1;b<=$fff;b++))
do
rm -rf /tmp/test${b}
done
rm -rf /tmp/testz
done;

运行结果如下:

[root@cacti]# sh get_in
2.35G 2016-04-10
3.69G 2016-04-09
6.84G 2016-04-08
[root@cacti]#


获取CACTI RRD文件每天峰值的SHELL

标签:shell   cacti   

原文地址:http://flyingzf.blog.51cto.com/38414/1767273

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!