修改v1版本流量统计带宽查询接口从clickhouse中查询

This commit is contained in:
renkaige
2019-05-20 14:26:16 +08:00
parent 8359cf3a2a
commit f862efd378
2 changed files with 77 additions and 11 deletions

View File

@@ -207,6 +207,53 @@ public class DashboardServiceController extends BaseRestController {
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Map resultMap = new 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());
}
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);
resultMap = dashboardService.getBandwidthTransByQuoTaType(beginDate, endDate, searchQuotaType,
searchDirection);
} 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());
}
} finally {
CustomerContextHolder.clearCustomerType();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",
resultMap, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTransThreeOld", method = RequestMethod.GET)
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
public Map<String, ?> trafficBandwidthTransThreeOld(String beginDate, String endDate, String searchQuotaType,
Model model, Integer searchDirection, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Map resultMap = new HashMap();
try {
if (StringUtils.isEmpty(beginDate) && StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar.getInstance();
@@ -235,6 +282,9 @@ public class DashboardServiceController extends BaseRestController {
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",
resultMap, 0);
}
/**
* 流量统计活跃端口统计

View File

@@ -37,6 +37,7 @@ import com.nis.domain.restful.dashboard.TrafficIpActiveStatistic;
import com.nis.domain.restful.dashboard.TrafficPortActiveStatistic;
import com.nis.domain.restful.dashboard.TrafficProtocolStatistic;
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
import com.nis.domain.restful.dashboard.TrafficUaStatistic;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
@@ -44,6 +45,7 @@ import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.StringUtils;
import com.nis.web.dao.IspInfoDao;
import com.nis.web.dao.TrafficReportDao;
import com.nis.web.dao.dashboard.NtcTotalReportDao;
import com.nis.web.dao.dashboard.TrafficAppStatisticDao;
import com.nis.web.dao.dashboard.TrafficAsnStatisticDao;
@@ -76,6 +78,9 @@ public class DashboardService extends BaseService {
public TrafficPortActiveStatisticDao trafficPortActiveStatisticDao;
@Autowired
private IspInfoDao ispInfoDao;
@Autowired
protected TrafficReportService trafficReportService;
// ip地址类型
private final String[] addrTypes = { "4", "6" };
// tcp udp
@@ -309,8 +314,7 @@ public class DashboardService extends BaseService {
/**
* 日期格式字符串转换成时间戳
*
* @param date_str
* 字符串日期
* @param date_str 字符串日期
* @return
*/
@Deprecated
@@ -327,8 +331,7 @@ public class DashboardService extends BaseService {
/**
* 时间戳 换成日期格式字符串转
*
* @param timeStamp
* 1544602212000
* @param timeStamp 1544602212000
* @return
*/
@Deprecated
@@ -1301,6 +1304,22 @@ public class DashboardService extends BaseService {
return fieldType == null ? null : fieldType.split(",");
}
public Map<?, ?> getBandwidthTransByQuoTaType(String beginDate, String endDate, String searchQuotaType,
Integer searchDirection) {
TrafficTransStatisticCK trafficTransStatisticCK = new TrafficTransStatisticCK();
trafficTransStatisticCK.setSearchBusinessType(1);
trafficTransStatisticCK.setBeginDate(beginDate);
trafficTransStatisticCK.setEndDate(endDate);
if (searchQuotaType.toLowerCase().equals("gbps")) {
trafficTransStatisticCK.setSearchQuotaType(1);
} else if (searchQuotaType.toLowerCase().equals("pps")) {
trafficTransStatisticCK.setSearchQuotaType(2);
} else if (searchQuotaType.toLowerCase().equals("linknumber")) {
trafficTransStatisticCK.setSearchQuotaType(3);
}
return trafficReportService.getBandwidthTransByQuoTaType(trafficTransStatisticCK);
}
public Map<String, Map> getBandwidthTransEntrance(String beginDate, String endDate, String searchQuotaType,
Integer searchDirection) throws ParseException {
Map<String, Map> resultMap = new HashMap<String, Map>();
@@ -1782,15 +1801,12 @@ public class DashboardService extends BaseService {
}
return resultMap;
}
public Map getAppBpsTrend(TrafficAppBpsStatistic entity) {
List<TrafficAppBpsStatistic> list = new ArrayList<TrafficAppBpsStatistic>();
list = trafficAppStatisticDao.getAppBpsTrend(entity);
Map resultMap = new HashMap();
Long gbps = 1024l*1024l*1024l*60l;
Long gbps = 1024l * 1024l * 1024l * 60l;
if (!StringUtil.isEmpty(list)) {
Date beginDate = DateUtils.parseDate(entity.getSearchStartTime());
Date endDate = DateUtils.parseDate(entity.getSearchEndTime());
@@ -1919,14 +1935,14 @@ public class DashboardService extends BaseService {
break;
}
c2sList.add(date.getTime());
c2sList.add(c2sNum/60);
c2sList.add(c2sNum / 60);
resultC2sList.add(c2sList);
s2cList.add(date.getTime());
s2cList.add(s2cNum/60);
s2cList.add(s2cNum / 60);
resultS2cList.add(s2cList);
totalList.add(date.getTime());
totalList.add(totalNum/60);
totalList.add(totalNum / 60);
resultTotalList.add(totalList);
// c2sTotal+=c2sNum;