流量统计增加活跃IPTOP10一个小时内的趋势,增加一个小时内TOP10最大值,增加接口错误处理

This commit is contained in:
zhanghongqing
2018-10-12 18:12:24 +08:00
parent 2fc5d87067
commit 6195d6042c
9 changed files with 1442 additions and 1228 deletions

View File

@@ -1,9 +1,11 @@
package com.nis.web.controller.dashboard;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -14,12 +16,17 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Maps;
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.reflect.TypeToken;
import com.nis.domain.Page;
import com.nis.domain.PageLog;
import com.nis.domain.SysDataDictionaryItem;
import com.nis.domain.configuration.WebsiteDomainTopic;
@@ -64,6 +71,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("活跃端口数据错误"+e);
list.add(Maps.newHashMap("error","request_service_failed"));
}
return list;
}
@@ -85,9 +93,88 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("活跃IP错误"+e);
list.add(Maps.newHashMap("error","request_service_failed"));
}
return list;
}
/**
* 活跃IP TOP10 一小时 间隔5分钟数据
*/
@RequestMapping(value="ipActiveMinuteList")
@ResponseBody
public List ipActiveMinuteList(){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List list = new ArrayList();
try {
String string = HttpClientUtil.get("http://127.0.0.1:8082/galaxy/service/log/v1/trafficIpActiveFiveMinute");
// String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE);
Gson gson = new GsonBuilder().create();
fromJsonList = gson.fromJson(string, new TypeToken<Map>(){}.getType());
logger.info("活跃IP1小时,间隔5分钟数据"+fromJsonList);
list = (ArrayList) fromJsonList.get("data");
return list;
} catch (Exception e) {
e.printStackTrace();
logger.error("活跃IP数据获取错误"+e);
list.add(Maps.newHashMap("error","request_service_failed"));
}
return list;
}
/**
* 活跃IP详情
* @param request
* @param response
* @param model
* @return
*/
public static Gson getIntGson() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(
new TypeToken<Map<String, Object>>() {
}.getType(),
new JsonDeserializer<Map<String, Object>>() {
@Override
public Map<String, Object> deserialize(
JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Map<String, Object> treeMap = new HashMap<String, Object>();
JsonObject jsonObject = json.getAsJsonObject();
Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
for (Map.Entry<String, JsonElement> entry : entrySet) {
treeMap.put(entry.getKey(), entry.getValue());
}
return treeMap;
}
}).create();
return gson;
}
@RequestMapping(value="ipActiveList")
public String ipActiveList( HttpServletRequest request, HttpServletResponse response, Model model, RedirectAttributes redirectAttributes){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
List<TrafficIpActiveStatistic> ipActiveList = new ArrayList<TrafficIpActiveStatistic>();
String string;
try {
string = HttpClientUtil.get("http://127.0.0.1:8082/galaxy/service/log/v1/trafficIpActiveOneHour");
// String string = HttpClientUtil.get(Constants.DASHBOARD_URL+Constants.TRAFFIC_IPACTIVE);
Gson gson = getIntGson();
fromJsonList = gson.fromJson(string, new TypeToken<Map<String, Object>>(){}.getType());
logger.info("活跃IP1小时"+fromJsonList);
ipActiveList = gson.fromJson(fromJsonList.get("data").toString(), new TypeToken<List<TrafficIpActiveStatistic>>() {}.getType()) ;
} catch (Exception e) {
e.printStackTrace();
logger.error("活跃IP统计错误"+e);
addMessage(redirectAttributes,"request_service_failed");
}
model.addAttribute("ipActiveList", ipActiveList);
return "/dashboard/trafficIpActiveList";
}
/**
* 协议统计
*/
@@ -123,6 +210,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("协议统计错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -161,6 +249,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("app流量分析错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -199,6 +288,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取操作系统列表错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -250,6 +340,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取操作系统下浏览器类型错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -288,6 +379,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取浏览器列表错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -339,6 +431,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("终端用户-获取浏览器下操作系统类型错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -383,6 +476,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("http网站流量分析数据错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -432,6 +526,7 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("http某个网站子域名流量统计错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@@ -498,13 +593,14 @@ public class DashboardController extends BaseController{
} catch (Exception e) {
e.printStackTrace();
logger.error("http网站主题流量分析数据错误"+e);
resultList.add(Maps.newHashMap("error","request_service_failed"));
}
return resultList;
}
@RequestMapping(value="webTypeList")
public String ipActiveList( HttpServletRequest request, HttpServletResponse response, Model model){
public String webTypeList( HttpServletRequest request, HttpServletResponse response, Model model){
PageLog<TrafficIpActiveStatistic> page = new PageLog<TrafficIpActiveStatistic>(request, response);
List list = new ArrayList();
for (int i = 1; i < 10; i++) {
@@ -516,7 +612,7 @@ public class DashboardController extends BaseController{
list.add(ip);
}
page.setList(list);
model.addAttribute("page", page);
model.addAttribute("page", page);
return "/dashboard/trafficWebTypeList";
}
@RequestMapping(value="bandwidthList")
@@ -637,4 +733,41 @@ public class DashboardController extends BaseController{
}
public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a", 10);
map.put("b", "10");
map.put("c", 10L);
map.put("d", "fsaf");
//Gson gson = new Gson();
Gson gson = new GsonBuilder()
/* .registerTypeAdapter(
new TypeToken<Map<String, Object>>() {
}.getType(),
new JsonDeserializer<Map<String, Object>>() {
@Override
public Map<String, Object> deserialize(
JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Map<String, Object> treeMap = new HashMap<String, Object>();
JsonObject jsonObject = json.getAsJsonObject();
Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet();
for (Map.Entry<String, JsonElement> entry : entrySet) {
treeMap.put(entry.getKey(), entry.getValue());
}
return treeMap;
}
})*/.create();
String json = gson.toJson(map);
System.out.println(json);
Map map1 = gson.fromJson(json, Map.class);
Map map2 = gson.fromJson(json, new TypeToken<Map<String, Object>>() {
}.getType());
System.out.println(map2.get("c"));
}
}

View File

@@ -67,6 +67,8 @@ public class TrafficStatisticsInfoController extends BaseController {
Double dropConnNum=0d;
Double monitorNum=0d;
Double loopConnNum=0d;
Double liveConnNum=0d;
Double newUniConnNum=0d;
Double inoctetsNum=0d;
Double outoctetsNum=0d;
Double bandwidth=0d;
@@ -76,6 +78,8 @@ public class TrafficStatisticsInfoController extends BaseController {
monitorNum = (Double) map.get("monitorNum");
dropConnNum = (Double) map.get("dropConnNum");
loopConnNum = (Double) map.get("loopConnNum");
liveConnNum = (Double) map.get("liveConnNum");
newUniConnNum = (Double) map.get("newUniConnNum");
inoctetsNum = (Double) map.get("inoctets");
outoctetsNum = (Double) map.get("outoctets");
//单位换算 byte->bit/s
@@ -88,6 +92,8 @@ public class TrafficStatisticsInfoController extends BaseController {
m.put("monitorNum", monitorNum);
m.put("loopConnNum", loopConnNum);
m.put("dropConnNum", dropConnNum);
m.put("liveConnNum", liveConnNum);
m.put("newUniConnNum", newUniConnNum);
m.put("bandwidth", bandwidth);
m.put("inoctetsNum", inoctetsNum);