关于独立任务管理程序获取Yarn任务ID的一些思路

  1. 通过task_id字段找出最新的app_id

    表中需要用到的字段如下:

    mysql> desc tbl_task_result;
    +--------------+--------------+------+-----+---------+-------+
    | Field        | Type         | Null | Key | Default | Extra |
    +--------------+--------------+------+-----+---------+-------+
    | task_id      | int(11)      | NO   | MUL | NULL    |       |
    | execute_time | datetime     | NO   |     | NULL    |       |
    | app_id       | varchar(255) | NO   |     | NULL    |       |
    | task_result  | text         | YES  |     | NULL    |       |
    +--------------+--------------+------+-----+---------+-------+
    
    +---------+---------------------+--------------------------------+
    | task_id | execute_time        | app_id                         |
    +---------+---------------------+--------------------------------+
    |     137 | 2019-05-31 15:38:38 | application_1551701772282_6957 |
    |      57 | 2019-05-31 15:40:00 | application_1551701772282_6958 |
    |      57 | 2019-05-31 15:45:00 | application_1551701772282_6959 |
    |      57 | 2019-05-31 15:50:00 | application_1551701772282_6960 |
    |      57 | 2019-05-31 15:55:00 | application_1551701772282_6961 |
    |      57 | 2019-05-31 16:00:00 | application_1551701772282_6962 |
    |      57 | 2019-05-31 16:05:00 | application_1551701772282_6963 |
    |      57 | 2019-05-31 16:10:00 | application_1551701772282_6964 |
    |      57 | 2019-05-31 16:15:00 | application_1551701772282_6965 |
    |      57 | 2019-05-31 16:20:00 | application_1551701772282_6966 |
    +---------+---------------------+--------------------------------+
    
    1、找出对应task_id的所有app_id
    select execute_time,app_id from tbl_task_result where task_id=57;
    2、从中依据时间execute_time获取最新的app_id
    select app_id 
    from 
    (select execute_time,app_id from tbl_task_result where task_id=57) a
    
    

获取集群资源状态

群集指标API

群集指标资源提供有关群集的一些总体指标。应从jmx界面检索更详细的指标。

URI

  • http://rm-http-address:port/ws/v1/cluster/metrics

支持HTTP操作

  • Y

查询参数支持

N

clusterMetrics对象的元素

项目数据类型描述
appsSubmittedINT提交的申请数量
appsCompletedINT申请完成的数量
appsPendingINT待处理的申请数量
appsRunningINT运行的应用程序数量
appsFailedINT应用程序数量失败
appsKilledINT被杀害的申请数量
reservedMB以MB为单位保留的内存量
availableMB以MB为单位的可用内存量
allocatedMB以MB为单位分配的内存量
totalMB以MB为单位的总内存量
reservedVirtualCores保留的虚拟核心数
availableVirtualCores可用虚拟核心数
allocatedVirtualCores分配的虚拟核心数
totalVirtualCores虚拟核心总数
containersAllocatedINT分配的容器数量
containersReservedINT保留的容器数量
containersPendingINT待处理的容器数量
totalNodesINT节点总数
activeNodesINT活动节点数
lostNodesINT丢失的节点数
unhealthyNodesINT不健康节点的数量
decommissioningNodesINT退役的节点数
decommissionedNodesINT退役的节点数量
rebootedNodesINT重新启动的节点数
shutdownNodesINT节点数量关闭

响应示例

JSON响应

HTTP请求:

 GET http://rm-http-address:port/ws/v1/cluster/metrics

响应标题:

  HTTP/1.1 200 OK
  Content-Type: application/json
  Transfer-Encoding: chunked
  Server: Jetty(6.1.26)

回应机构:

{
  “clusterMetrics”:
  {
    “appsSubmitted”:0,
    “appsCompleted”:0,
    “appsPending”:0,
    “appsRunning”:0,
    “appsFailed”:0,
    “appsKilled”:0,
    “reservedMB”:0,
    “availableMB”:17408,
    “allocatedMB”:0,
    “reservedVirtualCores”:0,
    “availableVirtualCores”:7,
    “allocatedVirtualCores”:1,
    “containersAllocated”:0,
    “containersReserved”:0,
    “containersPending”:0,
    “totalMB”:17408,
    “totalVirtualCores”:8,
    “totalNodes”:1,
    “lostNodes”:0,
    “unhealthyNodes”:0,
    “decommissioningNodes”:0,
    “decommissionedNodes”:0,
    “rebootedNodes”:0,
    “activeNodes”:1,
    “shutdownNodes”:0
  }
}

测试返回的数据

{"clusterMetrics":
	{
		"appsSubmitted":13441,
		"appsCompleted":13431,
		"appsPending":0,
		"appsRunning":0,
		"appsFailed":6,
		"appsKilled":4,
		"reservedMB":0,
		"availableMB":1007616,
		"allocatedMB":0,
		"reservedVirtualCores":0,
		"availableVirtualCores":171,
		"allocatedVirtualCores":0,
		"containersAllocated":0,
		"containersReserved":0,
		"containersPending":0,
		"totalMB":1007616,
		"totalVirtualCores":171,
		"totalNodes":9,
		"lostNodes":0,
		"unhealthyNodes":0,
		"decommissioningNodes":0,
		"decommissionedNodes":0,
		"rebootedNodes":0,
		"activeNodes":6,
		"shutdownNodes":3,
		"totalUsedResourcesAcrossPartition":
		{
			"memory":0,
			"vCores":0,
			"resourceInformations":
			{
				"resourceInformation":
				[
					{"maximumAllocation":9223372036854775807,
					"minimumAllocation":0,
					"name":"memory-mb",
					"resourceType":"COUNTABLE",
					"units":"Mi",
					"value":0}
					,
					{"maximumAllocation":9223372036854775807,
					"minimumAllocation":0,
					"name":"vcores",
					"resourceType":"COUNTABLE",
					"units":"",
					"value":0
					}
				]
			}
		},
		"totalClusterResourcesAcrossPartition":
		{
			"memory":1007616,
			"vCores":171,
			"resourceInformations":
			{
				"resourceInformation":
				[
					{"maximumAllocation":9223372036854775807,
					"minimumAllocation":0,
					"name":"memory-mb",
					"resourceType":"COUNTABLE",
					"units":"Mi",
					"value":1007616}
					,
					{"maximumAllocation":9223372036854775807,
					"minimumAllocation":0,
					"name":"vcores",
					"resourceType":"COUNTABLE",
					"units":"",
					"value":171
					}
				]
			}
		}
	}
}
获取集群任务排队数与可用内存量
import urllib2
import json

url = 'http://ip:port/ws/v1/cluster/metrics'
req = urllib2.Request(url)
res_data = urllib2.urlopen(req)
cluster_info = json.loads(res_data.read())["clusterMetrics"]
totalMemory = cluster_info["totalMB"]  #总内存量,单位MB
totalVirtualCores = cluster_info["totalVirtualCores"]  #总核心量
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值