流量统计增加活跃IPtop10在一小时的数据统计,活跃iptop10在一小时内最大值数据统计
This commit is contained in:
@@ -2,7 +2,9 @@ package com.nis.domain.restful.dashboard;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.nis.domain.BaseEntity;
|
||||
import com.nis.util.JsonDateSerializer;
|
||||
|
||||
public class TrafficIpActiveStatistic extends BaseEntity<TrafficIpActiveStatistic> {
|
||||
/**
|
||||
@@ -28,6 +30,17 @@ public class TrafficIpActiveStatistic extends BaseEntity<TrafficIpActiveStatisti
|
||||
|
||||
private Date statTime;
|
||||
|
||||
private String time;
|
||||
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Integer getStatId() {
|
||||
return statId;
|
||||
}
|
||||
@@ -91,7 +104,7 @@ public class TrafficIpActiveStatistic extends BaseEntity<TrafficIpActiveStatisti
|
||||
public void setS2cByteLen(Long s2cByteLen) {
|
||||
this.s2cByteLen = s2cByteLen;
|
||||
}
|
||||
|
||||
@JsonSerialize(using = JsonDateSerializer.class)
|
||||
public Date getStatTime() {
|
||||
return statTime;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "业务总量汇聚实时统计数据检索失败");
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "活跃端口实时统计数据检索失败");
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "协议统计图表数据检索失败");
|
||||
}
|
||||
@@ -145,7 +145,59 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "活跃IP实时统计数据检索失败");
|
||||
}
|
||||
throw ((RestServiceException) e);
|
||||
}
|
||||
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP实时统计数据检索成功",list, 0);
|
||||
}
|
||||
/**
|
||||
* 活跃IP TOP10 一小时数据
|
||||
*/
|
||||
@RequestMapping(value = "trafficIpActiveOneHour", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "活跃IP统计一个小时的活跃IP", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。")
|
||||
public Map<String,?> trafficIpActiveOneHour(Model model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
|
||||
List<HashMap> list = new ArrayList<HashMap>();
|
||||
try {
|
||||
List<HashMap> ipActiveChart = dashboardService.ipActiveOneHour();
|
||||
if (ipActiveChart.size() > 0) {
|
||||
list = ipActiveChart;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "活跃IP实时统计数据检索失败");
|
||||
}
|
||||
throw ((RestServiceException) e);
|
||||
}
|
||||
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP实时统计数据检索成功",list, 0);
|
||||
}
|
||||
/**
|
||||
* 活跃IP TOP10 一小时数据
|
||||
*/
|
||||
@RequestMapping(value = "trafficIpActiveFiveMinute", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "活跃IP统计最近五分钟TOP10在近一个小时间隔五分钟的活跃IP数据", httpMethod = "GET", notes = "对应活跃IP实时统计查询服务。")
|
||||
public Map<String,?> trafficIpActiveFiveMinute(Model model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
|
||||
List<HashMap> list = new ArrayList<HashMap>();
|
||||
try {
|
||||
List<HashMap> ipActiveChart = dashboardService.ipActiveFiveMinute();
|
||||
if (ipActiveChart.size() > 0) {
|
||||
list = ipActiveChart;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "活跃IP实时统计数据检索失败");
|
||||
}
|
||||
@@ -171,7 +223,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "App流量统计数据检索失败");
|
||||
}
|
||||
@@ -193,7 +245,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "操作系统流量分析统计检索失败");
|
||||
}
|
||||
@@ -216,7 +268,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "操作系统下浏览器分类统计数据检索失败");
|
||||
}
|
||||
@@ -238,7 +290,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "浏览器流量分析统计数据检索失败");
|
||||
}
|
||||
@@ -261,7 +313,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "浏览器下操作系统流量统计数据检索失败");
|
||||
}
|
||||
@@ -285,7 +337,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "网站流量分析统计数据检索失败");
|
||||
}
|
||||
@@ -308,7 +360,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "http网站分类分析数据检索失败");
|
||||
}
|
||||
@@ -331,7 +383,7 @@ public class DashboardServiceController extends BaseRestController {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
logger.error(e);
|
||||
logger.error("流量统计接口服务错误"+e);
|
||||
if (!(e instanceof RestServiceException)) {
|
||||
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "http网站主题分类分析数据检索失败");
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
package com.nis.web.dao.dashboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import com.nis.domain.restful.dashboard.TrafficIpActiveStatistic;
|
||||
import com.nis.web.dao.MyBatisDao;
|
||||
|
||||
@MyBatisDao
|
||||
public interface TrafficIpActiveStatisticDao {
|
||||
|
||||
List<TrafficIpActiveStatistic> getList(TrafficIpActiveStatistic trafficIpActiveStatistic);
|
||||
List<TrafficIpActiveStatistic> getIpList(TrafficIpActiveStatistic trafficIpActiveStatistic);
|
||||
|
||||
ArrayList<TrafficIpActiveStatistic> ipActiveFiveMinute(@Param("ipAddr") String ipAddr);
|
||||
|
||||
ArrayList<HashMap> ipActiveOneHour(@Param("ipAddr") String ipAddr);
|
||||
|
||||
ArrayList<LinkedHashMap> ipActiveChart();
|
||||
}
|
||||
@@ -17,16 +17,37 @@
|
||||
stat_time
|
||||
</sql>
|
||||
<!-- 活跃IPTOP列表 -->
|
||||
<select id="getList" resultMap="BaseResultMap">
|
||||
<select id="getIpList" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from galaxy.traffic_ip_active_statistic
|
||||
</select>
|
||||
|
||||
<!-- IP流量统计-->
|
||||
<!-- IP流量统计一小时内每隔五分钟数据-->
|
||||
<select id="ipActiveFiveMinute" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select IFNULL(p.maxNum,0) linkNum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
|
||||
(select date_sub(date_format((select MAX(stat_time) from traffic_ip_active_statistic), '%Y-%m-%d %H:%i' ),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
|
||||
WHERE ip_addr=#{ipAddr} AND stat_time > DATE_SUB((select MAX(stat_time) from traffic_ip_active_statistic), INTERVAL 1 HOUR)
|
||||
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>
|
||||
<!-- IP流量统计一小时-->
|
||||
<select id="ipActiveOneHour" parameterType="java.lang.String" resultType="java.util.HashMap">
|
||||
SELECT ip_addr ipAddr,area_id areaId, link_num linkNum ,c2s_pkt_num c2sPktNum,s2c_pkt_num s2cPktNum,c2s_byte_len c2sByteLen,s2c_byte_len s2cByteLen,date_format(stat_time, '%Y-%m-%d %H:%i:%s') statTime FROM galaxy.traffic_ip_active_statistic
|
||||
WHERE ip_addr=#{ipAddr}
|
||||
and stat_time > DATE_SUB((SELECT MAX(stat_time) FROM galaxy.traffic_ip_active_statistic),INTERVAL 1 HOUR)
|
||||
ORDER BY linkNum DESC LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- IP流量统计五分钟-->
|
||||
<select id="ipActiveChart" resultType="java.util.LinkedHashMap">
|
||||
SELECT ip_addr ipAddr, SUM(link_num) linkNum ,(SUM(c2s_pkt_num)+SUM(s2c_pkt_num)) pktNum,(SUM(c2s_byte_len)+SUM(s2c_byte_len)) byteLen FROM galaxy.traffic_ip_active_statistic
|
||||
WHERE stat_time >= DATE_SUB((SELECT MAX(stat_time) FROM galaxy.traffic_ip_active_statistic),INTERVAL 5 MINUTE)
|
||||
WHERE stat_time > DATE_SUB((SELECT MAX(stat_time) FROM galaxy.traffic_ip_active_statistic),INTERVAL 5 MINUTE)
|
||||
GROUP BY ip_addr ORDER BY linkNum DESC limit 0,10
|
||||
</select>
|
||||
|
||||
|
||||
@@ -84,14 +84,59 @@ public class DashboardService extends BaseService{
|
||||
* 分页查询活跃IPtop100
|
||||
* @return
|
||||
*/
|
||||
public Page<TrafficIpActiveStatistic> getList(Page<TrafficIpActiveStatistic> page,TrafficIpActiveStatistic entry){
|
||||
public Page<TrafficIpActiveStatistic> getIpList(Page<TrafficIpActiveStatistic> page,TrafficIpActiveStatistic entry){
|
||||
// 设置分页参数
|
||||
entry.setPage(page);
|
||||
// 执行分页查询
|
||||
page.setList(trafficIpActiveStatisticDao.getList(entry));
|
||||
page.setList(trafficIpActiveStatisticDao.getIpList(entry));
|
||||
return page;
|
||||
}
|
||||
public List<HashMap> ipActiveFiveMinute(){
|
||||
|
||||
ArrayList<LinkedHashMap> list = trafficIpActiveStatisticDao.ipActiveChart();
|
||||
ArrayList<HashMap> listMap=new ArrayList<HashMap>();
|
||||
if(list!=null&&list.size()>0) {
|
||||
for (LinkedHashMap map : list) {
|
||||
HashMap m = new HashMap();
|
||||
if(map.get("ipAddr")!=null) {
|
||||
String ipAddr = (String) map.get("ipAddr");
|
||||
m.put("ipAddr", ipAddr);
|
||||
ArrayList<TrafficIpActiveStatistic> ipList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipAddr);
|
||||
List linkList = new ArrayList();
|
||||
List timeList = new ArrayList();
|
||||
if(ipList!=null&&ipList.size()>0) {
|
||||
for (TrafficIpActiveStatistic ip : ipList) {
|
||||
if(ip.getLinkNum()!=null&&ip.getTime()!=null) {
|
||||
linkList.add(ip.getLinkNum());
|
||||
timeList.add(ip.getTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
m.put("linkNum",linkList);
|
||||
m.put("statTime",timeList);
|
||||
listMap.add(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return listMap;
|
||||
}
|
||||
public List<HashMap> ipActiveOneHour(){
|
||||
|
||||
ArrayList<LinkedHashMap> list = trafficIpActiveStatisticDao.ipActiveChart();
|
||||
ArrayList<HashMap> listMap=new ArrayList<HashMap>();
|
||||
if(list!=null&&list.size()>0) {
|
||||
for (LinkedHashMap map : list) {
|
||||
if(map.get("ipAddr")!=null) {
|
||||
String ipAddr = (String) map.get("ipAddr");
|
||||
ArrayList<HashMap> iplList = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr);
|
||||
listMap.add(iplList.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return listMap;
|
||||
}
|
||||
public List<LinkedHashMap> ipActiveChart(){
|
||||
|
||||
ArrayList<LinkedHashMap> list = trafficIpActiveStatisticDao.ipActiveChart();
|
||||
|
||||
Reference in New Issue
Block a user