您可以使用衡量指标 API 获取时间序列衡量指标。从 NSX 4.1.1 开始,您还可以使用衡量指标 API 获取不同实体(如 Edge 和传输节点)的状态。

这些 API 可以将多个意向路径用作特定资源类型(如 Edge 或网关)的输入,并返回相应的衡量指标。有关如何调用时间序列衡量指标 API 的完整信息,请参见《NSX Intelligence 和 NSX Application Platform API 指南》

以下列表包含与衡量指标 API 相关的术语及其描述。

术语 描述
资源类型 可用于衡量指标的任何实体,如 Edge 节点或网关。
资源 ID 资源类型的意向路径或标识符。
对象 特定资源类型的子实体。例如,规则集内的防火墙规则。

分配给任何资源衡量指标的唯一键。

以下键是可用于 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:因连接限制导致的每秒丢包的平均速率。
以下键可用作状态键:
  • cluster.overall_status

  • cluster.group_status(节点的每个组状态)

  • cluster.group_member_status(组的每个节点状态)

  • tn.admin_status

  • tn.link_status
  • tn.ccp_connection_status_from_tn

您可以使用以下 API 获取任何所需资源的密钥。

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

执行以下步骤以获取所需资源的衡量指标。请注意,示例中使用的衡量指标键仅用于示例目的。使用相应的 API 获取实际键和描述。

步骤 1:选择要提取时间序列衡量指标的资源类型

您可以获取 Edge 节点和网关的时间序列衡量指标。从以下列表中选择资源类型。
  • PolicyEdgeNode
  • ClusterNode
  • Tier0Interface
  • Tier1Interface
  • 第 0 层
  • 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
                                }
                           }
                    ]
                }
            ]
        }