-
通过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对象的元素
项目 | 数据类型 | 描述 |
---|---|---|
appsSubmitted | INT | 提交的申请数量 |
appsCompleted | INT | 申请完成的数量 |
appsPending | INT | 待处理的申请数量 |
appsRunning | INT | 运行的应用程序数量 |
appsFailed | INT | 应用程序数量失败 |
appsKilled | INT | 被杀害的申请数量 |
reservedMB | 长 | 以MB为单位保留的内存量 |
availableMB | 长 | 以MB为单位的可用内存量 |
allocatedMB | 长 | 以MB为单位分配的内存量 |
totalMB | 长 | 以MB为单位的总内存量 |
reservedVirtualCores | 长 | 保留的虚拟核心数 |
availableVirtualCores | 长 | 可用虚拟核心数 |
allocatedVirtualCores | 长 | 分配的虚拟核心数 |
totalVirtualCores | 长 | 虚拟核心总数 |
containersAllocated | INT | 分配的容器数量 |
containersReserved | INT | 保留的容器数量 |
containersPending | INT | 待处理的容器数量 |
totalNodes | INT | 节点总数 |
activeNodes | INT | 活动节点数 |
lostNodes | INT | 丢失的节点数 |
unhealthyNodes | INT | 不健康节点的数量 |
decommissioningNodes | INT | 退役的节点数 |
decommissionedNodes | INT | 退役的节点数量 |
rebootedNodes | INT | 重新启动的节点数 |
shutdownNodes | INT | 节点数量关闭 |
响应示例
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"] #总核心量