流量统计新app详情,动作趋势详情统计数接口

This commit is contained in:
zhanghongqing
2018-12-06 17:19:33 +08:00
parent a404fabff2
commit ab5e4cd471
8 changed files with 194 additions and 21 deletions

View File

@@ -13,6 +13,8 @@ public class NtcEntranceReport extends NtcReportEntity<NtcEntranceReport> {
protected Integer entranceId;
protected String searchEntrance;
protected String time;
/**
* @return the entranceId
@@ -42,4 +44,13 @@ public class NtcEntranceReport extends NtcReportEntity<NtcEntranceReport> {
public void setSearchEntrance(String searchEntrance) {
this.searchEntrance = searchEntrance;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}

View File

@@ -26,7 +26,7 @@ import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.DashboardService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
@SuppressWarnings("unchecked")
@RestController
@RequestMapping(value = "${servicePath}/log/v1")
@Api(value = "DashboardServiceController", description = "统计分析图表基本服务接口")
@@ -61,6 +61,30 @@ public class DashboardServiceController extends BaseRestController {
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "业务总量汇聚实时统计数据检索成功",list, 0);
}
/**
* 流量统计info滚动条数据显示 封堵监测回流丢弃详情趋势
*/
@RequestMapping(value = "ntcActionEntranceReport", method = RequestMethod.GET)
@ApiOperation(value = "根据不同动作统计总量汇聚", httpMethod = "GET", notes = "对应流量统计info滚动条动作类型详情数据显示")
public Map<String,?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response,String searchAction) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<HashMap> resultList = dashboardService.getActionTrans(searchAction);
if (resultList!=null&&resultList.size() > 0) {
list = resultList;
}
} catch (Exception e) {
e.printStackTrace();
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error("动作趋势分析统计数据检索失败"+ExceptionUtil.getExceptionMsg(e));
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"动作趋势分析统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "动作趋势分析统计数据检索成功",list, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
*/
@@ -123,7 +147,7 @@ public class DashboardServiceController extends BaseRestController {
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> ipActiveChart = dashboardService.protocolChart();
if (ipActiveChart.size() > 0) {
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveChart);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
}
@@ -148,7 +172,7 @@ public class DashboardServiceController extends BaseRestController {
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> ipActiveList = dashboardService.getProtocolList();
if (ipActiveList.size() > 0) {
if (ipActiveList!=null&&ipActiveList.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveList);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
}
@@ -176,7 +200,7 @@ public class DashboardServiceController extends BaseRestController {
List<LinkedHashMap> list = new ArrayList<LinkedHashMap>();
try {
List<LinkedHashMap> ipActiveChart = dashboardService.ipActiveChart();
if (ipActiveChart.size() > 0) {
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
list = ipActiveChart;
}
} catch (Exception e) {
@@ -200,7 +224,7 @@ public class DashboardServiceController extends BaseRestController {
List<HashMap> list = new ArrayList<HashMap>();
try {
List<HashMap> ipActiveChart = dashboardService.ipActiveOneHour();
if (ipActiveChart.size() > 0) {
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
list = ipActiveChart;
}
} catch (Exception e) {
@@ -213,7 +237,7 @@ public class DashboardServiceController extends BaseRestController {
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "活跃IP统计一个小时的活跃IP检索成功",list, 0);
}
/**
* 活跃IP TOP10 一小时数据
* 活跃IP TOP10 一小时间隔五分钟数据
*/
@RequestMapping(value = "trafficIpActiveFiveMinute", method = RequestMethod.GET)
@ApiOperation(value = "活跃IP最近一个小时的变化趋势统计", httpMethod = "GET", notes = "对最新TOP10的活跃IP在近一个小时的变化情况进行统计")
@@ -224,7 +248,7 @@ public class DashboardServiceController extends BaseRestController {
List<HashMap> list = new ArrayList<HashMap>();
try {
List<HashMap> ipActiveChart = dashboardService.ipActiveFiveMinute();
if (ipActiveChart.size() > 0) {
if (ipActiveChart!=null&&ipActiveChart.size() > 0) {
list = ipActiveChart;
}
} catch (Exception e) {
@@ -248,7 +272,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> appChart = dashboardService.appChart();
if (appChart.size() > 0) {
if (appChart!=null&&appChart.size() > 0) {
list = appChart;
}
} catch (Exception e) {
@@ -260,6 +284,31 @@ public class DashboardServiceController extends BaseRestController {
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App流量统计数据检索成功",list, 0);
}
/**
* App统计详情图与表
*/
@RequestMapping(value="trafficAppList", method = RequestMethod.GET)
@ApiOperation(value = "App统计占比与报表", httpMethod = "GET", notes = "对应App统计详情占比与报表")
public Map<String,?> trafficAppList(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<Map> appList = dashboardService.getAppList();
if (appList!=null&&appList.size() > 0) {
String jsonString = JsonMapper.toJsonString(appList);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
}
} catch (Exception e) {
e.printStackTrace();
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error("App统计图表数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"App统计图表数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App统计图表数据检索成功",
list, 0);
}
@RequestMapping(value = "trafficOsList", method = RequestMethod.GET)
@ApiOperation(value = "操作系统流量分析统计", httpMethod = "GET", notes = "对应终端用户的操作系统列表显示")
public Map<String,?> trafficOsList(Model model, HttpServletRequest request, HttpServletResponse response) {
@@ -268,7 +317,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> osChart = dashboardService.systemList();
if (osChart.size() > 0) {
if (osChart!=null&&osChart.size() > 0) {
list = osChart;
}
} catch (Exception e) {
@@ -289,7 +338,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> osChart = dashboardService.getBrowserBySystem(osType);
if (osChart.size() > 0) {
if (osChart!=null&&osChart.size() > 0) {
list=osChart;
}
} catch (Exception e) {
@@ -309,7 +358,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> bsChart = dashboardService.browserList();
if (bsChart.size() > 0) {
if (bsChart!=null&&bsChart.size() > 0) {
list = bsChart;
}
} catch (Exception e) {
@@ -330,7 +379,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> bsChart = dashboardService.getSystemBybrowser(bsType);
if (bsChart.size() > 0) {
if (bsChart!=null&&bsChart.size() > 0) {
list = bsChart;
}
} catch (Exception e) {
@@ -352,7 +401,7 @@ public class DashboardServiceController extends BaseRestController {
try {
// List<Map> websiteChart = dashboardService.websiteList();
List<Map> websiteChart = dashboardService.getDomainByWebsiteList();
if (websiteChart.size() > 0) {
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
} catch (Exception e) {
@@ -373,7 +422,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> websiteChart = dashboardService.getDomainByWebsiteServiceId(websiteServiceId);
if (websiteChart.size() > 0) {
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
} catch (Exception e) {
@@ -394,7 +443,7 @@ public class DashboardServiceController extends BaseRestController {
List<Map> list = new ArrayList<Map>();
try {
List<Map> websiteChart = dashboardService.getTopicAndDomainList();
if (websiteChart.size() > 0) {
if (websiteChart!=null&&websiteChart.size() > 0) {
list = websiteChart;
}
} catch (Exception e) {

View File

@@ -6,6 +6,7 @@ import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.dashboard.NtcTotalReport;
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
import com.nis.web.dao.MyBatisDao;
@@ -16,4 +17,7 @@ public interface NtcTotalReportDao {
List<Map> getTotalReportList(@Param("reportTime") Date reportTime);
List<Map> getNetFlowPortInfoNew(@Param("statTime") Date statTime);
List<TrafficTransStatistic> getBandwidthTrans(@Param("statTime") Date statTime,@Param("addrType") String addrType,@Param("transType") Integer transType);
Map getEntranceMaxReportTime();
List<NtcEntranceReport> getActionTrans(@Param("reportTime") Date reportTime,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql);
}

View File

@@ -38,8 +38,8 @@
<!-- 获取近五分钟的带宽根据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
(select date_sub(#{statTime},interval @mycnt :=@mycnt + 5 MINUTE) min5
from (SELECT @mycnt:=-5) 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,
@@ -61,4 +61,24 @@
ORDER by time
</select>
<!-- 获取报表最近时间 -->
<select id="getEntranceMaxReportTime" resultType="java.util.HashMap">
SELECT MAX(report_time) reportTime FROM ntc_entrance_report
</select>
<!-- entrance 1,2 ,动作为阻断,近五分钟数据 -->
<select id="getActionTrans" resultType="com.nis.domain.restful.NtcEntranceReport">
select IFNULL(p.sumNum,0) sum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
(select date_sub(#{reportTime},interval @mycnt :=@mycnt + 5 MINUTE) min5
from (SELECT @mycnt:=-5) m, ntc_entrance_report limit 12) a
LEFT JOIN (
SELECT date_format(report_time, '%Y-%m-%d %H:%i') timestamp, SUM(sum) sumNum FROM ntc_entrance_report
WHERE
<![CDATA[${serviceSql}]]>
and entrance_id=#{entranceId}
and report_time > DATE_SUB(#{reportTime}, 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>
</mapper>

View File

@@ -13,4 +13,5 @@ public interface TrafficAppStatisticDao {
TrafficAppStatistic getMaxStatTime();
List<Map> appChart(@Param("statTime")Date statTime);
List<Map> getAppList(@Param("statTime")Date statTime);
}

View File

@@ -24,4 +24,12 @@
WHERE app_type !=0 and stat_time = #{statTime}
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.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 stat_time=#{statTime} 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

@@ -25,7 +25,7 @@
</select>
<select id="getProtocolList" resultType="java.util.HashMap">
SELECT c.protocol_type protocolType,p.proto_type protoType,p.link_num linkNum, p.packets packets, p.GByte GByte FROM (
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 stat_time=#{statTime} GROUP BY proto_type ) p

View File

@@ -1,7 +1,9 @@
package com.nis.web.service.restful;
import com.beust.jcommander.internal.Maps;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.dashboard.*;
import com.nis.util.StringUtils;
import com.nis.web.dao.dashboard.*;
import com.nis.web.service.BaseService;
import com.zdjizhi.utils.StringUtil;
@@ -98,13 +100,74 @@ public class DashboardService extends BaseService{
}
}
m.put("linkNum",linkList);
m.put("gbps",linkList);
m.put("pps",linkList);
m.put("gbps",gbpsList);
m.put("pps",ppsList);
m.put("statTime",timeList);
listMap.add(m);
}
return listMap;
}
/**
* 根据service 动作查询近五分钟变化趋势
* entrance 默认为1,2
*/
public List<HashMap> getActionTrans(String serviceType) {
String sql ="";
String sqlBlock="((service>=16 and service<=40) or (service>=258 and service<=273) or (service=576))"; //阻断
String sqlMonitor="((service>=128 and service<=152) or (service>=384 and service<=513) or (service=592) or (service>=848 and service<=1030) or (service=1152))"; //监测
// 区分动作
if(StringUtils.isNotBlank(serviceType)) {
if(serviceType.equalsIgnoreCase("block")) {
sql=sqlBlock;
}
if(serviceType.equalsIgnoreCase("monitor")) {
sql=sqlMonitor;
}
}
ArrayList<HashMap> listMap=new ArrayList<HashMap>();
List<NtcEntranceReport> entrance1 = new ArrayList<NtcEntranceReport>();
List<NtcEntranceReport> entrance2 = new ArrayList<NtcEntranceReport>();
Map maxReportTime = ntcTotalReportDao.getEntranceMaxReportTime();
if(maxReportTime!=null && maxReportTime.get("reportTime")!=null) {
Date reportTime = (Date) maxReportTime.get("reportTime");
HashMap m1 = new HashMap();
HashMap m2 = new HashMap();
entrance1=ntcTotalReportDao.getActionTrans(reportTime, 1, sql);
entrance2=ntcTotalReportDao.getActionTrans(reportTime, 2, sql);
List timeList = new ArrayList();
List sumList1 = new ArrayList();
List sumList2 = new ArrayList();
// entrance 为1的趋势
if(entrance1!=null&&entrance1.size()>0) {
for (NtcEntranceReport tt : entrance1) {
if(tt.getTime()!=null&&tt.getSum()!=null) {
timeList.add(tt.getTime());
sumList1.add(tt.getSum());
}
}
}
// entrance 为2的趋势
if(entrance2!=null&&entrance2.size()>0) {
for (NtcEntranceReport tt : entrance2) {
if(tt.getTime()!=null&&tt.getSum()!=null) {
// timeList.add(tt.getTime());
sumList2.add(tt.getSum());
}
}
}
m1.put("count",sumList1);//[{time:[],link:[],link2:[]}]
m1.put("statTime",timeList);
m1.put("entranceId",1);
m2.put("count",sumList2);//[{link1:[],time:[],entrance:"1"},]
m2.put("statTime",timeList);
m2.put("entranceId",2);
listMap.add(m1);
listMap.add(m2);
}
return listMap;
}
/**
* 最近活跃端口时间五分钟数据
* @return List
@@ -252,6 +315,11 @@ public class DashboardService extends BaseService{
}
return list;
}
/**
* app应用top10 图
* @return
*/
public List<Map> appChart() {
List<Map> list=new ArrayList<Map>();
TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime();
@@ -267,7 +335,19 @@ public class DashboardService extends BaseService{
}
return list;
}
/**
* App统计报表
* @return
*/
public List<Map> getAppList(){
TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime();
List<Map> list=new ArrayList<Map>();
if(maxStatTime!=null&&maxStatTime.getStatTime()!=null) {
Date statTime = maxStatTime.getStatTime();
list = trafficAppStatisticDao.getAppList(statTime);
}
return list;
}
// 操作系统列表 排名TOP10
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Map> systemList(){