traffic新增接口
This commit is contained in:
@@ -187,6 +187,104 @@ public class DashboardServiceController extends BaseRestController {
|
||||
}
|
||||
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",list, 0);
|
||||
}
|
||||
/**
|
||||
* 根据ip46,协议tcp,udp查询带宽
|
||||
*/
|
||||
@RequestMapping(value = "trafficBandwidthTransThree", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
|
||||
public Map<String,?> trafficBandwidthTransThree(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) {
|
||||
String[] addrTypes=dashboardService.getFiledTypeByName("addr_type");
|
||||
String[] transTypes=dashboardService.getFiledTypeByName("trans_type");
|
||||
long start = System.currentTimeMillis();
|
||||
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
|
||||
Map<String,List<HashMap>> resultMap=new HashMap<String,List<HashMap>>();
|
||||
try {
|
||||
if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) {
|
||||
Calendar cal = Calendar. getInstance ();
|
||||
cal.setTime(new Date());
|
||||
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());//获取到完整的时间
|
||||
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
||||
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());
|
||||
}
|
||||
String addrType=null;
|
||||
Integer transType=null;
|
||||
if(addrTypes!=null){
|
||||
for(int i=0;i<addrTypes.length;i++){
|
||||
addrType=addrTypes[i];
|
||||
List<HashMap> resultList = dashboardService.getBandwidthTrans(addrType, transType,beginDate,endDate);
|
||||
if (resultList!=null&&resultList.size() > 0) {
|
||||
resultMap.put("ipv"+addrType+"Type1", resultList);
|
||||
}
|
||||
|
||||
resultList = dashboardService.getBandwidthTrans2(addrType, transType,beginDate,endDate);
|
||||
if (resultList!=null&&resultList.size() > 0) {
|
||||
resultMap.put("ipv"+addrType+"Type2", resultList);
|
||||
}
|
||||
addrType=null;
|
||||
}
|
||||
}
|
||||
if(transTypes!=null){
|
||||
for(int i=0;i<transTypes.length;i++){
|
||||
transType=Integer.valueOf(transTypes[i]);
|
||||
List<HashMap> resultList = dashboardService.getBandwidthTrans(addrType, transType,beginDate,endDate);
|
||||
if (resultList!=null&&resultList.size() > 0) {
|
||||
resultMap.put("trans"+transType+"Type1", resultList);
|
||||
}
|
||||
resultList = dashboardService.getBandwidthTrans2(addrType, transType,beginDate,endDate);
|
||||
if (resultList!=null&&resultList.size() > 0) {
|
||||
resultMap.put("trans"+transType+"Type2", resultList);
|
||||
}
|
||||
transType=null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:"+e.getMessage());
|
||||
logger.error("带宽实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
|
||||
if (e instanceof RestServiceException) {
|
||||
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
|
||||
"带宽实时统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
|
||||
} else if (e instanceof ServiceRuntimeException) {
|
||||
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
|
||||
"带宽实时统计数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
|
||||
} else {
|
||||
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
|
||||
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
}
|
||||
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",resultMap, 0);
|
||||
}
|
||||
/**
|
||||
* 根据ip46,协议tcp,udp查询带宽
|
||||
*/
|
||||
@RequestMapping(value = "trafficBandwidthTransFour", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
|
||||
public Map<String,?> trafficBandwidthTransFour(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response) {
|
||||
String[] addrTypes=dashboardService.getFiledTypeByName("addr_type");
|
||||
String[] transTypes=dashboardService.getFiledTypeByName("trans_type");
|
||||
long start = System.currentTimeMillis();
|
||||
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
|
||||
Map<String, List<HashMap>> resultMap=new HashMap<String, List<HashMap>>();
|
||||
try {
|
||||
resultMap = dashboardService.getBandwidthTransEntrance(beginDate, endDate);
|
||||
|
||||
} catch (Exception e) {
|
||||
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:"+e.getMessage());
|
||||
logger.error("带宽实时统计数据检索失败:"+ExceptionUtil.getExceptionMsg(e));
|
||||
if (e instanceof RestServiceException) {
|
||||
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
|
||||
"带宽实时统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
|
||||
} else if (e instanceof ServiceRuntimeException) {
|
||||
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
|
||||
"带宽实时统计数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
|
||||
} else {
|
||||
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
|
||||
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
}
|
||||
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",resultMap, 0);
|
||||
}
|
||||
/**
|
||||
* 流量统计活跃端口统计
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,10 @@ 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);
|
||||
|
||||
String getAddrType();
|
||||
String getTransType();
|
||||
String getEntranceId();
|
||||
List<TrafficTransStatistic> getBandwidthTrans2(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
|
||||
Map getEntranceMaxReportTime();
|
||||
List<NtcEntranceReport> getActionTrans(@Param("beginDate") String beginDate,@Param("endDate") String endDate ,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql);
|
||||
}
|
||||
@@ -82,8 +82,24 @@
|
||||
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
|
||||
</select>
|
||||
<select id="getTransType" resultType="String">
|
||||
SELECT GROUP_CONCAT(DISTINCT trans_type) FROM traffic_trans_statistic where trans_type!=0
|
||||
</select>
|
||||
<select id="getEntranceId" resultType="String">
|
||||
SELECT GROUP_CONCAT(DISTINCT entrance_id) FROM traffic_trans_statistic where entrance_id!=0
|
||||
</select>
|
||||
<!-- 获取报表最近时间 -->
|
||||
<select id="getEntranceMaxReportTime" resultType="java.util.HashMap">
|
||||
SELECT report_time reportTime FROM ntc_entrance_report order by report_time desc limit 1
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@Service
|
||||
public class DashboardService extends BaseService {
|
||||
@@ -1063,5 +1064,126 @@ public List<Map> getTopicTop10(){
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
public String [] getFiledTypeByName(String fieldName){
|
||||
if(fieldName==null){
|
||||
return null;
|
||||
}
|
||||
String fieldType=null;
|
||||
if("addr_type".equals(fieldName)){
|
||||
fieldType= ntcTotalReportDao.getAddrType();
|
||||
}
|
||||
if("trans_type".equals(fieldName)){
|
||||
fieldType= ntcTotalReportDao.getTransType();
|
||||
}
|
||||
if("entrance_id".equals(fieldName)){
|
||||
fieldType= ntcTotalReportDao.getEntranceId();
|
||||
}
|
||||
return fieldType==null?null:fieldType.split(",");
|
||||
}
|
||||
public Map<String,List<HashMap>> getBandwidthTransEntrance(String beginDate,String endDate) {
|
||||
long start = System.currentTimeMillis();
|
||||
Map<String,List<TrafficTransStatistic>> listMap = new HashMap<String,List<TrafficTransStatistic>>();
|
||||
List<TrafficTransStatistic> bandwidthList = new ArrayList<TrafficTransStatistic>();
|
||||
bandwidthList = ntcTotalReportDao.getBandwidthTrans2(beginDate,endDate);
|
||||
String[] addrTypes=getFiledTypeByName("addr_type");
|
||||
String[] transTypes=getFiledTypeByName("trans_type");
|
||||
String[] entranceIds = getFiledTypeByName("entrance_id");
|
||||
for (String entranceId : entranceIds) {
|
||||
for (String addrType : addrTypes) {
|
||||
listMap.put("ipv"+addrType+"Type"+entranceId, new ArrayList<TrafficTransStatistic>());
|
||||
}
|
||||
}
|
||||
for (String entranceId : entranceIds) {
|
||||
for (String transType : transTypes) {
|
||||
listMap.put("trans"+transType+"Type"+entranceId, new ArrayList<TrafficTransStatistic>());
|
||||
}
|
||||
}
|
||||
for (TrafficTransStatistic tts : bandwidthList) {
|
||||
String addrType = tts.getAddrType();
|
||||
Integer entranceId = tts.getEntranceId();
|
||||
Integer transType = tts.getTransType();
|
||||
String key1="ipv"+addrType+"Type"+entranceId;
|
||||
String key2="trans"+transType+"Type"+entranceId;
|
||||
listMap.get(key1).add(tts);
|
||||
listMap.get(key2).add(tts);
|
||||
}
|
||||
Map<String,List<HashMap>> resultMap=new HashMap<String,List<HashMap>>();
|
||||
Set<Entry<String,List<TrafficTransStatistic>>> entrySet = listMap.entrySet();
|
||||
for (Entry<String, List<TrafficTransStatistic>> entry : entrySet) {
|
||||
String key = entry.getKey();
|
||||
String entranceId = key.substring(key.length()-1);
|
||||
List<TrafficTransStatistic> value = entry.getValue();
|
||||
HashMap newData = getNewData(beginDate, endDate, value);
|
||||
newData.put("entranceId", entranceId);
|
||||
ArrayList<HashMap> resultList = new ArrayList<HashMap>();
|
||||
resultList.add(newData);
|
||||
resultMap.put(key, resultList);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private HashMap getNewData(String beginDate, String endDate, List<TrafficTransStatistic> bandwidthList) {
|
||||
HashMap resulMap = new HashMap();
|
||||
List timeList = new ArrayList();
|
||||
List linkList = new ArrayList();
|
||||
List gbpsList = new ArrayList();
|
||||
List ppsList = new ArrayList();
|
||||
if (bandwidthList != null && bandwidthList.size() > 0) {
|
||||
Map<String, Comparable> m= new HashMap<String, Comparable>();
|
||||
int inter=1000*60*5;// 间隔时间为五分钟
|
||||
// 开始时间,结束时间 时间戳
|
||||
Long b = dateToStamp(beginDate);
|
||||
Long e = dateToStamp(endDate);
|
||||
int num=0;
|
||||
Long pointTime=b;
|
||||
while(pointTime<e){
|
||||
|
||||
Long sumL=0l;
|
||||
Long sumP=0l;
|
||||
Long sumG=0l;
|
||||
if(pointTime>=e){
|
||||
break; //停止
|
||||
}
|
||||
for (TrafficTransStatistic tt : bandwidthList) {
|
||||
// 实际时间
|
||||
String time= tt.getTime();
|
||||
Long t = dateToStamp(time);
|
||||
if(t>=pointTime&&t<pointTime+inter){
|
||||
// 范围之内分到此pointTime组
|
||||
sumL=sumL+ tt.getLinkNum();
|
||||
sumP=sumP+ tt.getPps();
|
||||
sumG=sumG+ tt.getGbps();
|
||||
}
|
||||
}
|
||||
// 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会
|
||||
if(pointTime>=e-inter&&sumL>0) {
|
||||
linkList.add(sumL);
|
||||
}
|
||||
if(pointTime>=e-inter&&sumP>0) {
|
||||
ppsList.add(sumP);
|
||||
}
|
||||
if(pointTime>=e-inter&&sumG>0) {
|
||||
gbpsList.add(sumG);
|
||||
}
|
||||
if(pointTime>=e-inter&&(sumL>0||sumG>0||sumP>0)) {
|
||||
timeList.add(stampToDate(pointTime));
|
||||
}
|
||||
if(pointTime<e-inter) {
|
||||
timeList.add(stampToDate(pointTime));
|
||||
linkList.add(sumL);
|
||||
gbpsList.add(sumG);
|
||||
ppsList.add(sumP);
|
||||
}
|
||||
|
||||
num=num+1;
|
||||
pointTime =b+inter*num;
|
||||
}
|
||||
resulMap.put("linkNum", linkList);
|
||||
resulMap.put("gbps", gbpsList);
|
||||
resulMap.put("pps", ppsList);
|
||||
resulMap.put("statTime", timeList);
|
||||
}
|
||||
return resulMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user