您可以使用度量 API 來擷取時間序列度量。

這些 API 可以將多個意圖路徑當作特定資源類型 (如 Edge 或閘道) 的輸入,並傳回對應的度量。如需有關如何叫用時間序列度量 API 的完整資訊,請參閱《NSX Intelligence 和 NSX Application Platform API 指南》

以下清單包含與度量 API 相關的詞彙及其說明。

詞彙 說明
資源類型 可使用度量的任何實體,如 Edge 節點或閘道。
資源識別碼 資源類型的意圖路徑或識別碼。
物件 特定資源類型的子實體。例如,規則集內的防火牆規則。
度量索引鍵 指派給任何資源之度量的唯一索引鍵。

以下度量索引鍵是可用於 Edge 節點和 NSX Manager 的索引鍵範例:

  • disk.avg_used_percent:所使用區塊佔總數的百分比。
  • system.avg_load:過去 1 分鐘內的平均系統負載。
  • system.avg_mem_available_percent:可用記憶體佔總記憶體的百分比。
以下度量索引鍵是可用於閘道防火牆的索引鍵範例:
  • edge_fw.avg_drop_reason_alg:因應用程式層閘道而導致的防火牆捨棄的平均速率。
  • edge_fw.avg_drop_reason_connection_limit:因連線限制而導致的每秒捨棄的平均速率。

您可以使用以下 API 擷取任何所需資源的度量索引鍵。

GET https://<manager>/napp/api/v1/metrics/key-info?resource_type=<resource_type>

執行以下步驟以擷取所需資源的度量。請注意,範例中使用的度量索引鍵僅用於示範目的。請使用適當的 API 擷取實際索引鍵和說明。

步驟 1:選取要擷取時間序列度量的資源類型

您可以擷取 Edge 節點和閘道的時間序列度量。從以下清單中選取資源類型。
  • PolicyEdgeNode
  • ClusterNode
  • Tier0Interface
  • Tier1Interface
  • Tier0
  • Tier1

    NSX 4.0.1.1 開始,您還可以使用下列資源類型,來檢視 VPN 的時間序列度量。

  • PolicyBasedIPSecVpnSession
  • RouteBasedIPSecVpnSession

步驟 2:取得支援的度量索引鍵及其適用於資源類型的資訊

使用以下 API 取得適用於資源類型的受支援度量索引鍵。此 API 以 resource_type 作為查詢參數,並列出該資源可用的所有度量。此 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":[
        {
            "metric_key ":"edge.cpu_usage",
            "metric_unit":"PERCENT",
            "description":"Edge Cpu usage percentage"
        },
     {
            "metric_key":"edge.pnic_avg_rx_packets",
            "metric_unit":"PER_SECOND"
            "description":"Average Rx packets per second"
        }
  ]
}

}

步驟 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
                                }
                           }
                    ]
                }
            ]
        }