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中文件的 ...
随机推荐
- dynamics crm 365 附件上传图片并且显示。
参考了几篇博客做的: 新增websource文件(html): <!DOCTYPE html> <html> <head> <title>注释</ ...
- 2019.4.4 盒模型&定位&浮动
盒模型 盒模型 除了图片表单元素之外,基本所有标签都可以看做一个盒子 盒模型的要素 父子关系之间用padding 兄弟关系之间用margin margin padding border 后面跟的值的顺 ...
- idea 修改jar包源码的编码
项目中有些老的jar不是utf8打包的,中文显示乱码 打开的文件上直接右键, 修改只读jar的源码 自己写的文件可以在右下角修改编码,只读文件就要用上面的方法了
- 如何统计Visual Studio Code项目的代码行数
背景 年底到了,公司一年一度做述职报告的时间又到了,每到此时小伙伴们都想方设法的去做一些代码层面的汇总.在此交给大家个小妙招,走过路过不要错过哈,, 解决方案 使用Visual Studio Code ...
- c# 线程,同步,锁
最近在阅读<c#高级编程> 这本书.记录一下关于锁的使用 大致分为三种方法: 方法1:使用 lock 方法2:使用 Interlocked 方法3:使用 Monitor using Sys ...
- Android中Service与多个Activity通信
由于项目需要,我们有时候需要在service中处理耗时操作,然后将结果发送给activity以更新状态.通常情况下,我们只需要在一个service与一个activity之间通信,通常这种情况下,我们使 ...
- 添加ASP.NET网站资源文件夹
ASP.NET应用程序包含7个默认文件夹,分别为Bin.APP_Code.App_GlobalResources.App_LocalResources.App_WebReferences.App_Br ...
- Kubernetes Device Plugins
The gRPC server that the device plugin must implement is expected to be advertised on a unix socket ...
- MySQL查询操作select
查找记录 SELECT select_expr [,select_expr ...] [ FROM table_references(表的参照) [WHERE where_condition](条件) ...
- Unity Github 项目收集
http://gad.qq.com/article/detail/24048 重磅推荐: Github 热门 Unity Assets 查询:http://unitylist.com/browse 最 ...