优化Traffic和IP top10趋势图统计功能

This commit is contained in:
zhangdongxu
2018-12-22 21:41:54 +08:00
parent 1ecac8aae8
commit 007e8e14bf
5 changed files with 206 additions and 218 deletions

View File

@@ -17,6 +17,8 @@ public interface NtcTotalReportDao {
List<Map> getTotalReportList(@Param("reportTime") Date reportTime);
List<Map> getNetFlowPortInfoNew(@Param("statTime") Date statTime);
List<TrafficTransStatistic> getBandwidthTrans(@Param("entranceId") Integer entranceId,@Param("beginDate") String beginDate,@Param("endDate") String endDate,@Param("addrType") String addrType,@Param("transType") Integer transType);
List<TrafficTransStatistic> getBandwidthTransIPVx(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
List<TrafficTransStatistic> getBandwidthTransProtocol(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
String getAddrType();
String getTransType();
String getEntranceId();

View File

@@ -39,10 +39,6 @@
SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time = (SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1) and entrance_id=2
) total_traffic
</select>
<!-- 获取近五分钟的带宽根据ip46协议 tcp,udp变化 -->
<!-- <select id="getBandwidthTrans" resultMap="BandwidthResultMap">
@@ -70,6 +66,24 @@
ORDER by time
</select> -->
<!-- 获取近一小时的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTransIPVx" resultMap="BandwidthResultMap">
select addr_type,trans_type,entrance_id,IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time from traffic_trans_statistic
WHERE
<![CDATA[stat_id BETWEEN (select stat_id from traffic_trans_statistic where stat_time >= #{beginDate} order by stat_id limit 1)
and
(select stat_id from traffic_trans_statistic where stat_time < #{endDate} order by stat_id desc limit 1)
]]>
and addr_type in (4,6)
group by addr_type,stat_time ,entrance_id order by stat_time
</select>
<select id="getBandwidthTransProtocol" resultMap="BandwidthResultMap">
select addr_type,trans_type,entrance_id,IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time from traffic_trans_statistic
WHERE stat_id BETWEEN
<![CDATA[(select stat_id from traffic_trans_statistic where stat_time >= #{beginDate} order by stat_id limit 1)
and (select stat_id from traffic_trans_statistic where stat_time < #{endDate} order by stat_id desc limit 1) ]]>
and trans_type in (6,17) group by trans_type,stat_time ,entrance_id order by stat_time
</select>
<select id="getBandwidthTrans" resultMap="BandwidthResultMap">
select IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time time from traffic_trans_statistic
where <![CDATA[stat_time>=#{beginDate} and stat_time<=#{endDate} ]]>
@@ -82,14 +96,6 @@
and entrance_id=#{entranceId}
group by stat_time order by stat_time
</select>
<!-- 获取近一小时的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTrans2" resultMap="BandwidthResultMap">
select addr_type,trans_type,entrance_id,IFNULL((SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024,0) gbps,IFNULL(SUM(c2s_pkt_num+s2c_pkt_num)/300,0) pps,IFNULL(SUM(link_num),0) linkNum, stat_time time from traffic_trans_statistic
where <![CDATA[stat_time<=#{endDate} and stat_time>=#{beginDate}]]>
and addr_type !=0
and trans_type!=0
group by stat_time,addr_type,trans_type order by stat_time
</select>
<select id="getAddrType" resultType="String">
SELECT GROUP_CONCAT(DISTINCT addr_type) FROM traffic_trans_statistic where addr_type!=0

View File

@@ -27,11 +27,19 @@
SELECT stat_time statTime FROM traffic_ip_active_statistic order by stat_time desc limit 1
</select>
<!-- IP流量统计五分钟TOp10-->
<select id="ipActiveChart" resultType="java.util.LinkedHashMap">
<!-- <select id="ipActiveChart" resultType="java.util.LinkedHashMap">
SELECT ip_addr ipAddr, SUM(c2s_byte_len+s2c_byte_len) linkNum FROM traffic_ip_active_statistic
WHERE
<![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate}]]>
GROUP BY ip_addr ORDER BY linkNum DESC limit 0,10
</select>-->
<select id="ipActiveChart" resultType="java.util.LinkedHashMap">
SELECT ip_addr ipAddr,SUM(c2s_byte_len + s2c_byte_len) linkNum FROM traffic_ip_active_statistic WHERE
stat_id BETWEEN
(select stat_id from traffic_ip_active_statistic where<![CDATA[ stat_time >= #{beginDate} order by stat_id limit 1)]]>
AND
(select stat_id from traffic_ip_active_statistic where<![CDATA[ stat_time < #{endDate} order by stat_id desc limit 1)]]>
GROUP BY ip_addr ORDER BY linkNum DESC LIMIT 0,10
</select>
<!-- IP流量统计一小时内每隔五分钟数据-->
@@ -47,10 +55,17 @@
on date_format(p.timestamp,'%Y-%m-%d %H:%i')=date_format(a.min5,'%Y-%m-%d %H:%i')
ORDER by time
</select> -->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
<!--<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select SUM(c2s_byte_len+s2c_byte_len) count ,stat_time time from traffic_ip_active_statistic
WHERE ip_addr=#{ipAddr} and
<![CDATA[ stat_time> #{beginDate} and stat_time<=#{endDate} GROUP BY stat_time]]>
</select> -->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select ip_addr,SUM(c2s_byte_len+s2c_byte_len) count ,stat_time from traffic_ip_active_statistic
WHERE
<![CDATA[ip_addr in (${ipAddr}) and
stat_time>= #{beginDate} and stat_time<#{endDate} GROUP BY stat_time,ip_addr order by stat_time asc]]>
</select>
<!-- IP流量统计一小时-->
<select id="ipActiveOneHour" resultType="java.util.HashMap">