温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
Fayson的github: https://github.com/fayson/cdhproject
提示:代码块部分可以左右滑动查看噢
1
文档编写目的
大家也知道Cloudera Manager提供了丰富的监控指标,部分客户也有自己统一的监控平台,需要将CM上的监控指标集成到统一的监控平台上,因此可以通过提供的API接口获取监控指标,本篇文章Fayson主要介绍如何通过CM API接口获取集群所有节点内存和磁盘使用情况。如下图所示:
2
接口查找及说明
在Cloudera Manager的API列表中未找到一个比较合适的接口来直接获取指定节点内存和磁盘使用情况,最终在API列表中找到了获取时序数据的接口,该接口可以通过传入tsQuery语句查找到关于磁盘和内存使用情况的时序数据,具体接口如下:
http://${cm_host}:7180/api/v32/timeseries
接口参数说明:
contentType : application/json #指定返回内容类型
desiredRollup :RAW #指定数据聚合级别
from : 2019-05-07T14:47:05.542Z #指定查询数据的开始时间,为了减少获取的数据量可以指定当前时间前一分钟,默认为获取5分钟
mustUseDesiredRollup : false #默认为false
query : select physical_memory_total, physical_memory_used where hostId = "3b66b3d1-6eaf-4a64-aa20-ab07f9caa37a" #指定要查询的图表数据
to : now #指定查询数据的结束时间
API使用方式:
curl -X GET --header 'Accept: application/json' 'http://192.168.0.234:7180/api/v32/timeseries?contentType=application%2Fjson&desiredRollup=RAW&from=2019-05-07T14%3A47%3A05.542Z&mustUseDesiredRollup=false&query=select%20physical_memory_total%2C%20physical_memory_used%20where%20hostId%20%3D%20%223b66b3d1-6eaf-4a64-aa20-ab07f9caa37a%22&to=now'
返回值:
{
"items": [
{
"timeSeries": [
{
"metadata": {
"metricName": "physical_memory_total",
"entityName": "cdh235.macro.com",
"startTime": "2019-05-07T14:47:05.542Z",
"endTime": "2019-05-07T14:47:15.271Z",
"attributes": {
"hostname": "cdh235.macro.com",
"clusterDisplayName": "Cluster 1",
"entityName": "3b66b3d1-6eaf-4a64-aa20-ab07f9caa37a",
"clusterName": "cluster",
"hostId": "3b66b3d1-6eaf-4a64-aa20-ab07f9caa37a",
"active": "true",
"category": "HOST",
"version": "CDH 6.2.0",
"rackId": "/default"
},
"unitNumerators": [
"bytes"
],
"unitDenominators": [],
"expression": "SELECT physical_memory_total WHERE entityName = \"3b66b3d1-6eaf-4a64-aa20-ab07f9caa37a\" AND category = HOST",
"metricCollectionFrequencyMs": 60000,
"rollupUsed": "RAW"
},
"data": []
}
],
"warnings": [],
"timeSeriesQuery": "select physical_memory_total, physical_memory_used where hostId = \"3b66b3d1-6eaf-4a64-aa20-ab07f9caa37a\""
}
]
}
3
tsQuery语句使用
在上面我们找到通过CM API接口来获取指定tsQuery语句的监控数据,那接下来我们在Cloudera Manager上通过图表生成器来查询需要获取的数据,最终确定tsQuery语句,如下为Fayson写的两条语句用于满足前面的需求:
获取集群所有节点内存使用情况:
select physical_memory_total, physical_memory_used
获取集群所有节点磁盘使用情况:
select total_capacity_across_filesystems,total_capacity_used_across_filesystems WHERE category="HOST"
4
总结
1.通过CM时序数据API接口并指定tsQuery语句可以获取到Cloudera Manager界面上所有的监控图表数据。
2.在Cloudera Manager主机列表界面中显示的内存、磁盘和交换空间数据是由各个节点的Agent实时推送的并未写入数据库。
3.Cloudera Manager监控图表的时序数据是独立存储在Solr服务中。
提示:代码块部分可以左右滑动查看噢
为天地立心,为生民立命,为往圣继绝学,为万世开太平。 温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。