843 lines
33 KiB
Java
843 lines
33 KiB
Java
package com.nis.web.controller.dashboard;
|
|
|
|
import java.lang.reflect.Type;
|
|
import java.math.BigDecimal;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URLEncoder;
|
|
import java.text.DecimalFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import org.apache.http.client.utils.URIBuilder;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import com.beust.jcommander.internal.Maps;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
import com.google.gson.JsonDeserializationContext;
|
|
import com.google.gson.JsonDeserializer;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonParseException;
|
|
import com.google.gson.LongSerializationPolicy;
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.nis.domain.PageLog;
|
|
import com.nis.domain.SysDataDictionaryItem;
|
|
import com.nis.domain.configuration.WebsiteDomainTopic;
|
|
import com.nis.domain.dashboard.TrafficIpActiveStatistic;
|
|
import com.nis.util.CodeDicUtils;
|
|
import com.nis.util.Constants;
|
|
import com.nis.util.DateUtil;
|
|
import com.nis.util.DateUtils;
|
|
import com.nis.util.DictUtils;
|
|
import com.nis.util.StringUtil;
|
|
import com.nis.util.httpclient.HttpClientUtil;
|
|
import com.nis.web.controller.BaseController;
|
|
import com.nis.web.dao.dashboard.codedic.CodeResult;
|
|
@SuppressWarnings("all")
|
|
@Controller
|
|
@RequestMapping("${adminPath}/dashboard/traffic")
|
|
public class TrafficStatisticsInfoController extends BaseController {
|
|
/**
|
|
* rejectNum 封堵数量
|
|
* newUniConn 新建连接数
|
|
* liveConnNum 活跃链接数
|
|
* dropConnNum 丢弃链接数
|
|
*
|
|
*/
|
|
@RequestMapping(value="info")
|
|
@ResponseBody
|
|
public Map ipActive(){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
HashMap<String, Object> m = new HashMap<String, Object>();
|
|
List list = new ArrayList();
|
|
try {
|
|
Double rejectNum=0d;
|
|
Double dropConnNum=0d;
|
|
Double monitorNum=0d;
|
|
Double loopConnNum=0d;
|
|
Double closeConnNum=0d;
|
|
Double newUniConnNum=0d;
|
|
Double inoctetsNum=0d;
|
|
Double outoctetsNum=0d;
|
|
Double bandwidth=0d;
|
|
String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.NTC_TOTAL_REPORT);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
if(fromJsonList!=null&&list!=null&&list.size()>0){
|
|
Map map = (Map) list.get(0);
|
|
rejectNum = (Double) map.get("rejectNum") ;
|
|
monitorNum = (Double) map.get("monitorNum");
|
|
dropConnNum = (Double) map.get("dropConnNum");
|
|
loopConnNum = (Double) map.get("loopConnNum");
|
|
closeConnNum = (Double) map.get("closeConnNum");
|
|
newUniConnNum = (Double) map.get("newUniConnNum");
|
|
inoctetsNum = (Double) map.get("inoctets");
|
|
outoctetsNum = (Double) map.get("outoctets");
|
|
//单位换算 byte->bit/s
|
|
inoctetsNum=(inoctetsNum*8)/(5*60);
|
|
outoctetsNum=(outoctetsNum*8)/(5*60);
|
|
|
|
}
|
|
bandwidth=inoctetsNum+outoctetsNum;
|
|
m.put("rejectNum", rejectNum);
|
|
m.put("monitorNum", monitorNum);
|
|
m.put("loopConnNum", loopConnNum);
|
|
m.put("dropConnNum", dropConnNum);
|
|
m.put("closeConnNum", closeConnNum);
|
|
m.put("newUniConnNum", newUniConnNum);
|
|
|
|
m.put("bandwidth", bandwidth);
|
|
m.put("inoctetsNum", inoctetsNum);
|
|
m.put("outoctetsNum", outoctetsNum);
|
|
|
|
logger.debug("统计流量信息数据"+fromJsonList);
|
|
return m;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("统计流量信息数据错误"+e);
|
|
}
|
|
return m;
|
|
}
|
|
|
|
@RequestMapping(value="bandwidthList")
|
|
public String bandwidthList(Model model){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
model.addAttribute("beginDate", oneHoursAgo);
|
|
model.addAttribute("endDate", now);
|
|
return "/dashboard/trafficBandwidthList";
|
|
}
|
|
/**
|
|
* 流量统计滚动动作查看详情页面
|
|
*/
|
|
@RequestMapping(value={"trafficBlockList","trafficMonitorList"})
|
|
public String serviceBlockList(@RequestParam("searchAction")String searchAction,Model model){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
model.addAttribute("beginDate", oneHoursAgo);
|
|
model.addAttribute("endDate", now);
|
|
model.addAttribute("searchAction", searchAction);
|
|
return "/dashboard/trafficActionTransList";
|
|
}
|
|
/**
|
|
* 根据动作查询entrance趋势 间隔5分钟数据
|
|
*/
|
|
@RequestMapping(value="actionEntranceTrans")
|
|
@ResponseBody
|
|
public List actionTrans(String beginDate,String endDate,@RequestParam("searchAction")String searchAction){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List resultList = new ArrayList();
|
|
String url = Constants.DASHBOARD_URL+Constants.NTC_ACTION_ENTRANCE_REPORT;
|
|
url=url+"?searchAction="+searchAction;
|
|
try {
|
|
url = urlAddDate(url,beginDate,endDate);
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug(searchAction+"动作间隔5分钟数据"+fromJsonList);
|
|
resultList = (ArrayList) fromJsonList.get("data");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error(searchAction+"动作详情数据获取错误"+e);
|
|
resultList.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return resultList;
|
|
}
|
|
/**
|
|
*
|
|
*
|
|
* url路径时间参数格式化
|
|
* @param url
|
|
* @param beginDate
|
|
* @param endDate
|
|
* @return
|
|
* @throws URISyntaxException
|
|
*/
|
|
public String urlAddDate(String url,String beginDate,String endDate) throws URISyntaxException{
|
|
if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
}
|
|
URIBuilder uriBuilder = new URIBuilder(url);
|
|
uriBuilder.addParameter("beginDate",beginDate);
|
|
uriBuilder.addParameter("endDate",endDate);
|
|
return uriBuilder.toString();
|
|
}
|
|
/**
|
|
* 根据ip46,协议tcp,udp查询带宽 间隔5分钟数据
|
|
*/
|
|
@RequestMapping(value="bandwidthTrans")
|
|
@ResponseBody
|
|
public Map bandwidthTrans(String beginDate,String endDate,@RequestParam("addrType")String addrType,@RequestParam("transType")Integer transType){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
Map map = new HashMap();
|
|
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_BANDWIDTH_TRANS;
|
|
if(!StringUtil.isBlank(addrType)){
|
|
url=url+"?addrType="+addrType;
|
|
}
|
|
if(transType!=null){
|
|
url=url+"?transType="+transType;
|
|
}
|
|
try {
|
|
url=urlAddDate(url,beginDate,endDate);
|
|
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug("带宽1小时,间隔5分钟数据"+fromJsonList);
|
|
List list = (ArrayList) fromJsonList.get("data");
|
|
if(!StringUtil.isEmpty(list)){
|
|
map=(Map) list.get(0);
|
|
}
|
|
return map;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("带宽详情数据获取错误"+e);
|
|
}
|
|
return map;
|
|
}
|
|
/**
|
|
* 根据ip46,协议tcp,udp查询带宽 间隔5分钟数据
|
|
*/
|
|
@RequestMapping(value="bandwidthTransTwo")
|
|
@ResponseBody
|
|
public Map bandwidthTransTwo(String beginDate,String endDate,@RequestParam("addrType")String addrType,@RequestParam("transType")Integer transType){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
Map map = new HashMap();
|
|
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_BANDWIDTH_TRANS_TWO;
|
|
if(!StringUtil.isBlank(addrType)){
|
|
url=url+"?addrType="+addrType;
|
|
}
|
|
if(transType!=null){
|
|
url=url+"?transType="+transType;
|
|
}
|
|
try {
|
|
url=urlAddDate(url,beginDate,endDate);
|
|
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug("带宽1小时,间隔5分钟数据"+fromJsonList);
|
|
List list = (ArrayList) fromJsonList.get("data");
|
|
if(!StringUtil.isEmpty(list)){
|
|
map=(Map) list.get(0);
|
|
}
|
|
return map;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("带宽详情数据获取错误"+e);
|
|
}
|
|
return map;
|
|
}
|
|
/**
|
|
* 间隔5分钟数据
|
|
*/
|
|
@RequestMapping(value="bandwidthTransThree")
|
|
@ResponseBody
|
|
public Map bandwidthTransThree(String beginDate,String endDate,String searchQuotaType){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
Map map = new HashMap();
|
|
//String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_BANDWIDTH_TRANS_TWO;
|
|
String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_BANDWIDTH_TRANS_THREE;
|
|
//String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_BANDWIDTH_TRANS_FOUR;
|
|
try {
|
|
url=urlAddDate(url,beginDate,endDate);
|
|
url=url+"&searchQuotaType="+searchQuotaType;
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug("bandwidthTransThree服务查询数据成功");
|
|
Map result = (Map)fromJsonList.get("data");
|
|
return result;
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("带宽详情数据获取错误"+e);
|
|
}
|
|
return map;
|
|
}
|
|
/**
|
|
* 协议类型详细列表
|
|
*/
|
|
@RequestMapping(value="protocolTypeList")
|
|
public String protocolTypeList(Model model){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
model.addAttribute("beginDate", oneHoursAgo);
|
|
model.addAttribute("endDate", now);
|
|
return "/dashboard/trafficProtocolTypeList";
|
|
}
|
|
/**
|
|
* 协议详情统计图跟表
|
|
*/
|
|
@RequestMapping(value="protocolList")
|
|
@ResponseBody
|
|
public List protocolList(Model model,Integer entranceId,Integer[] protoType,@RequestParam(required=false)String beginDate,@RequestParam(required=false)String endDate){
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List list = new ArrayList();
|
|
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_PROTOCOL_LIST;
|
|
try {
|
|
url=urlAddDate(url,beginDate,endDate);
|
|
if(protoType!=null){
|
|
for (Integer dom : protoType) {
|
|
if(dom!=null){
|
|
url=url+"&protoType="+dom;
|
|
}
|
|
}
|
|
}
|
|
if(entranceId!=null){
|
|
url=url+"&entranceId="+entranceId;
|
|
}
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug("协议详情5分钟数据"+fromJsonList);
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
Long totalLink=0l;
|
|
Long totalPackets=0l;
|
|
Double totalGByte=0d;
|
|
DecimalFormat lf = new DecimalFormat("0");
|
|
DecimalFormat df = new DecimalFormat("0.0000000000");
|
|
List<CodeResult> appCodeList = CodeDicUtils.getCodeList("appCode");
|
|
//两个时间段之间的秒数
|
|
double allSeconds = DateUtils.getSecondsOfTwoDate(sdf.parse(beginDate),sdf.parse(endDate));
|
|
if(!StringUtil.isEmpty(list)){
|
|
for (Object object : list) {
|
|
Map m=(Map) object;
|
|
Double value1 = Double.parseDouble(m.get("protoType").toString());
|
|
totalGByte+=Double.parseDouble(m.get("GByte").toString());
|
|
// String linkNum = df.format(m.get("linkNum"));
|
|
m.put("GByte", df.format(m.get("GByte")));
|
|
m.put("packets", lf.format(m.get("packets")));
|
|
m.put("linkNum", lf.format(m.get("linkNum")));
|
|
double avgPacket=Double.parseDouble(m.get("packets").toString())/allSeconds;
|
|
m.put("pps",lf.format(avgPacket));
|
|
double avgByte=Double.parseDouble(m.get("GByte").toString())*1024*1024*1024*8/allSeconds;
|
|
m.put("bps",lf.format(avgByte));
|
|
totalLink+=Long.parseLong( m.get("linkNum").toString());
|
|
totalPackets+=Long.parseLong(m.get("packets").toString());
|
|
// 协议没匹配的匹配app码表
|
|
for (CodeResult code : appCodeList) {
|
|
Double value3 = Double.valueOf(code.getCode());
|
|
if(value1.equals(value3)){
|
|
m.put("protocolType", code.getItem());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
for (Object object : list) {
|
|
Map m=(Map) object;
|
|
m.put("totalLink", totalLink);
|
|
m.put("totalPackets", totalPackets);
|
|
m.put("totalGByte", totalGByte);
|
|
}
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("协议详情数据获取错误"+e);
|
|
list.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return list;
|
|
}
|
|
/**
|
|
* App类型详细列表
|
|
*/
|
|
@RequestMapping(value="appTypeList")
|
|
public String appTypeList(Model model){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
model.addAttribute("beginDate", oneHoursAgo);
|
|
model.addAttribute("endDate", now);
|
|
return "/dashboard/trafficAppTypeList";
|
|
}
|
|
/**
|
|
* App详情统计图跟表
|
|
*/
|
|
@RequestMapping(value="appList")
|
|
@ResponseBody
|
|
public List appList(Integer entranceId,@RequestParam(value="appType",required=false)Integer[] appType,@RequestParam(value="beginDate",required=false)String beginDate,@RequestParam(value="endDate",required=false)String endDate){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List list = new ArrayList();
|
|
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_APP_LIST;
|
|
try {
|
|
url=urlAddDate(url,beginDate,endDate);
|
|
if(appType!=null){
|
|
for (Integer dom : appType) {
|
|
if(dom!=null){
|
|
url=url+"&appType="+dom;
|
|
}
|
|
}
|
|
}
|
|
if(entranceId!=null){
|
|
url=url+"&entranceId="+entranceId;
|
|
}
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug("app详情5分钟数据"+fromJsonList);
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
Long totalLink=0l;
|
|
Long totalPackets=0l;
|
|
Double totalGByte=0d;
|
|
DecimalFormat lf = new DecimalFormat("0");
|
|
DecimalFormat df = new DecimalFormat("0.0000000000");
|
|
//两个时间段之间的秒数
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
double allSeconds = DateUtils.getSecondsOfTwoDate(sdf.parse(beginDate),sdf.parse(endDate));
|
|
if(!StringUtil.isEmpty(list)){
|
|
for (Object object : list) {
|
|
Map m=(Map) object;
|
|
totalGByte+=Double.parseDouble(m.get("GByte").toString());
|
|
// String linkNum = df.format(m.get("linkNum"));
|
|
m.put("GByte", df.format(m.get("GByte")));
|
|
m.put("packets", lf.format(m.get("packets")));
|
|
m.put("linkNum", lf.format(m.get("linkNum")));
|
|
totalLink+=Long.parseLong( m.get("linkNum").toString());
|
|
totalPackets+=Long.parseLong(m.get("packets").toString());
|
|
|
|
double avgPacket=Double.parseDouble(m.get("packets").toString())/allSeconds;
|
|
m.put("pps",lf.format(avgPacket));
|
|
double avgByte=Double.parseDouble(m.get("GByte").toString())*1024*1024*1024*8/allSeconds;
|
|
m.put("bps",lf.format(avgByte));
|
|
}
|
|
for (Object object : list) {
|
|
Map m=(Map) object;
|
|
m.put("totalLink", totalLink);
|
|
m.put("totalPackets", totalPackets);
|
|
m.put("totalGByte", totalGByte);
|
|
}
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("app详情数据获取错误"+e);
|
|
list.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return list;
|
|
}
|
|
/**
|
|
* App趋势界面 独立IP访问数量趋势图
|
|
*/
|
|
@RequestMapping(value="appTrendList")
|
|
public String appTrendList(Model model,String beginDate,String endDate,String appName,Integer appType){
|
|
if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 2);
|
|
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
}
|
|
model.addAttribute("appName", appName);
|
|
model.addAttribute("appType", appType);
|
|
model.addAttribute("beginDate", beginDate);
|
|
model.addAttribute("endDate", endDate);
|
|
return "/dashboard/trafficAppTrendList";
|
|
}
|
|
@RequestMapping("ajaxAppTrend")
|
|
@ResponseBody
|
|
public Map ajaxAppTrend(String beginDate,String endDate,Integer appType,Integer entranceId,Model model){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
Map list = new HashMap();
|
|
try {
|
|
String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_APP_TREND;
|
|
URIBuilder uriBuilder = new URIBuilder(url);
|
|
uriBuilder.addParameter("searchStartTime",beginDate);
|
|
uriBuilder.addParameter("searchEndTime",endDate);
|
|
url=uriBuilder.toString();
|
|
if(appType!=null){
|
|
url=url+"&searchAppId="+appType;
|
|
}
|
|
if(entranceId!=null){
|
|
url=url+"&searchEntranceId="+entranceId;
|
|
}
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
|
logger.debug("app趋势图"+fromJsonList);
|
|
list = (Map) fromJsonList.get("data");
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("app趋势图数据获取错误"+e);
|
|
list.put("error","request_service_failed");
|
|
}
|
|
return list;
|
|
}
|
|
@RequestMapping("ajaxAppTopList")
|
|
@ResponseBody
|
|
public List ajaxAppTopList(String beginDate,String endDate,Integer appType,Integer entranceId,Integer searchQuota,Model model){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List<Map> list = new ArrayList<Map>();
|
|
try {
|
|
String url=Constants.DASHBOARD_URL+Constants.APPCONN_RECORD_TOP100;
|
|
URIBuilder uriBuilder = new URIBuilder(url);
|
|
uriBuilder.addParameter("searchStartTime",beginDate);
|
|
uriBuilder.addParameter("searchEndTime",endDate);
|
|
url=uriBuilder.toString();
|
|
if(appType!=null){
|
|
url=url+"&searchAppId="+appType;
|
|
}
|
|
if(entranceId!=null){
|
|
url=url+"&searchEntranceId="+entranceId;
|
|
}
|
|
if(searchQuota!=null){
|
|
url=url+"&searchQuota="+searchQuota;
|
|
}else{
|
|
url=url+"&searchQuota="+1; // 默认是按照link 排序
|
|
}
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
|
logger.debug("app列表Top100"+fromJsonList);
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
if(list.size()>0) {
|
|
//两个时间段之间的秒数
|
|
DecimalFormat dl = new DecimalFormat("0");
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
double allSeconds = DateUtils.getSecondsOfTwoDate(sdf.parse(beginDate),sdf.parse(endDate));
|
|
for(Map m:list) {
|
|
double avgPacket=Double.parseDouble(m.get("pktNum").toString())/allSeconds;
|
|
m.put("pps",dl.format(avgPacket));
|
|
double avgByte=Double.parseDouble(m.get("byteNum").toString())*8/allSeconds;
|
|
m.put("bps",dl.format(avgByte));
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("app列表Top100"+e);
|
|
list.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* 网址类型列表
|
|
*/
|
|
@RequestMapping("webTypeList")
|
|
public String webTypeList(Model model){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
List<WebsiteDomainTopic> domainList = appCfgService.getDomainDict(new WebsiteDomainTopic());// domain 域名
|
|
model.addAttribute("domainList", domainList);
|
|
model.addAttribute("beginDate", oneHoursAgo);
|
|
model.addAttribute("endDate", now);
|
|
return "/dashboard/trafficWebTypeList";
|
|
}
|
|
@RequestMapping("domainTrans")
|
|
public String domainTrans(Model model,Integer domain,Integer entranceId,String beginDate,String endDate,String domainName){
|
|
|
|
model.addAttribute("domainName", domainName);
|
|
model.addAttribute("domain", domain);
|
|
model.addAttribute("entranceId", entranceId);
|
|
model.addAttribute("beginDate", beginDate);
|
|
model.addAttribute("endDate", endDate);
|
|
return "/dashboard/trafficDomainTrans";
|
|
}
|
|
@RequestMapping("ajaxDomainTrans")
|
|
@ResponseBody
|
|
public List ajaxDomainTrans(String beginDate,String endDate,Integer domain,Integer entranceId,Model model){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List list = new ArrayList();
|
|
try {
|
|
String url=Constants.DASHBOARD_URL+Constants.TRAFFIC_DOMAIN_TRANS;
|
|
url=urlAddDate(url, beginDate, endDate);
|
|
if(domain!=null){
|
|
url=url+"&domain="+domain;
|
|
}
|
|
if(entranceId!=null){
|
|
url=url+"&entranceId="+entranceId;
|
|
}
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
|
logger.debug("活跃域名1小时"+fromJsonList);
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("活跃域名数据获取错误"+e);
|
|
list.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return list;
|
|
}
|
|
/**
|
|
* 网站统计图跟表
|
|
*/
|
|
@RequestMapping(value="websiteList")
|
|
@ResponseBody
|
|
public List websiteList(Integer entranceId,Integer[] domain,Model model,@RequestParam(required=false)String beginDate,@RequestParam(required=false)String endDate){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List list = new ArrayList();
|
|
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_WEBSITELIST_NOTIME;
|
|
try {
|
|
if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 12);
|
|
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
}
|
|
url=urlAddDate(url, beginDate, endDate);
|
|
if(domain!=null){
|
|
for (Integer dom : domain) {
|
|
if(dom!=null){
|
|
url=url+"&domain="+dom;
|
|
}
|
|
}
|
|
}
|
|
if(entranceId!=null){
|
|
url=url+"&entranceId="+entranceId;
|
|
}
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
logger.debug("website接口数据"+fromJsonList);
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
BigDecimal divisor=new BigDecimal(1024*1024*1024);
|
|
DecimalFormat df = new DecimalFormat("0.000000000");
|
|
DecimalFormat dl = new DecimalFormat("0");
|
|
DecimalFormat pf = new DecimalFormat("0.000000000");
|
|
// Double totalLink=0d;
|
|
Double totalGbyte=0d;
|
|
Double totalPackets=0d;
|
|
//两个时间段之间的秒数
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
double allSeconds = DateUtils.getSecondsOfTwoDate(sdf.parse(beginDate),sdf.parse(endDate));
|
|
for (Object object : list) {
|
|
Map m=(Map)object;
|
|
Double count=(Double)m.get("byteCount");
|
|
totalGbyte+=count;
|
|
// totalLink+=(Double)m.get("linkNum");
|
|
totalPackets+=(Double)m.get("pktCount");
|
|
String format = df.format(count/1024/1024/1024);
|
|
m.put("Gbyte", format);
|
|
|
|
double avgPacket=Double.parseDouble(m.get("pktCount").toString())/allSeconds;
|
|
m.put("pps",dl.format(avgPacket));
|
|
double avgByte=Double.parseDouble(m.get("byteCount").toString())*8/allSeconds;
|
|
m.put("bps",dl.format(avgByte));
|
|
}
|
|
List<WebsiteDomainTopic> codeList = appCfgService.getDomainDict(new WebsiteDomainTopic());
|
|
Map<Long, String> map = new HashMap<Long,String>();
|
|
for (WebsiteDomainTopic websiteDomainTopic : codeList) {
|
|
if(!map.containsKey(websiteDomainTopic.getWebsiteServiceId())){
|
|
map.put(websiteDomainTopic.getId(),websiteDomainTopic.getDomain());
|
|
}
|
|
}
|
|
for (Object object : list) {
|
|
Map m=(Map)object;
|
|
// Double perLink = ((Double)m.get("linkNum"))/totalLink;
|
|
// m.put("perLink",pf.format(perLink));
|
|
// Double perPackets = ((Double)m.get("pktCount"))/totalPackets;
|
|
m.put("totalPackets", pf.format(totalPackets));
|
|
// Double perGbyte = ((Double)m.get("byteCount"))/totalGbyte;
|
|
m.put("totalGbyte", pf.format(totalGbyte/1024/1024/1024));
|
|
if(map.containsKey(Long.parseLong(dl.format(m.get("webId"))))){
|
|
m.put("website", map.get(Long.parseLong(dl.format(m.get("webId")))));
|
|
}else{
|
|
m.put("website", dl.format(m.get("webId")));
|
|
}
|
|
}
|
|
Collections.sort(list, new Comparator<Object>() {
|
|
|
|
@Override
|
|
public int compare(Object o1, Object o2) {
|
|
if(o1==null&&o2!=null){
|
|
return 1;
|
|
}
|
|
if(o1!=null&&o2==null){
|
|
return -1;
|
|
}
|
|
if(o1==o2&&o1==null){
|
|
return 0;
|
|
}
|
|
Map m1=(Map)o1;
|
|
Map m2=(Map)o2;
|
|
return -((Double)m1.get("byteCount")).compareTo((Double)m2.get("byteCount"));
|
|
}
|
|
});
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("网站域名数据获取错误"+e);
|
|
list.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* 主题 统计图跟表(目前只有表)
|
|
*/
|
|
@RequestMapping(value="statisticList")
|
|
@ResponseBody
|
|
public List statisticList(Model model,@RequestParam(required=false)String beginDate,@RequestParam(required=false)String endDate){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
List list = new ArrayList();
|
|
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_TOPICLIST;
|
|
Map map=new HashMap();
|
|
try {
|
|
url=urlAddDate(url,beginDate,endDate);
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
|
|
list = (ArrayList) fromJsonList.get("data");
|
|
List<SysDataDictionaryItem> codeList = DictUtils.getDictList("TOPIC");
|
|
Long totalLink=0l;
|
|
Long totalPackets=0l;
|
|
Double totalGByte=0d;
|
|
DecimalFormat lf = new DecimalFormat("0");
|
|
//两个时间段之间的秒数
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
double allSeconds = DateUtils.getSecondsOfTwoDate(sdf.parse(beginDate),sdf.parse(endDate));
|
|
if(!StringUtil.isEmpty(list)){
|
|
for (Object object : list) {
|
|
Map m=(Map) object;
|
|
totalLink+=Long.parseLong(lf.format(m.get("linkNum")));
|
|
totalPackets+=Long.parseLong(lf.format(m.get("packets")));
|
|
totalGByte+=Double.parseDouble(lf.format(m.get("count")));
|
|
double avgPacket=Double.parseDouble(m.get("packets").toString())/allSeconds;
|
|
m.put("pps",lf.format(avgPacket));
|
|
double avgByte=Double.parseDouble(m.get("count").toString())*8/allSeconds;
|
|
m.put("bps",lf.format(avgByte));
|
|
m.remove("domainData");
|
|
Double value1=0d;
|
|
if(StringUtil.isBlank(m.get("topicId").toString())){
|
|
value1=268435455d;
|
|
}else{
|
|
value1 = Double.parseDouble(m.get("topicId").toString());
|
|
}
|
|
for (SysDataDictionaryItem code : codeList) {
|
|
Double value2 = Double.valueOf(code.getItemCode());
|
|
if(value1.equals(value2)){
|
|
m.put("name",code.getItemValue());
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
//将总数据赋值给每个实体 方便计算百分比 如果数据都为空 则不返回给页面展示
|
|
for(int i=list.size()-1;i>=0;i--) {
|
|
Map m2=(Map) list.get(i);
|
|
m2.put("allLink", totalLink);
|
|
m2.put("allPackets",totalPackets);
|
|
m2.put("allGByte", totalGByte);
|
|
long parseLong = Long.parseLong(lf.format(m2.get("linkNum")));
|
|
long parseLong2 = Long.parseLong(lf.format(m2.get("packets")));
|
|
double parseDouble = Double.parseDouble(lf.format(m2.get("count")));
|
|
if(parseLong==0&&parseLong2==0&&parseDouble==0) {
|
|
list.remove(i);
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("协议详情数据获取错误"+e);
|
|
list.add(Maps.newHashMap("error","request_service_failed"));
|
|
}
|
|
return list;
|
|
}
|
|
/**
|
|
* drop, loop,new link,close link,pass,live link
|
|
*/
|
|
@RequestMapping("ntcTotalReportDetail")
|
|
public String ntcTotalReportDetail(Model model,String searchAction){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//鑾峰彇鍒板畬鏁寸殑鏃堕棿
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
model.addAttribute("searchAction", searchAction);
|
|
model.addAttribute("beginDate", oneHoursAgo);
|
|
model.addAttribute("endDate", now);
|
|
return "/dashboard/ntcTotalReportDetailList";
|
|
}
|
|
@RequestMapping("ajaxNtcTotalReportDetail")
|
|
@ResponseBody
|
|
public Map ajaxNtcTotalReportDetail(String beginDate,String endDate,Model model,String searchAction){
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
Map map = new HashMap();
|
|
try {
|
|
String url=Constants.DASHBOARD_URL+Constants.TREND_TOTAL_REPORT;
|
|
if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){
|
|
Calendar cal = Calendar. getInstance ();
|
|
cal.setTime(new Date());
|
|
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间
|
|
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
|
|
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());
|
|
}
|
|
URIBuilder uriBuilder = new URIBuilder(url);
|
|
uriBuilder.addParameter("searchReportStartTime",beginDate);
|
|
uriBuilder.addParameter("searchReportEndTime",endDate);
|
|
url=uriBuilder.toString();
|
|
if(searchAction!=null){
|
|
if("action_drop".equals(searchAction)){
|
|
url=url+"&searchBusinessType="+1;
|
|
}
|
|
if("action_loop".equals(searchAction)){
|
|
url=url+"&searchBusinessType="+2;
|
|
}
|
|
if("new_link".equals(searchAction)){
|
|
url=url+"&searchBusinessType="+3;
|
|
}
|
|
if("close_link".equals(searchAction)){
|
|
url=url+"&searchBusinessType="+4;
|
|
}
|
|
if("pass".equals(searchAction)){
|
|
url=url+"&searchBusinessType="+6;
|
|
}
|
|
if("live_link".equals(searchAction)){
|
|
url=url+"&searchBusinessType="+5;
|
|
}
|
|
}
|
|
|
|
String string = HttpClientUtil.get(url);
|
|
Gson gson = new GsonBuilder().create();
|
|
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
|
|
logger.debug("动作详情统计一小时"+fromJsonList);
|
|
map = (Map) fromJsonList.get("data");
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
logger.error("动作详情统计一小时数据获取错误"+e);
|
|
}
|
|
return map;
|
|
}
|
|
}
|