流量统计sql去掉entrance_id 条件

This commit is contained in:
zhanghongqing
2018-12-09 19:13:47 +08:00
parent 455e4a38a9
commit 27eb0cd6f0
4 changed files with 63 additions and 180 deletions

View File

@@ -23,7 +23,7 @@
<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}
where report_time > DATE_SUB(#{reportTime}, INTERVAL 1 HOUR)
</select>
<!-- 获取带宽最近时间 -->
@@ -32,15 +32,8 @@
</select>
<!-- 根据最近时间条获取带宽,进出口流量 -->
<select id="getNetFlowPortInfoNew" resultType="java.util.HashMap">
SELECT SUM(total_traffic.inoctets) AS inoctets ,SUM(total_traffic.outoctets) AS outoctets FROM (
SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=1
UNION ALL
SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=2
) total_traffic
SELECT IFNULL(SUM(c2s_byte_len),0) AS inoctets ,IFNULL(SUM(s2c_byte_len),0) AS outoctets FROM traffic_trans_statistic
WHERE stat_time > DATE_SUB(#{statTime}, INTERVAL 1 HOUR)
</select>
<!-- 获取近五分钟的带宽根据ip46协议 tcp,udp变化 -->
<select id="getBandwidthTrans" resultMap="BandwidthResultMap">

View File

@@ -17,47 +17,28 @@
</sql>
<!-- 查询最近时间 -->
<select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficAppStatistic">
SELECT stat_time statTime FROM traffic_app_statistic WHERE app_type != 0 order by stat_time desc limit 1
SELECT stat_time statTime FROM traffic_app_statistic order by stat_time desc limit 1
</select>
<select id="appChart" resultType="java.util.HashMap">
SELECT x.appType appType, SUM(x.count) count FROM
( SELECT app_type appType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_app_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_app_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=1
GROUP BY appType
UNION ALL
SELECT app_type appType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_app_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_app_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=2
GROUP BY appType
) x GROUP BY x.appType order by count desc limit 0,10
<select id="appChart" resultType="java.util.HashMap">
SELECT app_type appType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_app_statistic
WHERE stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour)
GROUP BY app_type order by count desc limit 0,10
</select>
<!-- 获取app统计详情 -->
<select id="getAppList" resultType="java.util.HashMap">
SELECT IFNULL(c.app_name,p.appType) appName,p.appType appType,p.linkNum linkNum, p.packets packets, p.GByte GByte FROM (
SELECT x.appType ,SUM(x.link_num) AS linkNum,SUM(x.pkt) AS packets,
(SUM(x.byte)/1024/1024/1024) AS GByte FROM
( SELECT app_type appType,SUM(link_num) link_num,SUM(c2s_byte_len+s2c_byte_len) byte,SUM(c2s_pkt_num+s2c_pkt_num) pkt FROM traffic_app_statistic
where
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB((SELECT stat_time FROM traffic_app_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
SELECT IFNULL(c.app_name,p.app_type) appName,p.app_type appType,p.link_num linkNum, p.packets packets, p.GByte GByte FROM (
SELECT app_type,SUM(link_num) AS link_num,SUM(c2s_pkt_num+s2c_pkt_num) AS packets,
(SUM(c2s_byte_len+s2c_byte_len)/1024/1024/1024) AS GByte
FROM traffic_app_statistic WHERE
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
stat_time >= #{beginTime} and stat_time &lt;= #{endTime}
</if>
and entrance_id=1
GROUP BY appType
UNION ALL
SELECT app_type appType,SUM(link_num) link_num,SUM(c2s_byte_len+s2c_byte_len) byte,SUM(c2s_pkt_num+s2c_pkt_num) pkt FROM traffic_app_statistic
where
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB((SELECT stat_time FROM traffic_app_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
stat_time >= #{beginTime} and stat_time &lt;= #{endTime}
</if>
and entrance_id=2
GROUP BY appType
) x
GROUP BY x.appType ) p
LEFT JOIN ui_code_app_dic c ON p.appType=c.view_code ORDER BY p.GByte DESC
</if>
GROUP BY app_type ) p
LEFT JOIN ui_code_app_dic c ON p.app_type=c.view_code ORDER BY p.GByte DESC
</select>
</mapper>

View File

@@ -19,46 +19,23 @@
<select id="getMaxStatTime" resultType="com.nis.domain.restful.dashboard.TrafficProtocolStatistic">
SELECT stat_time statTime FROM traffic_protocol_statistic WHERE proto_type != 0 order by stat_time desc limit 1
</select>
<select id="protocolChart" resultType="java.util.HashMap">
SELECT x.protoType protoType, SUM(x.count) count FROM
( SELECT proto_type protoType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_protocol_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_protocol_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=1
GROUP BY protoType
UNION ALL
SELECT proto_type protoType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_protocol_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_protocol_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=2
GROUP BY protoType
) x
GROUP BY x.protoType ORDER BY count DESC LIMIT 0, 10
<select id="protocolChart" resultType="java.util.HashMap">
SELECT proto_type protoType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_protocol_statistic WHERE
stat_time > DATE_SUB(#{statTime},INTERVAL 1 hour) GROUP BY proto_type ORDER BY count DESC LIMIT 0, 10
</select>
<select id="getProtocolList" resultType="java.util.HashMap">
SELECT IFNULL(c.protocol_type,p.protoType) protocolType,p.protoType protoType,p.linkNum linkNum, p.packets packets, p.GByte GByte FROM (
SELECT x.protoType ,SUM(x.link_num) AS linkNum,SUM(x.pkt) AS packets,
(SUM(x.byte)/1024/1024/1024) AS GByte FROM
( SELECT proto_type protoType,SUM(link_num) link_num,SUM(c2s_byte_len+s2c_byte_len) byte,SUM(c2s_pkt_num+s2c_pkt_num) pkt FROM traffic_protocol_statistic
where
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB((SELECT stat_time FROM traffic_protocol_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
SELECT IFNULL(c.protocol_type,p.proto_type) protocolType,p.proto_type protoType,p.link_num linkNum, p.packets packets, p.GByte GByte FROM (
SELECT proto_type,SUM(link_num) AS link_num,SUM(c2s_pkt_num+s2c_pkt_num) AS packets,
(SUM(c2s_byte_len+s2c_byte_len)/1024/1024/1024) AS GByte
FROM traffic_protocol_statistic WHERE
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
stat_time >= #{beginTime} and stat_time &lt;= #{endTime}
</if>
and entrance_id=1
GROUP BY protoType
UNION ALL
SELECT proto_type protoType,SUM(link_num) link_num,SUM(c2s_byte_len+s2c_byte_len) byte,SUM(c2s_pkt_num+s2c_pkt_num) pkt FROM traffic_protocol_statistic
where
<if test="beginTime==null or endTime==null">
stat_time > DATE_SUB((SELECT stat_time FROM traffic_protocol_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR)
</if>
<if test="beginTime!=null and endTime!=null">
stat_time >= #{beginTime} and stat_time &lt;= #{endTime}
</if>
and entrance_id=2
GROUP BY protoType
) x
GROUP BY x.protoType ) p
LEFT JOIN ui_code_protocol_type_dic c ON p.protoType=c.view_code ORDER BY p.GByte DESC
</if>
GROUP BY proto_type ) p
LEFT JOIN ui_code_protocol_type_dic c ON p.proto_type=c.view_code ORDER BY p.GByte DESC
</select>
</mapper>

View File

@@ -21,132 +21,64 @@
SELECT stat_time statTime FROM traffic_ua_statistic order by stat_time desc limit 1
</select>
<!--获取操作系统列表TOP10 -->
<select id="systemList" resultMap="BaseResultMap">
SELECT x.osType osType, SUM(x.count) count FROM
( SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=1
GROUP BY osType
UNION ALL
SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=2
GROUP BY osType
) x
GROUP BY x.osType ORDER BY count DESC limit 0,10
<select id="systemList" resultMap="BaseResultMap">
SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE stat_time > DATE_SUB(#{statTime}, INTERVAL 1 HOUR)
GROUP BY os_type ORDER BY count DESC limit 0,10
</select>
<!--获取上个时间段操作系统的数据量 -->
<select id="preSystemListCount" resultType="java.lang.Long">
SELECT SUM(x.count) count FROM
( SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time &lt; DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and os_type=#{osType} and entrance_id=1
and stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 2 HOUR) and os_type=#{osType} and entrance_id=1
GROUP BY osType
UNION ALL
SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time &lt; DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and os_type=#{osType} and entrance_id=2
and stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 2 HOUR) and os_type=#{osType} and entrance_id=2
GROUP BY osType
) x
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE os_type=#{osType}
and stat_time &lt; DATE_SUB(#{statTime},INTERVAL 1 HOUR)
and stat_time > DATE_SUB(#{statTime},INTERVAL 2 HOUR)
</select>
<!-- 根据操作系统获取浏览器分类 -->
<select id="getBrowserBySystem" resultType="java.util.HashMap">
SELECT x.bsType bsType, SUM(x.count) count FROM
( SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and os_type=#{osType} and entrance_id=1
GROUP BY bsType
UNION ALL
SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and os_type=#{osType} and entrance_id=2
GROUP BY bsType
) x
GROUP BY x.bsType ORDER BY count DESC limit 0,10
SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE os_type=#{osType} and stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
GROUP BY bs_type ORDER BY count DESC limit 0,10
</select>
<!--浏览器TOP10后所有为others -->
<select id="systemOthers" resultType="java.util.HashMap">
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM
( SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and os_type=#{osType}
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE bs_type !=0 and os_type=#{osType}
<if test="bsType!=null and bsType.size()>0">
and x.bsType not in
and bs_type not in
<foreach collection="bsType" item="singleType" index="index" open="(" close=")" separator=",">
#{singleType}
</foreach>
</if>
ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and os_type=#{osType} and entrance_id=1
UNION ALL
SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
<if test="bsType!=null and bsType.size()>0">
and x.bsType not in
<foreach collection="bsType" item="singleType" index="index" open="(" close=")" separator=",">
#{singleType}
</foreach>
</if>
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and os_type=#{osType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and os_type=#{osType} and entrance_id=2
) x
and stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
</select>
<!--获取浏览器列表TOP10 -->
<select id="browserList" resultMap="BaseResultMap">
SELECT x.bsType, SUM(x.count) count FROM
( SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=1
GROUP BY bsType
UNION ALL
SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and entrance_id=2
GROUP BY bsType
) x
GROUP BY x.bsType ORDER BY count DESC limit 0,10
SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
GROUP BY bs_type ORDER BY count DESC limit 0,10
</select>
<!--获取上个时间段浏览器的数据量 -->
<select id="preBrowserListCount" resultType="java.lang.Long">
SELECT SUM(x.count) count FROM
( SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time &lt; DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and bs_type=#{bsType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and bs_type=#{bsType} and entrance_id=1
and stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and bs_type=#{bsType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 2 HOUR) and bs_type=#{bsType} and entrance_id=1
GROUP BY bsType
UNION ALL
SELECT bs_type bsType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time &lt; DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and bs_type=#{bsType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and bs_type=#{bsType} and entrance_id=2
and stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and bs_type=#{bsType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 2 HOUR) and bs_type=#{bsType} and entrance_id=2
GROUP BY bsType
) x
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE bs_type=#{bsType}
and stat_time &lt; DATE_SUB(#{statTime},INTERVAL 1 HOUR) and stat_time > DATE_SUB(#{statTime},INTERVAL 2 HOUR)
</select>
<!-- 根据浏览器获取操作系统分类 -->
<select id="getSystemBybrowser" resultType="java.util.HashMap">
SELECT x.osType osType, SUM(x.count) count FROM
( SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and bs_type=#{bsType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and bs_type=#{bsType} and entrance_id=1
GROUP BY osType
UNION ALL
SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and bs_type=#{bsType} ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and bs_type=#{bsType} and entrance_id=2
GROUP BY osType
) x
GROUP BY x.osType ORDER BY count DESC limit 0,10
<select id="getSystemBybrowser" resultType="java.util.HashMap">
SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE bs_type=#{bsType} and stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
GROUP BY os_type ORDER BY count DESC limit 0,10
</select>
<!--操作系统TOP10后所有为others -->
<select id="browserOthers" parameterType="java.util.List" resultType="java.util.HashMap">
SELECT SUM(x.count) count FROM
( SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=1 and bs_type=#{bsType}
SELECT SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
WHERE os_type !=0 and bs_type=#{bsType}
<if test="osType!=null and osType.size()>0">
and os_type not in
<foreach collection="osType" item="singleType" index="index" open="(" close=")" separator=",">
#{singleType}
</foreach>
</if>
ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and bs_type=#{bsType} and entrance_id=1
UNION ALL
SELECT os_type osType, SUM(c2s_byte_len+s2c_byte_len) count FROM traffic_ua_statistic
where stat_time > DATE_SUB((SELECT stat_time FROM traffic_ua_statistic WHERE entrance_id=2 and bs_type=#{bsType}
<if test="osType!=null and osType.size()>0">
and os_type not in
<foreach collection="osType" item="singleType" index="index" open="(" close=")" separator=",">
#{singleType}
</foreach>
</if>
ORDER BY stat_time DESC LIMIT 0,1),INTERVAL 1 HOUR) and bs_type=#{bsType} and entrance_id=2
) x
and stat_time > DATE_SUB(#{statTime},INTERVAL 1 HOUR)
</select>
</mapper>