当前位置:网站首页>RRDtool 画MRTG Log数据
RRDtool 画MRTG Log数据
2022-06-29 23:01:00 【星哥玩云】
简述:公司已经有mrtg画流量图了,这里需要对现有的流量图汇总。想利用rrdtool画出总流量图。 1.了解mrtg log格式:
1233645600 1543128 37293414 1724764 39253194 1233645300 1585731 38744665 1794511 41541920 1233645000 2006102 47017612 2433360 53782126 …… MRTG日志分为两部分:
+ 第一部分
日志的第一行是第一部分。有三列,分别代表MRTG上次的运行时间戳,输入 总流量和输出总流量。
+ 第二部分
除去第一行剩下的部分为第二部分,总共5列,分别代表: 1. A(第一列) 这一列相关数据的时间戳,需要注意的是开始时每行之间的时间间 隔为5分钟,最后为一天. perl -e 'print scalar localtime(x),"\n"'
2. B(第二列) 每秒的平均输入(average incoming)流量,以字节为单位。
3. C(第三列) 每秒的平均输出(average outgoing)流量,以字节为单位。
4. D(第四列) 当前间隔内每秒的最大输入流量(maximum incoming),以字节为单 位。这是从当前间隔内所有的更新中计算出来的。假设当前时隔为1小时,每5分 钟更新一次,那么这个值就是所有12次数据中最大的那个。
5. E(第五列) 当前间隔内每秒的最大输出流量(maximum outgoing),以字节为单 位。计算方法同上。
2.汇总mrtg日志: [[email protected] addflow]# cat addflow.sh #!/bin/sh if [ $# -ne 3 ] ; then echo "usage: $0 log_file log_dir swfile" echo "Example usage: $0 all_sw.log all all_sw" exit 1 fi curdir="/usr/local/NetFlow/All_mrtg_log" vlan1="$curdir/$1" swfile="$curdir/$2" swlog=`cat $swfile` log_dir=$3 for i in $swlog do rsync -avL --timeout=120 $curdir/log/$i $curdir/addflow/$log_dir done #getti() #{ # ti=$1 #} #while read LINE #do # getti $LINE # break #done < $vlan1 addto() { to1=`expr $to1 + $2 ` to2=`expr $to3 + $3 ` } addport() { ti1=`expr $ti1 + $2 ` ti2=`expr $ti2 + $3 ` ti3=`expr $ti3 + $4 ` ti4=`expr $ti4 + $5 ` } sumport() { file="$dir/$1" num=0 while read PORT do if [ $num -gt 1 ]; then break fi if [ $num -lt 1 ]; then addto $PORT else addport $PORT fi num=`expr $num + 1 ` done < $file } ti=`date +%s` port=`ls $curdir/addflow/$log_dir/*.log` for i in $port do sumport $i done sed -i '1,2d' $vlan1 sed -i "1 i$ti $ti1 $ti2 $ti3 $ti4" $vlan1 sed -i "1 i$ti $to1 $to2" $vlan1
3.创建rrd文件 这里选用GAUGE类型,计算的数据直接存入rrd。 [[email protected] NetFlow]# cat create_rrd.sh #!/bin/bash /usr/bin/rrdtool create all_sw.rrd --step 300 DS:input:GAUGE:600:0:U DS:output:GAUGE:600:0:U RRA:AVERAGE:0.5:1:2400 RRA:AVERAGE:0.5:4:2400 RRA:AVERAGE:0.5:24:2400 RRA:AVERAGE:0.5:288:2400
update rrd和画图都写到一个bash脚本。 4.更新rrd文件函数 update_rrd() { rrdfile=$1 log_file=$2 STEP=2 HEARTBEAT=4 now=`date +%s` input=`less $log_file|awk '{if( NR == 2) print $2}'` output=`less $log_file|awk '{if( NR == 2) print $3}'` echo -e "input:$input\noutput:$output" /usr/bin/rrdtool updatev $rrdfile $now:$input:$output }
5.rrdtool画过去24小时的图 update_png() { DIR=$1 image_path="${DIR}/$2" rrdfile="${DIR}/$3" PIC=${image_path}/$4 dk=$5 title1=$6 now=`date "+%Y/%m/%d %H\:%M\:%S"` rrdtool graph $PIC\ --title "$title1"\ --vertical-label "单位:(Bits per Second)"\ --end now --start end-86400\ -w 700 -h 200 \ -Y -X 9 -b 1000\ --x-grid MINUTE:12:HOUR:1:HOUR:1:0:'%H'\ --lower-limit=0\ --font TITLE:10: \ --font AXIS:7: \ --font LEGEND:8: \ --font UNIT:7: \ DEF:in=$rrdfile:input:AVERAGE\ DEF:out=$rrdfile:output:AVERAGE\ CDEF:v1=in,8,*\ CDEF:v2=out,8,*\ AREA:v1#00FF00:"上传" \ GPRINT:v1:LAST:"当前:%8.2lf%s" \ GPRINT:v1:MAX:"最大:%8.2lf%s" \ GPRINT:v1:MIN:"最小:%8.2lf%s" \ GPRINT:v1:AVERAGE:"平均:%8.2lf%s\n" \ LINE1:v2#0000ff:"下载" \ GPRINT:v2:LAST:"当前:%8.2lf%s" \ GPRINT:v2:MAX:"最大:%8.2lf%s" \ GPRINT:v2:MIN:"最小:%8.2lf%s" \ GPRINT:v2:AVERAGE:"平均:%8.2lf%s\n" \ COMMENT:"总采购带宽 ${dk} G\t\t\t\t\tLast Updated\: $now" }
6.rrdtool画过去一周的图 update_week_png() { DIR=$1 image_path="${DIR}/$2" rrdfile="${DIR}/$3" PIC=${image_path}/$4 dk=$5 title1=$6 now=`date "+%Y/%m/%d %H\:%M\:%S"` etime=`date +%s` stime=`expr $etime - 604800` echo "etime:$etime stime:$stime" rrdtool graph $PIC\ --title "$title1"\ --vertical-label "单位:(Bits per Second)"\ # -s `date -d "-1 week" +%s` \ --start=$stime\ --end=$etime\ -w 700 -h 200 \ -Y -X 9 -b 1000\ --lower-limit=0\ --font TITLE:10: \ --font AXIS:7: \ --font LEGEND:8: \ --font UNIT:7: \ DEF:in=$rrdfile:input:AVERAGE\ DEF:out=$rrdfile:output:AVERAGE\ CDEF:v1=in,8,*\ CDEF:v2=out,8,*\ AREA:v1#00FF00:"上传" \ GPRINT:v1:LAST:"当前:%8.2lf%s" \ GPRINT:v1:MAX:"最大:%8.2lf%s" \ GPRINT:v1:MIN:"最小:%8.2lf%s" \ GPRINT:v1:AVERAGE:"平均:%8.2lf%s\n" \ LINE1:v2#0000ff:"下载" \ GPRINT:v2:LAST:"当前:%8.2lf%s" \ GPRINT:v2:MAX:"最大:%8.2lf%s" \ GPRINT:v2:MIN:"最小:%8.2lf%s" \ GPRINT:v2:AVERAGE:"平均:%8.2lf%s\n" \ COMMENT:"总采购带宽 ${dk} G\t\t\t\t\tLast Updated\: $now" }
7.函数调用 M_DIR=/usr/local/NetFlow update_rrd $M_DIR/all_sw.rrd $M_DIR/All_mrtg_log/all_sw.log update_png $M_DIR images all_sw.rrd all_sw.png 1024 "过去 24 小时离线和云播总流量" update_week_png $M_DIR images all_sw.rrd all_sw_week.png 1024 "过去 一周 离线和云播总流量"
8.效果图展示:
边栏推荐
- Efficient implementation of dynamiccast with template function and specialization function
- Ansible自动化运维
- 微博系统中”微博评论“的高性能高可用计算架构
- wirehark数据分析与取证infiltration.pacapng
- 提供有效的绩效评估
- Software testing interface testing JMeter 5.5 installation tutorial
- Node data collection and remote flooding transmission of label information
- Pytest initializing and cleaning up the environment
- STM32基础知识点
- Weekly Postgres world news 2022w25
猜你喜欢
The soft youth under the blessing of devcloud makes education "smart" in the cloud
字节云数据库未来方向的探索与实践
VS无法定位程序输入点于动态链接库
Touch key and key control corresponding LED status reversal
M1笔记本居家办公的痛点及解决方案 | 社区征文
Qt中使用QDomDocument和QDomnode来读取xml
nrm详解
wirehark数据分析与取证infiltration.pacapng
优雅的改造短信业务模块,策略模式走起!
Constexpr function
随机推荐
What if MySQL fails to store emoticons
Number theory - division and blocking
Taishan Office Technology Lecture: all elements in a row have the same height
Go zero micro Service Practice Series (VII. How to optimize such a high demand)
收藏!这些提高程序员生产力的工具你用过吗?
80-Redis详解
什么是IGMP?IGMP与ICMP有啥区别?
按头安利 好看又实用的点胶机 SolidWorks模型素材看这里
M1笔记本居家办公的痛点及解决方案 | 社区征文
剑指 Offer 38. 字符串的排列
大学里遗憾的事,希望你无怨也无悔
Efficient implementation of dynamiccast with template function and specialization function
error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
js函数相关的复习
Effective self summary of remote communication | community essay solicitation
触摸按键与按键控制对应的LED状态翻转
远程沟通高效的自我总结| 社区征文
Ansible automatic operation and maintenance
Uniapp copy contents to clipboard
[learn FPGA programming from scratch -51]: high level chapter - FPGA development based on IP core - what is FPGA IP core (soft core, fixed core, hard core) and learning methods