#!/bin/bash
while true; do
mkdir -p /data/shell/Xstats
if [[ ! -f "/data/shell/Xstats/downlink_traffic.rrd" ]]; then
rrdtool create /data/shell/Xstats/downlink_traffic.rrd \
--step 5 \
DS:apollo:COUNTER:10:0:U \
DS:dns-in:COUNTER:10:0:U \
DS:eolhh:COUNTER:10:0:U \
DS:tnsytdyh:COUNTER:10:0:U \
DS:dns-out:COUNTER:10:0:U \
DS:phylax-block:COUNTER:10:0:U \
DS:phylax-direct:COUNTER:10:0:U \
DS:phylax-proxy-1:COUNTER:10:0:U \
DS:phylax-proxy-2:COUNTER:10:0:U \
DS:phylax-proxy-3:COUNTER:10:0:U \
DS:phylax-proxy-4:COUNTER:10:0:U \
DS:phylax-proxy-5:COUNTER:10:0:U \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
elif [[ -f "/data/shell/Xstats/downlink_traffic.rrd" ]]; then
rrdtool update /data/shell/Xstats/downlink_traffic.rrd N:$(echo -e "$(curl -4sLk -o - http://192.168.1.67:11111/debug/vars | jq -r '.stats | .[] | .[] | .downlink')\n$(curl -4sLk -o - http://cnta.gpst.net.cn:11111/debug/vars | jq -r '.stats | .[] | .[] | .downlink')" | awk '{if(NR<=12){a[NR]=$1}else if(NR>12){a[NR-12]+=$1}}END{for(i=1;i<=12;i++){printf"%d:",a[i]}}' | sed 's/:$//g')
cd /data/shell/Xstats
/opt/rrdtool/bin/rrdtool graph /data/shell/Xstats/downlink_traffic.png \
--start -1800s \
--title '下行连接速率趋势图' \
--vertical-label 'bits/sec' \
--width 1200 \
--height 500 \
--right-axis 1:0 \
--units=si --base=1024 \
-n LEGEND:10:'/usr/share/fonts/TrueType/simhei.ttf' \
-n TITLE:12:'/usr/share/fonts/TrueType/simhei.ttf' \
-n AXIS:10:'/usr/share/fonts/TrueType/simhei.ttf' \
--color BACK#F5F5F5 --color CANVAS#EEE8AA \
HRULE:30000000#FF0000:"30Mbps预警阈值线\n" \
DEF:apollo=downlink_traffic.rrd:apollo:AVERAGE \
DEF:dns-in=downlink_traffic.rrd:dns-in:AVERAGE \
DEF:eolhh=downlink_traffic.rrd:eolhh:AVERAGE \
DEF:tnsytdyh=downlink_traffic.rrd:tnsytdyh:AVERAGE \
DEF:dns-out=downlink_traffic.rrd:dns-out:AVERAGE \
DEF:phylax-block=downlink_traffic.rrd:phylax-block:AVERAGE \
DEF:phylax-direct=downlink_traffic.rrd:phylax-direct:AVERAGE \
DEF:phylax-proxy-1=downlink_traffic.rrd:phylax-proxy-1:AVERAGE \
DEF:phylax-proxy-2=downlink_traffic.rrd:phylax-proxy-2:AVERAGE \
DEF:phylax-proxy-3=downlink_traffic.rrd:phylax-proxy-3:AVERAGE \
DEF:phylax-proxy-4=downlink_traffic.rrd:phylax-proxy-4:AVERAGE \
DEF:phylax-proxy-5=downlink_traffic.rrd:phylax-proxy-5:AVERAGE \
CDEF:apollo_bits=apollo,8,* \
CDEF:dns-in_bits=dns-in,8,* \
CDEF:eolhh_bits=eolhh,8,* \
CDEF:tnsytdyh_bits=tnsytdyh,8,* \
CDEF:dns-out_bits=dns-out,8,* \
CDEF:phylax-block_bits=phylax-block,8,* \
CDEF:phylax-direct_bits=phylax-direct,8,* \
CDEF:phylax-proxy-1_bits=phylax-proxy-1,8,* \
CDEF:phylax-proxy-2_bits=phylax-proxy-2,8,* \
CDEF:phylax-proxy-3_bits=phylax-proxy-3,8,* \
CDEF:phylax-proxy-4_bits=phylax-proxy-4,8,* \
CDEF:phylax-proxy-5_bits=phylax-proxy-5,8,* \
LINE1:apollo_bits#0000FF:'V入站' \
LINE1:dns-in_bits#FF9500:'D入站' \
LINE1:eolhh_bits#FFCC00:'T入站' \
LINE1:tnsytdyh_bits#34C759:'H入站' \
LINE2:dns-out_bits#007AFF:'D出站' \
LINE2:phylax-block_bits#5856D6:'黑洞' \
LINE2:phylax-direct_bits#AF52DE:'直连' \
LINE2:phylax-proxy-1_bits#FF2D55:'A核出站' \
LINE2:phylax-proxy-2_bits#00C7BE:'B核出站' \
LINE2:phylax-proxy-3_bits#8E8E93:'C核出站' \
LINE2:phylax-proxy-4_bits#FF6B6B:'D核出站' \
LINE2:phylax-proxy-5_bits#4CD964:'E核出站\n' \
GPRINT:apollo_bits:MAX:'V入站峰值\: %.2lf %s' \
GPRINT:dns-in_bits:MAX:'D入站峰值\: %.2lf %s' \
GPRINT:eolhh_bits:MAX:'T入站峰值\: %.2lf %s' \
GPRINT:tnsytdyh_bits:MAX:'H入站峰值\: %.2lf %s\n' \
GPRINT:dns-out_bits:MAX:'D出站峰值\: %.2lf %s' \
GPRINT:phylax-block_bits:MAX:'黑洞峰值\: %.2lf %s' \
GPRINT:phylax-direct_bits:MAX:'直连峰值\: %.2lf %s\n' \
GPRINT:phylax-proxy-1_bits:MAX:'A核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-2_bits:MAX:'B核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-3_bits:MAX:'C核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-4_bits:MAX:'D核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-5_bits:MAX:'E核出站峰值\: %.2lf %s\n' \
GPRINT:apollo_bits:AVERAGE:'V入站均值\: %.2lf %s' \
GPRINT:dns-in_bits:AVERAGE:'D入站均值\: %.2lf %s' \
GPRINT:eolhh_bits:AVERAGE:'T入站均值\: %.2lf %s' \
GPRINT:tnsytdyh_bits:AVERAGE:'H入站均值\: %.2lf %s\n' \
GPRINT:dns-out_bits:AVERAGE:'D出站均值\: %.2lf %s' \
GPRINT:phylax-block_bits:AVERAGE:'黑洞均值\: %.2lf %s' \
GPRINT:phylax-direct_bits:AVERAGE:'直连均值\: %.2lf %s\n' \
GPRINT:phylax-proxy-1_bits:AVERAGE:'A核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-2_bits:AVERAGE:'B核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-3_bits:AVERAGE:'C核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-4_bits:AVERAGE:'D核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-5_bits:AVERAGE:'E核出站均值\: %.2lf %s'
fi
if [[ ! -f "/data/shell/Xstats/uplink_traffic.rrd" ]]; then
rrdtool create /data/shell/Xstats/uplink_traffic.rrd \
--step 5 \
DS:apollo:COUNTER:10:0:U \
DS:dns-in:COUNTER:10:0:U \
DS:eolhh:COUNTER:10:0:U \
DS:tnsytdyh:COUNTER:10:0:U \
DS:dns-out:COUNTER:10:0:U \
DS:phylax-block:COUNTER:10:0:U \
DS:phylax-direct:COUNTER:10:0:U \
DS:phylax-proxy-1:COUNTER:10:0:U \
DS:phylax-proxy-2:COUNTER:10:0:U \
DS:phylax-proxy-3:COUNTER:10:0:U \
DS:phylax-proxy-4:COUNTER:10:0:U \
DS:phylax-proxy-5:COUNTER:10:0:U \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797
elif [[ -f "/data/shell/Xstats/uplink_traffic.rrd" ]]; then
rrdtool update /data/shell/Xstats/uplink_traffic.rrd N:$(echo -e "$(curl -4sLk -o - http://192.168.1.67:11111/debug/vars | jq -r '.stats | .[] | .[] | .uplink')\n$(curl -4sLk -o - http://cnta.gpst.net.cn:11111/debug/vars | jq -r '.stats | .[] | .[] | .uplink')" | awk '{if(NR<=12){a[NR]=$1}else if(NR>12){a[NR-12]+=$1}}END{for(i=1;i<=12;i++){printf"%d:",a[i]}}' | sed 's/:$//g')
cd /data/shell/Xstats
/opt/rrdtool/bin/rrdtool graph /data/shell/Xstats/uplink_traffic.png \
--start -1800s \
--title '上行连接速率趋势图' \
--vertical-label 'bits/sec' \
--width 1200 \
--height 500 \
--right-axis 1:0 \
--units=si --base=1024 \
-n LEGEND:10:'/usr/share/fonts/TrueType/simhei.ttf' \
-n TITLE:12:'/usr/share/fonts/TrueType/simhei.ttf' \
-n AXIS:10:'/usr/share/fonts/TrueType/simhei.ttf' \
--color BACK#F5F5F5 --color CANVAS#EEE8AA \
HRULE:10000000#FF0000:"10Mbps预警阈值线\n" \
DEF:apollo=uplink_traffic.rrd:apollo:AVERAGE \
DEF:dns-in=uplink_traffic.rrd:dns-in:AVERAGE \
DEF:eolhh=uplink_traffic.rrd:eolhh:AVERAGE \
DEF:tnsytdyh=uplink_traffic.rrd:tnsytdyh:AVERAGE \
DEF:dns-out=uplink_traffic.rrd:dns-out:AVERAGE \
DEF:phylax-block=uplink_traffic.rrd:phylax-block:AVERAGE \
DEF:phylax-direct=uplink_traffic.rrd:phylax-direct:AVERAGE \
DEF:phylax-proxy-1=uplink_traffic.rrd:phylax-proxy-1:AVERAGE \
DEF:phylax-proxy-2=uplink_traffic.rrd:phylax-proxy-2:AVERAGE \
DEF:phylax-proxy-3=uplink_traffic.rrd:phylax-proxy-3:AVERAGE \
DEF:phylax-proxy-4=uplink_traffic.rrd:phylax-proxy-4:AVERAGE \
DEF:phylax-proxy-5=uplink_traffic.rrd:phylax-proxy-5:AVERAGE \
CDEF:apollo_bits=apollo,8,* \
CDEF:dns-in_bits=dns-in,8,* \
CDEF:eolhh_bits=eolhh,8,* \
CDEF:tnsytdyh_bits=tnsytdyh,8,* \
CDEF:dns-out_bits=dns-out,8,* \
CDEF:phylax-block_bits=phylax-block,8,* \
CDEF:phylax-direct_bits=phylax-direct,8,* \
CDEF:phylax-proxy-1_bits=phylax-proxy-1,8,* \
CDEF:phylax-proxy-2_bits=phylax-proxy-2,8,* \
CDEF:phylax-proxy-3_bits=phylax-proxy-3,8,* \
CDEF:phylax-proxy-4_bits=phylax-proxy-4,8,* \
CDEF:phylax-proxy-5_bits=phylax-proxy-5,8,* \
LINE1:apollo_bits#0000FF:'V入站' \
LINE1:dns-in_bits#FF9500:'D入站' \
LINE1:eolhh_bits#FFCC00:'T入站' \
LINE1:tnsytdyh_bits#34C759:'H入站' \
LINE2:dns-out_bits#007AFF:'D出站' \
LINE2:phylax-block_bits#5856D6:'黑洞' \
LINE2:phylax-direct_bits#AF52DE:'直连' \
LINE2:phylax-proxy-1_bits#FF2D55:'A核出站' \
LINE2:phylax-proxy-2_bits#00C7BE:'B核出站' \
LINE2:phylax-proxy-3_bits#8E8E93:'C核出站' \
LINE2:phylax-proxy-4_bits#FF6B6B:'D核出站' \
LINE2:phylax-proxy-5_bits#4CD964:'E核出站\n' \
GPRINT:apollo_bits:MAX:'V入站峰值\: %.2lf %s' \
GPRINT:dns-in_bits:MAX:'D入站峰值\: %.2lf %s' \
GPRINT:eolhh_bits:MAX:'T入站峰值\: %.2lf %s' \
GPRINT:tnsytdyh_bits:MAX:'H入站峰值\: %.2lf %s\n' \
GPRINT:dns-out_bits:MAX:'D出站峰值\: %.2lf %s' \
GPRINT:phylax-block_bits:MAX:'黑洞峰值\: %.2lf %s' \
GPRINT:phylax-direct_bits:MAX:'直连峰值\: %.2lf %s\n' \
GPRINT:phylax-proxy-1_bits:MAX:'A核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-2_bits:MAX:'B核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-3_bits:MAX:'C核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-4_bits:MAX:'D核出站峰值\: %.2lf %s' \
GPRINT:phylax-proxy-5_bits:MAX:'E核出站峰值\: %.2lf %s' \
GPRINT:apollo_bits:AVERAGE:'V入站均值\: %.2lf %s' \
GPRINT:dns-in_bits:AVERAGE:'D入站均值\: %.2lf %s' \
GPRINT:eolhh_bits:AVERAGE:'T入站均值\: %.2lf %s' \
GPRINT:tnsytdyh_bits:AVERAGE:'H入站均值\: %.2lf %s\n' \
GPRINT:dns-out_bits:AVERAGE:'D出站均值\: %.2lf %s' \
GPRINT:phylax-block_bits:AVERAGE:'黑洞均值\: %.2lf %s' \
GPRINT:phylax-direct_bits:AVERAGE:'直连均值\: %.2lf %s\n' \
GPRINT:phylax-proxy-1_bits:AVERAGE:'A核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-2_bits:AVERAGE:'B核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-3_bits:AVERAGE:'C核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-4_bits:AVERAGE:'D核出站均值\: %.2lf %s' \
GPRINT:phylax-proxy-5_bits:AVERAGE:'E核出站均值\: %.2lf %s'
fi
sleep 5
done

Categories:
系统运维