您可以使用度量 API 來擷取時間序列度量。從 NSX 4.1.1 開始,您還可以使用度量 API,來擷取不同實體 (例如 Edge 和傳輸節點) 的狀態。
這些 API 可以將多個意圖路徑當作特定資源類型 (如 Edge 或閘道) 的輸入,並傳回對應的度量。如需有關如何叫用時間序列度量 API 的完整資訊,請參閱《NSX Intelligence 和 NSX Application Platform API 指南》。
以下清單包含與度量 API 相關的詞彙及其說明。
詞彙 | 說明 |
---|---|
資源類型 | 可使用度量的任何實體,如 Edge 節點或閘道。 |
資源識別碼 | 資源類型的意圖路徑或識別碼。 |
物件 | 特定資源類型的子實體。例如,規則集內的防火牆規則。 |
金鑰 | 指派給任何資源之度量的唯一索引鍵。 以下索引鍵是可用於 Edge 節點和 NSX Manager 的度量索引鍵範例:
以下索引鍵是可用於閘道防火牆的度量索引鍵範例:
以下索引鍵可作為狀態索引鍵:
您可以使用下列 API 擷取任何所需資源的金鑰。
|
執行以下步驟以擷取所需資源的度量。請注意,範例中使用的度量索引鍵僅用於示範目的。請使用適當的 API 擷取實際索引鍵和說明。
步驟 1:選取要擷取時間序列度量的資源類型
- PolicyEdgeNode
- ClusterNode
- Tier0Interface
- Tier1Interface
- Tier0
- Tier1
- PolicyBasedIPSecVpnSession
- RouteBasedIPSecVpnSession
步驟 2:取得支援的索引鍵及其適用於資源類型的資訊
使用下列 API 取得資源類型的支援金鑰。此 API 採用 resource_type 作為查詢參數,且會列出該資源的所有可用索引鍵。回應中的 value_type 欄位是指定該索引鍵是度量索引鍵還是狀態索引鍵。如果此欄位中的值為「Double」,則該索引鍵是度量索引鍵; 如果值為「string」,則該索引鍵為狀態索引鍵。對於度量索引鍵,此 API 還提供每個度量的說明和單位。
URI 路徑:
GET https://<manager>/napp/api/v1/metrics/key-info?resource_type=<resource_type>
範例:
GET https://<manager>/napp/api/v1/metrics/key-info?resource_type=PolicyEdgeNode
回應:
{ "results":[ { "aggregate_by_resource_ids" : false, "key ":"edge.cpu_usage", "metric_unit":"PERCENT", "description":"Edge Cpu usage percentage" "value_type": "DOUBLE" }, { "aggregate_by_resource_ids" : false, "key":"edge.pnic_avg_rx_packets", "metric_unit":"PER_SECOND" "description":"Average Rx packets per second" "value_type": "DOUBLE" } ] } }
步驟 3:取得資源和索引鍵的物件資訊
使用下列 API 取得所需資源類型的金鑰的物件資訊。
URI 路徑:
POST https://<manager>/napp/api/v1/metrics/object-info
範例要求:
{ "resource_type":"PolicyEdgeNode", "resource_ids": [ "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/2ed9af04-21c9-11e9-be65-000c2902dff7", "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/1349af04-21c9-11e9-be65-000c2902d0000" ], "keys": [ "edge_cores.cpu_usage", "edge.pnic_avg_rx_packets"], "start_time":1603971420 "end_time": 1603973420 "granularity": "5M", "max_num_data_points": 10 }
範例回應:
{ "start_time": 1603971420, "end_time": 1603973420, "resource_type": "PolicyEdgeNode", "results": [ { "resource_id": "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/2ed9af04-21c9-11e9-be65-000c2902dff7", "key_results": [ { "key": "edge.pnic_avg_rx_packets", "unit": "PER_SECOND", }, { "key": "edge_core.cpu_usage", "results": [ { "object_id": "core1", "node_id": "2ed9af04-21c9-11e9-be65-000c2902dff7", "node_path": "/infra/default/edge/1", node_name": "Edge1", }, { "object_id": "core2", "node_id": "2ed9af04-21c9-11e9-be65-000c2902dff7", "node_path": "/infra/default/edge/1", "node_name": "Edge1", } ] } ] }, { "resource_id": "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/1349af04-21c9-11e9-be65-000c2902d0000", "key_results": [ { "key": "edge.pnic_avg_rx_packets", "unit": "PER_SECOND", "description": "Average packet per second (PPS) network utilization on ingress on the the management interface(s)", } ] } ] }
步驟 4:擷取資料
使用下列 API 擷取資料。
URI 路徑:
POST https://<manager>/napp/api/v1/metrics/data
範例要求:
{ "resource_type":"PolicyEdgeNode", "resource_ids": [ "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/2ed9af04-21c9-11e9-be65-000c2902dff7", "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/1349af04-21c9-11e9-be65-000c2902d0000" ], "object_ids": ["core1" ,"core2"], "node_ids": [], "keys": [ "edge_cores.cpu_usage", "edge.pnic_avg_rx_packets"], "start_time":1603971420 "end_time": 1603973420 "granularity": "5M", "max_num_data_points": 10 }
範例回應:
{ "start_time": 1603971420, --> output start_time and end_time maybe different from input start_time and end_time "end_time": 1603973420, "resource_type": "PolicyEdgeNode", "results": [ { "path": "/infra/sites/default/enforcement-points/default/edge-clusters/57d2c653-4d63-48d8-b188-40b4e45a9bc8/edge-nodes/2ed9af04-21c9-11e9-be65-000c2902dff7", "key_results": [ { { "key": "edge_core.cpu_usage", "results": [ { "object_id": "core1", "node_id": "2ed9af04-21c9-11e9-be65-000c2902dff7", "data": [ { "time": 1603444589, "value": 29 }, { "time": 1603444489, "value": 30 }, { "time": 1603444389, "value": 35 } }, { "object_id": "core2", "object_description": "Some description", "node_id": "2ed9af04-21c9-11e9-be65-000c2902dff7", "node_name": "Edge1", "node_path":"/infra/default/edge/1" "data": [ { "time": 1603444589, "value": 29 }, { "time": 1603444489, "value": 30 }, { "time": 1603444389, "value": 35 } } ] } ] }