当前位置:网站首页>RRDTOOL draws MRTG log data
RRDTOOL draws MRTG log data
2022-06-29 23:23:00 【Brother Xing plays with the clouds】
sketch : The company already has mrtg Draw a flow chart , Here we need to summarize the existing flow charts . Want to use rrdtool Draw the total flow diagram . 1. understand mrtg log Format :
1233645600 1543128 37293414 1724764 39253194 1233645300 1585731 38744665 1794511 41541920 1233645000 2006102 47017612 2433360 53782126 …… MRTG The log is divided into two parts :
+ The first part
The first line of the log is the first part . There are three columns , Represent the MRTG Last run timestamp , Input Total flow and total output flow .
+ The second part
Remove the first line and the rest is the second part , in total 5 Column , Represent the : 1. A( First column ) The timestamp of this column of related data , Note the time between each line at the beginning Septum is 5 minute , The last day . perl -e 'print scalar localtime(x),"\n"'
2. B( Second column ) Average input per second (average incoming) Traffic , In bytes .
3. C( The third column ) Average output per second (average outgoing) Traffic , In bytes .
4. D( The fourth column ) The maximum input traffic per second in the current interval (maximum incoming), Single byte position . This is calculated from all updates in the current interval . Suppose the current interval is 1 Hours , Every time 5 branch The clock is updated once , Then this value is all 12 The largest one in the secondary data .
5. E( The fifth column ) Maximum output traffic per second in the current interval (maximum outgoing), Single byte position . The calculation method is the same as above .
2. Summary mrtg journal : [[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. establish rrd file Here is chosen GAUGE type , The calculated data is directly stored in 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 And drawing a picture bash Script . 4. to update rrd File functions 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 Draw the past 24 Hour chart 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 " Company :(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:" Upload " \ GPRINT:v1:LAST:" At present :%8.2lf%s" \ GPRINT:v1:MAX:" Maximum :%8.2lf%s" \ GPRINT:v1:MIN:" Minimum :%8.2lf%s" \ GPRINT:v1:AVERAGE:" Average :%8.2lf%s\n" \ LINE1:v2#0000ff:" download " \ GPRINT:v2:LAST:" At present :%8.2lf%s" \ GPRINT:v2:MAX:" Maximum :%8.2lf%s" \ GPRINT:v2:MIN:" Minimum :%8.2lf%s" \ GPRINT:v2:AVERAGE:" Average :%8.2lf%s\n" \ COMMENT:" Total purchase bandwidth ${dk} G\t\t\t\t\tLast Updated\: $now" }
6.rrdtool Draw a picture of the past week 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 " Company :(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:" Upload " \ GPRINT:v1:LAST:" At present :%8.2lf%s" \ GPRINT:v1:MAX:" Maximum :%8.2lf%s" \ GPRINT:v1:MIN:" Minimum :%8.2lf%s" \ GPRINT:v1:AVERAGE:" Average :%8.2lf%s\n" \ LINE1:v2#0000ff:" download " \ GPRINT:v2:LAST:" At present :%8.2lf%s" \ GPRINT:v2:MAX:" Maximum :%8.2lf%s" \ GPRINT:v2:MIN:" Minimum :%8.2lf%s" \ GPRINT:v2:AVERAGE:" Average :%8.2lf%s\n" \ COMMENT:" Total purchase bandwidth ${dk} G\t\t\t\t\tLast Updated\: $now" }
7. Function call 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 " In the past 24 Total hourly offline and cloud seeding traffic " update_week_png $M_DIR images all_sw.rrd all_sw_week.png 1024 " In the past a week Total offline and cloud broadcast traffic "
8. Renderings show :
边栏推荐
- Speech signal processing (II): phonation physiology, auditory physiology and auditory psychology
- Intranet penetration (NC)
- PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记
- Evolution from stand-alone to distributed database storage system
- 3D stereo photo album, Valentine's day, couple birthday gift code applicable
- 0. grpc环境搭建
- 论文阅读《Large-Scale Direct SLAM with Stereo Cameras》
- C指针进阶2-->函数指针数组 回调函数简化计算器代码,基于回调函数模拟实现qsort函数
- Wechat applet: (update) cloud development wechat group contacts
- Incluxdb time series database system
猜你喜欢
随机推荐
The development of grpc
Dépannage de l'étiquette: impossible d'ouvrir l'image marquée
[从零开始学习FPGA编程-51]:高阶篇 - 基于IP核的FPGA开发- 什么是FPGA IP核(软核、固核、硬核)与学习方法
Error: c2665: "qmessagebox:: critical": none of the four overloads can convert all parameter types
Laravel creates its own facade extension geoip to obtain country, region and city information according to IP
Pain points and solutions of M1 notebook home office | community essay solicitation
JS function related review
关于二叉树
字节云数据库未来方向的探索与实践
Deep parsing of kubernetes controller runtime
111. simple chat room 14: chat room client
Software testing interface testing JMeter 5.5 installation tutorial
Wireshark data analysis and forensics information pacapng
Weekly Postgres world news 2022w25
Wechat applet: picture seconds plus watermark generation
Sword finger offer 38 Arrangement of strings
Some of my favorite websites
股票开户安全吗?上海股票开户。
Unity Pac Man games, maze implementation
CE第二次作业









