Hadoop自定义JobTracker和NameNode管理页面
为了可以方便地在hadoop的管理界面(namenode和jobtracker)中自定义展示项,使用代理servlet的方式实现了hadoop的管理界面。
首先,
在org.apache.hadoop.http.HttpServer中的构造函数public HttpServer(String name, String bindAddress, int port,boolean findPort, Configuration conf, AccessControlList adminsAcl,Connector connector)中添加如下代码,指定资源包和url前缀:
ServletHolder servletHoder = new ServletHolder();
servletHoder.setInitParameter("com.sun.jersey.config.property.packages","com.test.agent");
servletHoder.setServlet(new com.sun.jersey.spi.container.servlet.ServletContainer());
webAppContext.addServlet(servletHoder, "/agent/*");
之后,在包中定义了一个抽象对象AbstractResource
public class AbstractResource {
protected JsonMapper jsonMapper = JsonMapper.nonDefaultMapper();
protected @Context
ServletContext context;
public JsonMapper getJsonMapper() {
return jsonMapper;
}
public void setJsonMapper(JsonMapper jsonMapper) {
this.jsonMapper = jsonMapper;
}
public ServletContext getContext() {
return context;
}
public void setContext(ServletContext context) {
this.context = context;
}
}
然后,真实的资源代码实现AbstractResource对象,对资源进行定义
@Path("/job")
public class JobResource extends AbstractResource {
private DecimalFormat percentFormat = new DecimalFormat("##0.00");
private SimpleDateFormat dateFormat = new SimpleDateFormat(
"d-MMM-yyyy HH:mm:ss");
@Path("/clustersummary")
@GET
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String getClusterSummaryInfo() {
JobTracker jt = (JobTracker) context.getAttribute("job.tracker");
ClusterMetrics metrics = jt.getClusterMetrics();
String tasksPerNode = metrics.getTaskTrackerCount() > 0 ? percentFormat
.format(((double) (metrics.getMapSlotCapacity() + metrics
.getReduceSlotCapacity()))
/ metrics.getTaskTrackerCount()) : "-";
Map<String, String> summaryInfo = new LinkedHashMap<String, String>();
summaryInfo.put("usedHeapMemoryBytes",
Long.toString(Runtime.getRuntime().totalMemory()));
summaryInfo.put("totalHeapMemoryBytes",
Long.toString(Runtime.getRuntime().maxMemory()));
summaryInfo.put("runningMapTasks",
Integer.toString(metrics.getRunningMaps()));
summaryInfo.put("runningReduceTasks",
Integer.toString(metrics.getRunningReduces()));
summaryInfo.put("totalJobSubmissions",
Integer.toString(metrics.getTotalJobSubmissions()));
summaryInfo.put("numTotalTaskTrackers",
Integer.toString(metrics.getTaskTrackerCount()));
summaryInfo.put("occupiedMapSlots",
Integer.toString(metrics.getOccupiedMapSlots()));
summaryInfo.put("occupiedReduceSlots",
Integer.toString(metrics.getOccupiedReduceSlots()));
summaryInfo.put("reservedMapSlots",
Integer.toString(metrics.getReservedMapSlots()));
summaryInfo.put("reservedReduceSlots",
Integer.toString(metrics.getReservedReduceSlots()));
summaryInfo.put("mapTaskCapacity",
Integer.toString(metrics.getMapSlotCapacity()));
summaryInfo.put("reduceTaskCapacity",
Integer.toString(metrics.getReduceSlotCapacity()));
summaryInfo.put("avgTasksPerTaskTracker", tasksPerNode);
summaryInfo.put("numBlackListedTaskTrackers",
Integer.toString(metrics.getBlackListedTaskTrackerCount()));
summaryInfo.put("numGrayListedTaskTrackers",
Integer.toString(metrics.getGrayListedTaskTrackerCount()));
summaryInfo.put("numDecommissionedTaskTrackers",
Integer.toString(metrics.getDecommissionedTaskTrackerCount()));
return jsonMapper.toJson(summaryInfo);
}
}
这样可以通过访问url进行访问,自定义管理界面访问的端口与原有的管理页面端口相同。JobTracker使用50030,NameNode使用50070,依次类推。具体见下单元测试代码:
public class JobResourceIntTest {
HttpClient client;
@Before
public void setUp() {
client = new DefaultHttpClient();
}
private String urlPrefix = "http://ip:50030/agent/job/";
private String jobId = "job_201405121106_0001";
private String tipId = "task_201405121106_0001_m_000000";
private String attemptId = "attempt_201405121106_0001_m_000000_0";
private String regex = "\"total\":\"(.+?)\",";
private Pattern p = Pattern.compile(regex);
@Test
public void testClusterSummary() {
HttpGet clusterSummary = new HttpGet(urlPrefix + "clustersummary");
try {
HttpResponse response = client.execute(clusterSummary);
String clusterSummaryStr = EntityUtils.toString(response
.getEntity());
System.out.println(clusterSummaryStr);
Assert.assertTrue(clusterSummaryStr.contains("usedHeapMemoryBytes"));
Assert.assertTrue(clusterSummaryStr.contains("runningMapTasks"));
} catch (Exception e) {
e.printStackTrace();
}
clusterSummary.releaseConnection();
}
@After
public void tearDown() {
}
}
上述是后端的实现和单元测试,前端可根据需要进行资源获取和界面设计。
Hadoop自定义JobTracker和NameNode管理页面的更多相关文章
- git学习------>在CenterOS系统上安装GitLab并自定义域名访问GitLab管理页面
目前就职的公司一直使用SVN作为版本管理,现在打算尝试从SVN迁移到Git.安排我来预言并搭建好相关的环境以及自己尝试使用Git.今天我就尝试在Center OS系统上安装GitLab,现在在此记录一 ...
- Hadoop JobTracker和NameNode运行时参数查看
1)JobTracker运行时参数: hadoop@ubuntu:/home/zhangchao3$ ps -ef | grep job hadoop 29563 1 0 11:34 pts/12 ...
- Django(四) 后台管理:创建管理员、注册模型类、自定义管理页面显示内容
后台管理 第1步.本地化:设置语言.时区 修改project1/settings.py #LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'zh-hans' #设置语言 ...
- C#_MVC 自定义AuthorizeAttribute实现权限管理
随笔- 28 文章- 31 评论- 16 MVC 自定义AuthorizeAttribute实现权限管理 在上一节中提到可以使用AuthorizeAttribute进行权限管理: [Autho ...
- MVC自定义AuthorizeAttribute实现权限管理
[转]MVC自定义AuthorizeAttribute实现权限管理 原文载自:小飞的DD http://www.cnblogs.com/feiDD/articles/2844447.html 网站的权 ...
- hadoop学习笔记肆--元数据管理机制
1.首先,认识几个名词 (1).NameNode中读.写.以及DataNode映射等信息叫做“元数据” ,NameNode元数据存放位置有.内存.fsimage.edits log三个位置. (2). ...
- python 全栈开发,Day132(玩具管理页面,控制玩具通讯录,基于请求的好友关系建立)
先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.5.zip 注意:由于涉及到 ...
- BBS--后台管理页面,编辑文章,xss攻击
1 1.对文章进行增删改查 # 后台管理url re_path(r'^cn_backend/$', views.cn_backend, name='cn_backend'), re_path(r'^c ...
- [hadoop读书笔记] 第十章 管理Hadoop集群
P375 Hadoop管理工具 dfsadmin - 查询HDFS状态信息,管理HDFS. bin/hadoop dfsadmin -help 查询HDFS基本信息 fsck - 检查HDFS中文件的 ...
随机推荐
- windows下hla编译环境配置(转)
原文地址:http://blog.chinaunix.net/uid-20548989-id-1667169.html HLA简介 HLA,英文"High Level Ass ...
- Jmeter使用指南----压力测试工具
来源: https://blog.csdn.net/u012111923/article/details/80705141 https://www.cnblogs.com/st-leslie/p/51 ...
- CSAPP阅读笔记-栈帧-来自第三章3.7的笔记-P164-P176
1.基本结构: 如上图所示,是通用的栈帧结构.大致分两块,调用者函数P和被调用者函数Q. 对P来说,要做的工作是把传递参数中多于6个的部分压栈,随后把Q返回时要执行的下一条指令的地址压栈. 对Q来说, ...
- React条件性渲染
React条件性渲染的方式和Vue是不同的,之前用vue做项目时觉得vue是在是强大,通过v-if就可以选择性的渲染组件,另外,对于列表的渲染更是方便,一个v-for就可以进行快速的渲染,但是Reac ...
- MySQL修改数据表
ALTER [IGNORE] table tb_name alter_spec,alter_spec......... alter_specification: ADD [COLUMN] create ...
- unittest单元测试框架总结(转载)
转载:https://www.cnblogs.com/yufeihlf/p/5707929.html unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该 ...
- 手动修改user-agent
1. 在浏览器地址栏输入 about:config.弹出对话框:
- vue+cordova项目
教你用Cordova打包Vue项目 现在国内越来越多的开发者使用Vue开发混合app,但是当大家开发完成过后才发现不知道该怎么将Vue项目打包成app.据我现在的了解打包Vue项目目前流行的就是使 ...
- bzoj 3064: Tyvj 1518 CPU监控
Description 1.区间加 \(z\) 2.区间覆盖为 \(z\) 3.查询区间最大值 4.查询区间历史最大值 Solution 线段树维护历史最值,思想大致是维护标记出现过的最大值 考虑这种 ...
- JavaScript中变量的LHS引述和RHS引用
JavaScript中变量的LHS引述和RHS引用 www.MyException.Cn 网友分享于:2015-02-04 浏览:0次 JavaScript中变量的LHS引用和RHS引用 在Jav ...