Article Directory
1, api usage guide
总览:http://test-c6:7180/static/apidocs/
quickstart: http://test-c6:7180/static/apidocs/tutorial.html
a, view cluster information
[root@test-c6 ~]# curl -u admin:admin 'http://localhost:7180/api/v1/clusters'
{
"items" : [ {
"name" : "Cluster 1",
"version" : "CDH5"
} ]
}
b, view host information
[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, view service status
## 查询单个服务
[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, start/stop service
[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 monitoring query
a, use guide
http://test-c6:7180/static/help/topics/cm_dg_tsquery.html
b, execute sql in the query console
http://test-c6:7180/cmf/views/search , execute sql query
Query item | sql parameters |
---|---|
Physical memory | physical_memory_total, physical_memory_used, physical_memory_memfree, physical_memory_buffers |
Swap memory | swap_total, swap_used, swap_free |
load | load_1, load_5, load_15 |
cpu usage | cpu_percent |
Network throughput rate | total_bytes_receive_rate_across_network_interfaces, total_bytes_transmit_rate_across_network_interfaces |
Disk read and write rate | read_bytes_rate ,write_bytes_rate |
c, use api to query 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"
} ]
}