新增流量统计带宽详情接口,查询ipv4,6,tcp,udp条件

This commit is contained in:
zhanghongqing
2018-12-04 11:59:01 +08:00
parent c1ddd76665
commit feb178ef2a
7 changed files with 264 additions and 79 deletions

View File

@@ -7,12 +7,13 @@ import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.restful.dashboard.NtcTotalReport;
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface NtcTotalReportDao {
NtcTotalReport getMaxReportTime();
Map getMaxRecvTime();
Map getMaxStatTime();
List<Map> getTotalReportList(@Param("reportTime") Date reportTime);
List<Map> getNetFlowPortInfoNew(@Param("statTime") Date statTime);
// List<Map> getNetFlowPortInfoOld(@Param("recvTime") Date recvTime);
List<TrafficTransStatistic> getBandwidthTrans(@Param("statTime") Date statTime,@Param("addrType") String addrType,@Param("transType") Integer transType);
}

View File

@@ -1,41 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nis.web.dao.dashboard.NtcTotalReportDao">
<!-- <resultMap id="BaseResultMap" type="com.nis.domain.restful.dashboard.NtcTotalReport">
<resultMap id="BandwidthResultMap" type="com.nis.domain.restful.dashboard.TrafficTransStatistic">
<id column="stat_id" jdbcType="INTEGER" property="statId" />
<result column="app_type" jdbcType="INTEGER" property="appType" />
<result column="addr_type" jdbcType="INTEGER" property="addrType" />
<result column="trans_type" jdbcType="INTEGER" property="transType" />
<result column="entrance_id" jdbcType="INTEGER" property="entranceId" />
<result column="c2s_pkt_num" jdbcType="INTEGER" property="c2sPktNum" />
<result column="s2c_pkt_num" jdbcType="INTEGER" property="s2cPktNum" />
<result column="c2s_byte_len" jdbcType="INTEGER" property="c2sByteLen" />
<result column="s2c_byte_len" jdbcType="INTEGER" property="s2cByteLen" />
<result column="link_num" jdbcType="BIGINT" property="linkNum" />
<result column="c2s_pkt_num" jdbcType="BIGINT" property="c2sPktNum" />
<result column="s2c_pkt_num" jdbcType="BIGINT" property="s2cPktNum" />
<result column="c2s_byte_len" jdbcType="BIGINT" property="c2sByteLen" />
<result column="s2c_byte_len" jdbcType="BIGINT" property="s2cByteLen" />
<result column="stat_time" jdbcType="TIMESTAMP" property="statTime" />
</resultMap> -->
<!-- <select id="appChart" resultType="java.util.HashMap">
SELECT app_type appType, (SUM(c2s_pkt_num)+SUM(s2c_pkt_num)+SUM(c2s_byte_len)+SUM(s2c_byte_len)) count ,(SUM(c2s_pkt_num)+SUM(s2c_pkt_num)) pktNum,(SUM(c2s_byte_len)+SUM(s2c_byte_len)) byteLen FROM traffic_app_statistic
WHERE app_type !=0 and stat_time >= DATE_SUB(NOW(),INTERVAL 5 MINUTE)
GROUP BY app_type order by count desc limit 0,10
</select> -->
<!-- 获取最近时间并且有效 -->
</resultMap>
<!-- 获取取阻断,监测等流量信息最近时间 -->
<select id="getMaxReportTime" resultType="com.nis.domain.restful.dashboard.NtcTotalReport">
SELECT MAX(report_time) reportTime FROM ntc_total_report
</select>
<!-- 获取带宽最近时间并且有效 -->
<select id="getMaxRecvTime" resultType="java.util.HashMap">
SELECT MAX(stat_time) statTime FROM traffic_trans_statistic
</select>
<!-- 根据最近的时间获取阻断,监测等流量信息 -->
<select id="getTotalReportList" resultType="java.util.HashMap">
SELECT SUM(reject_num) rejectNum,SUM(monitor_num) monitorNum,SUM(c2s_pkt_num) c2sPktNum,SUM(s2c_pkt_num) s2cPktNum,SUM(c2s_byte_len) c2sByteLen,SUM(s2c_byte_len) s2cByteLen,SUM(new_uni_conn_num) newUniConnNum,SUM(live_conn_num) liveConnNum,
SUM(drop_conn_num) dropConnNum,SUM(loop_conn_num) loopConnNum FROM ntc_total_report
where report_time = #{reportTime}
</select>
<!-- 获取带宽最近时间 -->
<select id="getMaxStatTime" resultType="java.util.HashMap">
SELECT MAX(stat_time) statTime FROM traffic_trans_statistic
</select>
<!-- 根据最近时间条获取带宽,进出口流量 -->
<select id="getNetFlowPortInfoNew" resultType="java.util.HashMap">
SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time = #{statTime}
</select>
<!-- 获取上个时间段的数据 -->
<!-- <select id="getNetFlowPortInfoOld" resultType="java.util.HashMap">
SELECT IFNULL(SUM(INOCTETS),0) inoctets ,IFNULL(SUM(OUTOCTETS),0) outoctets FROM TRAFFIC_NETFLOW_PORT_INFO
where RECV_TIME = DATE_SUB(#{recvTime},INTERVAL 5 MINUTE)
</select>-->
<!-- 获取近五分钟的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTrans" resultMap="BandwidthResultMap">
select IFNULL(p.gbps,0) gbps,IFNULL(p.pps,0) pps,IFNULL(p.sumNum,0) linkNum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
(select date_sub(#{statTime},interval @mycnt :=@mycnt + 1 MINUTE) min5
from (SELECT @mycnt:=-1) m, traffic_trans_statistic limit 12) a
LEFT JOIN (
SELECT date_format(stat_time, '%Y-%m-%d %H:%i') timestamp,
SUM(link_num)/300 sumNum,
SUM(c2s_pkt_num+s2c_pkt_num)/300 AS pps,
(SUM(c2s_byte_len+s2c_byte_len)*8/300/1024/1024/1024) AS gbps
FROM traffic_trans_statistic
<where>
<if test="addrType != null">
and addr_type=#{addrType}
</if>
<if test="transType != null">
and trans_type=${transType}
</if>
AND stat_time > DATE_SUB(#{statTime,jdbcType=TIMESTAMP}, INTERVAL 1 HOUR)
</where>
GROUP by timestamp
) p
on date_format(p.timestamp,'%Y-%m-%d %H:%i')=date_format(a.min5,'%Y-%m-%d %H:%i')
ORDER by time
</select>
</mapper>

View File

@@ -35,11 +35,11 @@
<!-- IP流量统计一小时内每隔五分钟数据-->
<select id="ipActiveFiveMinute" resultMap="BaseResultMap">
select IFNULL(p.maxNum,0) linkNum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
select IFNULL(p.sumNum,0) linkNum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
(select date_sub(#{statTime},interval @mycnt :=@mycnt + 5 MINUTE) min5
from (SELECT @mycnt:=-5) m, traffic_ip_active_statistic limit 12) a
LEFT JOIN (
SELECT date_format(stat_time, '%Y-%m-%d %H:%i') timestamp, max(link_num) maxNum FROM traffic_ip_active_statistic
SELECT date_format(stat_time, '%Y-%m-%d %H:%i') timestamp, SUM(c2s_byte_len+s2c_byte_len) sumNum FROM traffic_ip_active_statistic
WHERE ip_addr=#{ipAddr} AND stat_time > DATE_SUB(#{statTime,jdbcType=TIMESTAMP}, INTERVAL 1 HOUR)
GROUP by timestamp
) p