弘协网络 | F5技术交流

通过REST API获取连接表

2021-01-19 14:53:25

Will Tang

PHPWord

通过REST API获取连接表

 

查看连接表是我们在F5上做Troubleshooting时常用的手段,我们通常是通过tmsh命令来获取F5设备上当前的连接信息,而通过REST API也可以很方便的来获取连接表信息,本文就对这一方法做简单介绍。

 

REST API Endpoint

获取连接表信息的Endpoint是mgmt/tm/sys/connection,详细信息可以参考clouddoc:

https://clouddocs.f5.com/api/icontrol-rest/APIRef_tm_sys_connection.html

这里做个简单演示


完整响应如下

{
  "kind": "tm:sys:connection:connectionstats",
  "selfLink": "https://localhost/mgmt/tm/sys/connection?ver=13.1.1.5",
  "entries": {
    "https://localhost/mgmt/tm/sys/connection/0": {
      "nestedStats": {
        "entries": {
          "connectionId": {
            "value": 0
          },
          "csBytesIn": {
            "value": 608
          },
          "csBytesOut": {
            "value": 608
          },
          "csClientAddr": {
            "description": "10.1.10.241"
          },
          "csClientPort": {
            "value": 123
          },
          "csPacketsIn": {
            "value": 8
          },
          "csPacketsOut": {
            "value": 8
          },
          "csServerAddr": {
            "description": "80.241.0.72"
          },
          "csServerPort": {
            "value": 123
          },
          "flowAccelType": {
            "description": "none"
          },
          "idleTime": {
            "value": 11
          },
          "idleTimeout": {
            "value": 30
          },
          "lasthopInfo": {
            "description": "/Common/external_vlan 00:0c:29:79:f5:77"
          },
          "protocol": {
            "value": 17
          },
          "slot": {
            "description": "1"
          },
          "ssBytesIn": {
            "value": 608
          },
          "ssBytesOut": {
            "value": 608
          },
          "ssClientAddr": {
            "description": "10.1.10.241"
          },
          "ssClientPort": {
            "value": 39345
          },
          "ssPacketsIn": {
            "value": 8
          },
          "ssPacketsOut": {
            "value": 8
          },
          "ssServerAddr": {
            "description": "80.241.0.72"
          },
          "ssServerPort": {
            "value": 123
          },
          "tmm": {
            "value": 0
          },
          "type": {
            "description": "self"
          },
          "unitId": {
            "value": 0
          },
          "virtualPathAddr": {
            "description": "0.0.0.0%65535"
          },
          "virtualPathPort": {
            "value": 0
          }
        }
      }
    }
  }
}

响应是JSON格式的,看起来不像CLI中那么直观。

对连接表做过滤

以上是显示所有连接信息,但实际使用中我们希望只显示想看到的信息,我们可以根据clouddoc中给出的参数对要获取的连接表做过滤

例如我们只想要显示后端服务是10.1.20.12:80的连接信息,可以通过以下uri获取:

/mgmt/tm/sys/connection?options=ss-server-addr+10.1.20.12+ss-server-port+80

命令行中使用请加双引号进行转义


 

发布评论 加入社群

发布评论

相关文章

Ansible 部署/删除 nginx

晏顺

2020-04-06 19:56:17 404

Harbor部署和使用

晏顺

2020-03-26 20:18:52 650

Harbor部署和使用

晏顺

2020-03-26 20:18:52 749

Login

手机号
验证码
© 2019 F5 Networks, Inc. 版权所有。京ICP备16013763号-1