Hadoop之电信日志数据处理(四)-------web界面实现及可视化效果展示

工具类:

public class DBUtils {
	private static ComboPooledDataSource source = new ComboPooledDataSource();
	
	private DBUtils() {
	}

	public static DataSource getSource(){
		return source;
	}
	
	public static Connection getConn(){
		try {
			return source.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
}

 

servlet类实现:

public class APP01Servlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			//查询日期
			String dateStr = request.getParameter("date");
			System.out.println(dateStr);
			//查询类型
			int type = Integer.parseInt(request.getParameter("type"));
			String sql = null;
			String title = null;
			switch (type) {
				case 1://总流量
					title = "应用大类总流量top10";
					sql = "select " +
							"apptype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(totalTraffic) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";
					break;
				case 2://上行流量
					title = "应用大类上行总流量top10";
					sql = "select " +
							"apptype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(trafficUL) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";
					break;
				case 3://下行流量
					title = "应用大类下行总流量top10";
					sql = "select " +
							"apptype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(trafficDL) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";
					break;
				case 4://尝试次数
					title = "应用大类尝试次数top10";
					sql = "select " +
							"apptype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(attempts) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";
					break;
				case 5://接受次数
					title = "应用大类接受次数top10";
					sql = "select " +
							"apptype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(accepts) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";
					break;
	
				default:
					throw new RuntimeException("未知操作码");
			}
			
			//查询数据库
			QueryRunner runner = new QueryRunner(DBUtils.getSource());
			List<Map<String, Object>> list = runner.query(sql, new MapListHandler());
			
			//处理结果 -- 图例
			StringBuffer legendBuf = new StringBuffer();
			//处理结果 -- 数据
			StringBuffer seriesBuf = new StringBuffer();
			
			int sum = 0;
			for(Map<String,Object> m : list){
				String app01Name = APP01.getName((Integer) m.get("apptype"));
				legendBuf.append("'"+app01Name+"',");
				
				int data = ((BigDecimal) m.get("su")).intValue();
				sum += data;
				seriesBuf.append("{value:"+data+", name:'"+app01Name+"'},");
			}
			String legend = "legend: {orient : 'vertical',x : 'left',data:["+(legendBuf.length() == 0 ? "" : legendBuf.substring(0, legendBuf.length()-1))+"]}";
			String series = "series : [{name:'应用大类',type:'pie',radius : '55%',center: ['50%', '60%'],data:["+(seriesBuf.length() == 0 ? "" : seriesBuf.substring(0,seriesBuf.length()-1))+"]}]";
		  
			
			//整合
			Map<String,String> resultMap = new HashMap<String,String>();
			resultMap.put("date", dateStr);
			resultMap.put("title", 	"title : {text: '"+title+"',subtext: '',x:'center'}");
			resultMap.put("legend", legend);
			resultMap.put("series", series);
			resultMap.put("sum", sum*0.75+"");
			//转发
			request.setAttribute("map", resultMap);
			request.getRequestDispatcher("/app01.jsp").forward(request,response);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}

 

public class APP02Servlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String app01name = new String(request.getParameter("app01name").getBytes("iso8859-1"),"utf-8");
		int app01id = APP01.getId(app01name);
		String dateStr = request.getParameter("date");
		int type = Integer.parseInt(request.getParameter("type"));
		
		try {

			String sql = null;
			String title = null;
			switch (type) {
				case 1://总流量
					title = app01name+"类总流量top10";
					sql = "select " +
							"apptype,appsubtype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(totalTraffic) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,appsubtype,dateid " +
							"having dateid ='"+dateStr+"' and apptype= '"+app01id+"'" +
							"order by su desc " +
							"limit 0,10";
					break;
				case 2://上行流量
					title = app01name+"类上行总流量top10";
					sql = "select " +
							"apptype,appsubtype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(trafficUL) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,appsubtype,dateid " +
							"having dateid ='"+dateStr+"' and apptype= '"+app01id+"'" +
							"order by su desc " +
							"limit 0,10";
					break;
				case 3://下行流量
					title = app01name+"类下行总流量top10";
					sql = "select " +
							"apptype,appsubtype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(trafficDL) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,appsubtype,dateid " +
							"having dateid ='"+dateStr+"' and apptype= '"+app01id+"'" +
							"order by su desc " +
							"limit 0,10";
					break;
				case 4://尝试次数
					title = app01name+"类尝试次数top10";
					sql = "select " +
							"apptype,appsubtype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(attempts) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,appsubtype,dateid " +
							"having dateid ='"+dateStr+"' and apptype= '"+app01id+"'" +
							"order by su desc " +
							"limit 0,10";
					break;
				case 5://接受次数
					title = app01name+"类接受次数top10";
					sql = "select " +
							"apptype,appsubtype,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(accepts) su " +
							"from D_H_HTTP_APPTYPE " +
							"group by apptype,appsubtype,dateid " +
							"having dateid ='"+dateStr+"' and apptype= '"+app01id+"'" +
							"order by su desc " +
							"limit 0,10";
					break;
	
				default:
					throw new RuntimeException("未知操作码");
			}
			
			//查询数据库
			QueryRunner runner = new QueryRunner(DBUtils.getSource());
			List<Map<String, Object>> list = runner.query(sql, new MapListHandler());
			
			//处理结果 -- 图例
			StringBuffer legendBuf = new StringBuffer();
			//处理结果 -- 数据
			StringBuffer seriesBuf = new StringBuffer();
			
			int sum = 0;
			for(Map<String,Object> m : list){
				String app02Name = APP02.getName((Integer) m.get("appsubtype"));
				legendBuf.append("'"+app02Name+"',");
				
				int data = ((BigDecimal) m.get("su")).intValue();
				sum += data;
				seriesBuf.append("{value:"+data+", name:'"+app02Name+"'},");
			}
			String legend = "legend: {orient : 'vertical',x : 'left',data:["+(legendBuf.length() == 0 ? "" : legendBuf.substring(0, legendBuf.length()-1))+"]}";
			String series = "series : [{name:'"+app01name+"类',type:'pie',radius : '55%',center: ['50%', '60%'],data:["+(seriesBuf.length() == 0 ? "" : seriesBuf.substring(0,seriesBuf.length()-1))+"]}]";
		  
			
			//整合
			Map<String,String> resultMap = new HashMap<String,String>();
			resultMap.put("date", dateStr);
			resultMap.put("title", 	"title : {text: '"+title+"',subtext: '',x:'center'}");
			resultMap.put("legend", legend);
			resultMap.put("series", series);
			resultMap.put("sum", sum*0.75+"");
			//转发
			request.setAttribute("map", resultMap);
			request.getRequestDispatcher("/app02.jsp").forward(request,response);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}

 

public class APP03Servlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			//查询日期
			String dateStr = request.getParameter("date");
			//查询类型
			int type = Integer.parseInt(request.getParameter("type"));

			String sql = null;
			String title = null;
			switch (type) {
				case 1://尝试次数
					title = "网站表现尝试次数top10";
					sql = "select " +
							"host,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(attempts) su " +
							"from D_H_HTTP_HOST " +
							"group by host,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";	
					break;
				case 2://接受次数
					title = "网站表现接受次数top10";
					sql = "select " +
							"host,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(accepts) su " +
							"from D_H_HTTP_HOST " +
							"group by host,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";	
					break;
				case 3://总流量
					title = "网站总流量top10";
					sql = "select " +
							"host,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(totaltraffic) su " +
							"from D_H_HTTP_HOST " +
							"group by host,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";	
					break;
				case 4://上行流量
					title = "网站上行流量top10";
					sql = "select " +
							"host,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(trafficUL) su " +
							"from D_H_HTTP_HOST " +
							"group by host,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";	
					break;
				case 5://上行流量
					title = "网站上行流量top10";
					sql = "select " +
							"host,DATE_FORMAT(hourid,'%Y-%m-%d') dateid,sum(trafficDL) su " +
							"from D_H_HTTP_HOST " +
							"group by host,dateid " +
							"having dateid ='"+dateStr+"' " +
							"order by su desc " +
							"limit 0,10";	
					break;

				default:
					throw new RuntimeException("未知操作码");
			}
			
			//查询数据库
			QueryRunner runner = new QueryRunner(DBUtils.getSource());
			List<Map<String, Object>> list = runner.query(sql, new MapListHandler());
			
			//处理结果 -- 横坐标
			StringBuffer xAxisBuf = new StringBuffer();
			
			//处理结果 -- 数据
			StringBuffer seriesBuf = new StringBuffer();
			
			for(Map<String,Object> m : list){
				String hostName = (String) m.get("host");
				xAxisBuf.append("'"+hostName+"',");
				
				int data = ((BigDecimal) m.get("su")).intValue();
				seriesBuf.append("{value:"+data+", name:'"+hostName+"'},");
			}
			String xAxis = "xAxis: {data:["+(xAxisBuf.length() == 0 ? "" : xAxisBuf.substring(0, xAxisBuf.length()-1))+"]}";
			String series = "series : [{name:'网站表现',type:'bar',data:["+(seriesBuf.length() == 0 ? "" : seriesBuf.substring(0,seriesBuf.length()-1))+"]}]";
		  
			
			//整合
			Map<String,String> resultMap = new HashMap<String,String>();
			resultMap.put("date", dateStr);
			resultMap.put("title", 	"title : {text: '"+title+"',subtext: '',x:'center'}");
			resultMap.put("xAxis", xAxis);
			resultMap.put("series", series);
			//转发
			request.setAttribute("map", resultMap);
			request.getRequestDispatcher("/app03.jsp").forward(request,response);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}

 

public class APP04Servlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String hostname = new String(request.getParameter("hostname").getBytes("iso8859-1"),"utf-8");
		String dateStr = request.getParameter("date");
		int type = Integer.parseInt(request.getParameter("type"));
		
		try {

			String sql = null;
			String title = null;
			switch (type) {
				case 1://尝试次数
					title = hostname+"网站尝试次数top10";
					sql = "select " +
							"host,DATE_FORMAT(hourid,'%H') hour,sum(attempts) su " +
							"from D_H_HTTP_HOST " +
							"group by host,hour " +
							"having host ='"+ hostname +"'" +
							"order by su desc ";
					break;
				default:
					throw new RuntimeException("未知操作码");
			}
			
			//查询数据库
			QueryRunner runner = new QueryRunner(DBUtils.getSource());
			List<Map<String, Object>> list = runner.query(sql, new MapListHandler());
			
			//处理结果 -- 横轴
			StringBuffer xAxisBuf = new StringBuffer();
			//处理结果 -- 数据
			StringBuffer seriesBuf = new StringBuffer();
			
			int sum = 0;
			for(Map<String,Object> m : list){
				String hour = (String) m.get("hour");
				xAxisBuf.append("'"+hour+"',");
				
				int data = ((BigDecimal) m.get("su")).intValue();
				seriesBuf.append("{value:"+data+", name:'"+hour+"'},");
			}
			String xAxis = "xAxis: {data:["+(xAxisBuf.length() == 0 ? "" : xAxisBuf.substring(0, xAxisBuf.length()-1))+"]}";
			String series = "series : [{name:'"+hostname+"网站',type:'line',data:["+(seriesBuf.length() == 0 ? "" : seriesBuf.substring(0,seriesBuf.length()-1))+"]}]";
		  
			
			//整合
			Map<String,String> resultMap = new HashMap<String,String>();
			resultMap.put("date", dateStr);
			resultMap.put("title", 	"title : {text: '"+title+"',subtext: '',x:'center'}");
			resultMap.put("xAxis", xAxis);
			resultMap.put("series", series);
			//转发
			request.setAttribute("map", resultMap);
			request.getRequestDispatcher("/app04.jsp").forward(request,response);
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}

 

public class MonitorServlet extends HttpServlet {

	@SuppressWarnings("unused")
	public void doGet(HttpServletRequest request, final HttpServletResponse resp)
			throws ServletException, IOException {
		
		resp.setContentType("text/html;charset=UTF-8");
		
		final CountDownLatch cdl = new CountDownLatch(1);
		ZooKeeper zk =null;
		try {
			if(zk == null){
				zk = new ZooKeeper("192.168.164.129:2181", 2000, new Watcher() {
					public void process(WatchedEvent event) {
						cdl.countDown();
					}
				});
			}
			cdl.await();
			
			List<String> list1 = zk.getChildren("/zebra/engin1", null);
			List<String> list2 = zk.getChildren("/zebra/engin2", null);
			List<String> list = new ArrayList<String>();
			list.addAll(list1);
			list.addAll(list2);
			String s = "";
			for(String str : list){
				s += str;
				s += ",";
			}
			String st = s.substring(0, s.length()-2);
			if(list1!=null && list2 != null){
				resp.getWriter().println(st);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}

前端页面实现请到博客资源处下载

相关jar包:

链接:https://pan.baidu.com/s/1zEyTG_VpjUlw5Nj-tL1K0w 
提取码:joi0 

可视化效果展示:

Hadoop之电信日志数据处理(一)------业务简介

Hadoop之电信日志数据处理(二)------mapreducer端处理

Hadoop之电信日志数据处理(三)------创建数据库及数据收集

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【资源说明】 基于Hadoop实现大数据可视化分析的Web系统源码+项目说明+sql数据库.zip 1.本项目利用Hadoop处理高校无线定位大数据,有效地将位置信息应用于学生时空行为模式挖掘,建立基于精准位置信息的行为数据挖掘计算模型。 2.基于Hadoop计算平台,并实现大数据进行可视化分析的Web系统,采用ssm+mysql技术。 3.利用一些合适的算法实现校园热点区域提取、学生异常轨迹探测、人流迁徙分析及学生时空行为相似性分析推测等功能。  4.基于学校地图API和echarts插件可视化展现。 校园热点区域提取 采用基本的K-means算法,然后在校园地图上使用热力图形式呈现 学生异常轨迹探测 采用地理接口,筛选出不在建筑物范围内的定点。 人流迁徙分析 从wifi定点数据中根据用户特性、时间特性、建筑特性,归纳出有效完整轨迹,之后采用分段轨迹聚类算法,分析校内人员轨迹迁徙状况。 在地图上使用echarts插件里的迁徙图在校园地图上动态呈现校园人群迁徙分布。 学生时空行为相似性分析推测等功能 采用基本的Word2Vec的Skip-Gram模型用于计算人员的基于时空行为的相似人群,根据人员的脱敏信息,进行分析与预测。 使用该算法的主要工作就是基于WiFi定位数据构建自己的“语料库”。 为什么可以采用Word2Vec的Skip-Gram模型的原因: 解决用户时空行为相似问题 一种行为的所有用户(学号) -> 分词处理后一段语言文字 每个用户(学号)-> 每个关键词 用户之间的亲密程度 -> 关键词相近概率 可视化web端项目 特点: 1.实现了在自己指定的地图范围上使用echerts插件,实现热力图,迁徙图。 2.基于wifi定位数据,使用了K-means算法、Word2Vec算法、轨迹分段聚类算法。 3.基于真实数据的课题实践。 4.Hadoop分布式计算的应用。 【备注】 1.项目代码均经过功能验证ok,确保稳定可靠运行。欢迎下载使用体验! 2.主要针对各个计算机相关专业,包括计算机科学、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师、企业员工。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可直接作为毕设、课程设计、大作业、初期项目立项演示等用途。 4.当然也鼓励大家基于此进行二次开发。在使用过程中,如有问题或建议,请及时沟通。 5.期待你能在项目中找到乐趣和灵感,也欢迎你的分享和反馈!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值