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中文件的 ...
随机推荐
- mvn修改版本号命令
mvn -DnewVersion=1.0.0 -DgenerateBackupPoms=false versions:set
- [转] Citrix XenDesktop桌面登录VM提示Citrix Web插件错误
[From] http://blog.51cto.com/xuhaili100love/1223707 [适用版本] 适用所有Citrix虚拟桌面版本 [现象描述] 使用SC登录虚拟机提示“无法访问您 ...
- Vue-cli3 WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB)
在vue.config.js里 添加 configureWebpack : { performance: { hints:'warning', //入口起点的最大体积 整数类型(以字节为单位) max ...
- Android微信支付流程及返回码-1之坑
http://www.51testing.com/html/36/n-3724336.html 之前做微信支付的时候,直接是以库形式引入项目的,虽然一直觉得微信支付的开发文档不太理想,但是印象中也没有 ...
- 漫谈TCPIP协议原理
一.每次说道TCPIP协议,有能说会道者,总爱说三次握手,什么意思? 顾名思义,假设有两个机器A和B 1.当A发送给B一个包的时候,B接收到了,这个时候,B有两个选择,要么将包数据放入缓存,等待处理, ...
- idea validation code
K71U8DBPNE-eyJsaWNlbnNlSWQiOiJLNzFVOERCUE5FIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...
- selenium 多窗口(windows)及ITargetLocator使用总结
1. selenium能实现窗口切换的原理 2. 常见命令 2.1 WindowHandle 2.2 WindowHandles 2.3 SwitchTo 3. 使用JavaScript新建窗口 4. ...
- PHP面向对象的基本思路
第一步:识别对象 ——任何实体都可以被识别为一个对象 第二步:识别对象的属性 ——对象里面存储的数据被识别为属性 ——对于不同的业务逻辑,关注的数据不同,独享里面存储的属性也不同 第三步:识别对象的行 ...
- 012-MD5Utils工具类模板
package ${enclosing_package}; import java.math.BigInteger; import java.security.MessageDigest; impor ...
- CSS ::Selection的使用方法
大家都知道浏览器对选中的文本默认样式都是统一的,Windows下是一个深蓝色的背景,白字的前景,而在Mac下是一个淡蓝色背景,白色字体,就如上图所展示的一样,自从有了这个“::selection”选择 ...