文章目录
1, api使用指南
总览:http://test-c6:7180/static/apidocs/
quickstart: http://test-c6:7180/static/apidocs/tutorial.html
a, 查看集群信息
[root@test-c6 ~]# curl -u admin:admin 'http://localhost:7180/api/v1/clusters'
{
"items" : [ {
"name" : "Cluster 1",
"version" : "CDH5"
} ]
}
b, 查看主机信息
[root@test-c6 ~]# curl -u admin:admin http://localhost:7180/api/v17/hosts
{
"items" : [ {
"hostId" : "68d905d8-4802-486d-9285-41e70576c05b",
"ipAddress" : "192.168.56.161",
"hostname" : "test-c6",
"rackId" : "/default",
"hostUrl" : "http://test-c6:7180/cmf/hostRedirect/68d905d8-4802-486d-9285-41e70576c05b",
"maintenanceMode" : false,
"maintenanceOwners" : [ ],
"commissionState" : "COMMISSIONED",
"numCores" : 1,
"numPhysicalCores" : 1,
"totalPhysMemBytes" : 5210898432
}, {
"hostId" : "0244fbb4-0d02-40b5-9cac-17d9e388eb97",
"ipAddress" : "192.168.56.162",
"hostname" : "test-c62",
"rackId" : "/default",
"hostUrl" : "http://test-c6:7180/cmf/hostRedirect/0244fbb4-0d02-40b5-9cac-17d9e388eb97",
"maintenanceMode" : false,
"maintenanceOwners" : [ ],
"commissionState" : "COMMISSIONED",
"numCores" : 1,
"numPhysicalCores" : 1,
"totalPhysMemBytes" : 2176856064
} ]
}
c, 查看服务状态
## 查询单个服务
[root@test-c6 ~]# curl -u admin:admin http://localhost:7180/api/v17/clusters/Cluster%201/services/hbase
{
"name" : "hbase",
"type" : "HBASE",
"clusterRef" : {
"clusterName" : "cluster"
},
"serviceUrl" : "http://test-c6:7180/cmf/serviceRedirect/hbase",
"roleInstancesUrl" : "http://test-c6:7180/cmf/serviceRedirect/hbase/instances",
"serviceState" : "STOPPED",
"healthSummary" : "DISABLED",
"healthChecks" : [ {
"name" : "HBASE_MASTER_HEALTH",
"summary" : "DISABLED",
"suppressed" : false
}, {
"name" : "HBASE_REGION_SERVERS_HEALTHY",
"summary" : "DISABLED",
"suppressed" : false
} ],
"configStalenessStatus" : "FRESH",
"clientConfigStalenessStatus" : "FRESH",
"maintenanceMode" : false,
"maintenanceOwners" : [ ],
"displayName" : "HBase",
"entityStatus" : "STOPPED"
}
##查询所有服务
[root@test-c6 ~]# curl -u admin:admin http://localhost:7180/api/v17/clusters/Cluster%201/services
{
"items" : [ {
"name" : "zookeeper",
"type" : "ZOOKEEPER",
"clusterRef" : {
"clusterName" : "cluster"
},
"serviceUrl" : "http://test-c6:7180/cmf/serviceRedirect/zookeeper",
"roleInstancesUrl" : "http://test-c6:7180/cmf/serviceRedirect/zookeeper/instances",
"serviceState" : "STARTED",
"healthSummary" : "BAD",
"healthChecks" : [ {
"name" : "ZOOKEEPER_CANARY_HEALTH",
"summary" : "GOOD",
"suppressed" : false
}, {
"name" : "ZOOKEEPER_SERVERS_HEALTHY",
"summary" : "BAD",
"suppressed" : false
} ],
"configStalenessStatus" : "FRESH",
"clientConfigStalenessStatus" : "FRESH",
"maintenanceMode" : false,
"maintenanceOwners" : [ ],
"displayName" : "ZooKeeper",
"entityStatus" : "BAD_HEALTH"
},
{
"name" : "hdfs",
"type" : "HDFS",
"clusterRef" : {
"clusterName" : "cluster"
},
"serviceUrl" : "http://test-c6:7180/cmf/serviceRedirect/hdfs",
"roleInstancesUrl" : "http://test-c6:7180/cmf/serviceRedirect/hdfs/instances",
"serviceState" : "STARTED",
"healthSummary" : "BAD",
"healthChecks" : [ {
"name" : "HDFS_BLOCKS_WITH_CORRUPT_REPLICAS",
"summary" : "GOOD",
"suppressed" : false
}, {
"name" : "HDFS_CANARY_HEALTH",
"summary" : "GOOD",
"suppressed" : false
}, {
"name" : "HDFS_DATA_NODES_HEALTHY",
"summary" : "BAD",
"suppressed" : false
}, {
"name" : "HDFS_FREE_SPACE_REMAINING",
"summary" : "GOOD",
"suppressed" : false
}, {
"name" : "HDFS_HA_NAMENODE_HEALTH",
"summary" : "BAD",
"suppressed" : false
}, {
"name" : "HDFS_MISSING_BLOCKS",
"summary" : "GOOD",
"suppressed" : false
}, {
"name" : "HDFS_UNDER_REPLICATED_BLOCKS",
"summary" : "BAD",
"suppressed" : false
} ],
"configStalenessStatus" : "FRESH",
"clientConfigStalenessStatus" : "FRESH",
"maintenanceMode" : false,
"maintenanceOwners" : [ ],
"displayName" : "HDFS",
"entityStatus" : "BAD_HEALTH"
}
]}
d, 启动/停止服务
[root@test-c6 ~]# curl -X POST -u admin:admin \
'http://localhost:7180/api/v1/clusters/Cluster%201/services/hdfs/commands/start'
{
"id" : 377,
"name" : "HdfsStartWithFailovers",
"startTime" : "2020-09-16T11:54:12.652Z",
"active" : true,
"serviceRef" : {
"clusterName" : "cluster",
"serviceName" : "hdfs"
}
}
############## 查看命令执行结果
[root@test-c6 ~]# curl -u admin:admin 'http://localhost:7180/api/v1/commands/377'
{
"id" : 377,
"name" : "HdfsStartWithFailovers",
"startTime" : "2020-09-16T11:54:12.652Z",
"endTime" : "2020-09-16T11:54:35.444Z",
"active" : false,
"success" : true,
"resultMessage" : "Successfully started HDFS service",
"serviceRef" : {
"clusterName" : "cluster",
"serviceName" : "hdfs"
},
"children" : {
"items" : [ {
"id" : 378,
"name" : "Start",
"startTime" : "2020-09-16T11:54:12.656Z",
"endTime" : "2020-09-16T11:54:35.444Z",
"active" : false,
"success" : true,
"resultMessage" : "Successfully started service.",
"serviceRef" : {
"clusterName" : "cluster",
"serviceName" : "hdfs"
}
} ]
}
}
2, tsql监控查询
a, 使用指南
http://test-c6:7180/static/help/topics/cm_dg_tsquery.html
b, 在查询控制台执行sql
http://test-c6:7180/cmf/views/search, 执行sql查询
查询项 | sql参数 |
---|---|
物理内存 | physical_memory_total, physical_memory_used, physical_memory_memfree, physical_memory_buffers |
交换内存 | swap_total, swap_used, swap_free |
负载 | load_1, load_5, load_15 |
cpu使用率 | cpu_percent |
网络吞吐速率 | total_bytes_receive_rate_across_network_interfaces, total_bytes_transmit_rate_across_network_interfaces |
磁盘读写速率 | read_bytes_rate ,write_bytes_rate |
c, 使用api查询sql
[root@test-c6 ~]# curl -u admin:admin http://localhost:7180/api/v17/timeseries?query=select%20cpu_percent
{
"items" : [ {
"timeSeries" : [ {
"metadata" : {
"metricName" : "cpu_percent",
"entityName" : "test-c6",
"startTime" : "2020-09-16T14:13:45.172Z",
"endTime" : "2020-09-16T14:18:45.172Z",
"attributes" : {
"hostname" : "test-c6",
"clusterDisplayName" : "Cluster 1",
"entityName" : "68d905d8-4802-486d-9285-41e70576c05b",
"clusterName" : "cluster",
"hostId" : "68d905d8-4802-486d-9285-41e70576c05b",
"active" : "true",
"category" : "HOST",
"version" : "CDH 5.12.0",
"rackId" : "/default"
},
"unitNumerators" : [ "percent" ],
"unitDenominators" : [ ],
"expression" : "SELECT cpu_percent WHERE entityName = \"68d905d8-4802-486d-9285-41e70576c05b\" AND category = HOST",
"metricCollectionFrequencyMs" : 60000,
"rollupUsed" : "RAW"
},
"data" : [ {
"timestamp" : "2020-09-16T14:14:00.000Z",
"value" : 5.5,
"type" : "SAMPLE"
}, {
"timestamp" : "2020-09-16T14:15:00.000Z",
"value" : 3.5,
"type" : "SAMPLE"
}, {
"timestamp" : "2020-09-16T14:16:00.000Z",
"value" : 3.5,
"type" : "SAMPLE"
}, {
"timestamp" : "2020-09-16T14:17:00.000Z",
"value" : 3.3,
"type" : "SAMPLE"
}, {
"timestamp" : "2020-09-16T14:18:00.000Z",
"value" : 3.6,
"type" : "SAMPLE"
} ]
}, {
"metadata" : {
"metricName" : "cpu_percent",
"entityName" : "test-c62",
"startTime" : "2020-09-16T14:13:45.172Z",
"endTime" : "2020-09-16T14:18:45.172Z",
"attributes" : {
"hostname" : "test-c62",
"clusterDisplayName" : "Cluster 1",
"entityName" : "0244fbb4-0d02-40b5-9cac-17d9e388eb97",
"clusterName" : "cluster",
"hostId" : "0244fbb4-0d02-40b5-9cac-17d9e388eb97",
"active" : "true",
"category" : "HOST",
"version" : "CDH 5.12.0",
"rackId" : "/default"
},
"unitNumerators" : [ "percent" ],
"unitDenominators" : [ ],
"expression" : "SELECT cpu_percent WHERE entityName = \"0244fbb4-0d02-40b5-9cac-17d9e388eb97\" AND category = HOST",
"metricCollectionFrequencyMs" : 60000,
"rollupUsed" : "RAW"
},
"data" : [ ]
} ],
"warnings" : [ ],
"timeSeriesQuery" : "select cpu_percent"
} ]
}