工具类:
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
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
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
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
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 list1 = zk.getChildren("/zebra/engin1", null);
List list2 = zk.getChildren("/zebra/engin2", null);
List list = new ArrayList();
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之电信日志数据处理(三)------创建数据库及数据收集