帮洪庆提交 内容:网站域名统计详情

This commit is contained in:
tanghao
2018-12-18 03:59:34 +08:00
parent 056289209e
commit 45b1d4b324
8 changed files with 468 additions and 459 deletions

View File

@@ -606,7 +606,7 @@ public class DashboardController extends BaseController{
String domain = wdt.getDomain();
Double domainId = wdt.getId().doubleValue();
Double webId = Double.parseDouble(dataMap.get("webId").toString());
//10个域名之外的为others webId设为-1外
//10个域名之外的为others webId设为-1外
if(dataMap.get("webId").toString().equals("-1")){
dataMap.put("domain", "Others");
break;
@@ -698,92 +698,6 @@ public class DashboardController extends BaseController{
}
return resultList;
}
@RequestMapping(value="webTypeList")
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++) {
TrafficIpActiveStatistic ip = new TrafficIpActiveStatistic();
ip.setId(i);
ip.setIpAddr(3+i+".1.1."+i);
ip.setAreaId("11");
ip.setLinkNum(1212l);
list.add(ip);
}
page.setList(list);
model.addAttribute("page", page);
return "/dashboard/trafficWebTypeList";
}
////////////////////////////////////////test
@RequestMapping(value="showChart")
public String showChart(@ModelAttribute("entry") TrafficIpActiveStatistic entry, Model model){
String ipAddr="1.1.1.1";
TrafficIpActiveStatistic ip=new TrafficIpActiveStatistic();
ArrayList list = new ArrayList();
// chartMap.put("ipAddr", ip.getIpAddr());
HashMap map1 = new HashMap();
HashMap map2 = new HashMap();
HashMap map3 = new HashMap();
HashMap map4 = new HashMap();
map1.put("name", "c2sPktNum");
map1.put("y", ip.getC2sPktNum());
map2.put("name", "s2cPktNum");
map2.put("y", ip.getS2cPktNum());
map3.put("name", "c2sByteLen");
map3.put("y", ip.getC2sByteLen());
map4.put("name", "s2cByteLen");
map4.put("y", ip.getS2cByteLen());
list.add(ip.getC2sPktNum());
list.add(ip.getS2cPktNum());
list.add(ip.getC2sByteLen());
list.add(ip.getS2cByteLen());
// String json = new Gson().toJson();
model.addAttribute("ipAddr",ipAddr);
model.addAttribute("chartMap",list);
return "/dashboard/trafficWebTypeList";
}
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

@@ -256,34 +256,6 @@ public class TrafficStatisticsInfoController extends BaseController {
}
return map;
}
/**
* 间隔5分钟数据
*/
@RequestMapping(value="bandwidthTransThree")
@ResponseBody
public Map bandwidthTransThree(String beginDate,String endDate){
Map<String, Object> fromJsonList = new HashMap<String, Object>();
Map map = new HashMap();
//String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_BANDWIDTH_TRANS_TWO;
//String url="http://192.168.11.78:8080/galaxy/service/log/v1/"+Constants.TRAFFIC_BANDWIDTH_TRANS_THREE;
//String url="http://192.168.11.78:8080/galaxy/service/log/v1/"+Constants.TRAFFIC_BANDWIDTH_TRANS_FOUR;
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);
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;
}
/**
* 协议类型详细列表
*/
@@ -427,24 +399,77 @@ public class TrafficStatisticsInfoController extends BaseController {
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);
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 12);
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_IPACTIVE_ONEHOUR;
String url = "http://localhost:8088/galaxy-service/service/log/v1/trafficDomainTrans";
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("活跃IP1小时"+fromJsonList);
list = (ArrayList) fromJsonList.get("data");
} catch (Exception e) {
e.printStackTrace();
logger.error("活跃IP数据获取错误"+e);
list.add(Maps.newHashMap("error","request_service_failed"));
}
return list;
}
/**
* 网站统计图跟表
*/
@RequestMapping(value="websiteList")
@ResponseBody
public List websiteList(Model model,@RequestParam(required=false)String beginDate,@RequestParam(required=false)String endDate){
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;
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_WEBSITELIST_NOTIME;
// String url = "http://192.168.11.87:8088/galaxy-service/service/log/v1/"+Constants.TRAFFIC_WEBSITELIST;
try {
url=urlAddDate(url,beginDate,endDate);
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){
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>(){}.getType());
@@ -454,15 +479,15 @@ public class TrafficStatisticsInfoController extends BaseController {
DecimalFormat df = new DecimalFormat("0.00");
DecimalFormat dl = new DecimalFormat("0");
DecimalFormat pf = new DecimalFormat("0.00%");
Double totalLink=0d;
// Double totalLink=0d;
Double totalGbyte=0d;
Double totalPackets=0d;
for (Object object : list) {
Map m=(Map)object;
Double count=(Double)m.get("count");
Double count=(Double)m.get("byteCount");
totalGbyte+=count;
totalLink+=(Double)m.get("linkNum");
totalPackets+=(Double)m.get("packets");
// totalLink+=(Double)m.get("linkNum");
totalPackets+=(Double)m.get("pktCount");
String format = df.format(count/1024/1024/1024);
m.put("Gbyte", format);
}
@@ -475,14 +500,16 @@ public class TrafficStatisticsInfoController extends BaseController {
}
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("packets"))/totalPackets;
// Double perLink = ((Double)m.get("linkNum"))/totalLink;
// m.put("perLink",pf.format(perLink));
Double perPackets = ((Double)m.get("pktCount"))/totalPackets;
m.put("perPackets", pf.format(perPackets));
Double perGbyte = ((Double)m.get("count"))/totalGbyte;
Double perGbyte = ((Double)m.get("byteCount"))/totalGbyte;
m.put("perGbyte", pf.format(perGbyte));
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>() {
@@ -500,10 +527,10 @@ public class TrafficStatisticsInfoController extends BaseController {
}
Map m1=(Map)o1;
Map m2=(Map)o2;
if((Double)m1.get("count")==(Double)m2.get("count")){
if((Double)m1.get("byteCount")==(Double)m2.get("byteCount")){
return 0;
}
int result=((Double)m1.get("count")-(Double)m2.get("count"))>0?-1:1;
int result=((Double)m1.get("byteCount")-(Double)m2.get("byteCount"))>0?-1:1;
return result;
}
});
@@ -523,8 +550,9 @@ public class TrafficStatisticsInfoController extends BaseController {
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_TOPIC_AND_DOMAIN_CHART;
String url = Constants.DASHBOARD_URL+Constants.TRAFFIC_TOPICLIST;
//String url = "http://192.168.11.87:8088/galaxy-service/service/log/v1/"+Constants.TRAFFIC_TOPIC_AND_DOMAIN_CHART;
//String url = "http://192.168.11.87:8088/galaxy-service/service/log/v1/"+Constants.TRAFFIC_TOPICLIST;
Map map=new HashMap();
try {
url=urlAddDate(url,beginDate,endDate);
@@ -557,11 +585,18 @@ public class TrafficStatisticsInfoController extends BaseController {
}
}
}
for(Object object2 : list) {
Map m2=(Map) object2;
//将总数据赋值给每个实体 方便计算百分比 如果数据都为空 则不返回给页面展示
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) {