# Getting active pool member connections using Python

**URL:** <https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336>\
**Category:** Technical Forums\
**Tags:** icontrol, super-netops, devops, rest, connection, api, ltm, pool-member, python\
**Created:** [June 5, 2018, 6:58pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336 "2018-06-05T18:58:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Harber](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Tim\_Harber](https://community.f5.com/u/Tim_Harber)\
**Post date:** [June 5, 2018, 6:58pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/1 "2018-06-05T18:58:23Z")

</div>

If I want to see all of the client connections connecting to a pool member from the CLI I can do something like a “show sys connection ss-server-addr 1.2.3.4”. I can also do this using Postman mapping to ";, but I cannot figure out how to do this via Python.

Using Python if I try to connect to “bigip.sys.raw” I do not see a module called “connection” or anything similar. Does anyone know how, or have some sample code on how to accomplish this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Jason\_Nance\_333](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jason\_Nance\_333](https://community.f5.com/u/Jason_Nance_333)\
**Post date:** [June 6, 2018, 2:36pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/2 "2018-06-06T14:36:18Z")

</div>

The stats are pulled from the pool or member itself. Try this for an example:

```tcl
!/usr/bin/env python3

from f5.bigip import ManagementRoot
from getpass import getpass
from pprint import pprint

hostname = 'my.f5.ltm.net'
username = 'foo'

mgmt = ManagmentRoot(hostname, username, getpass())

pool = mgmt.tm.ltm.pools.pool.load(name='my_pool_name')
poolstats = pool.stats.load()

pprint(poolstats.raw)

members = pool.members_s.get_collection()
member0_stats = members[0].stats.load()

pprint(member0_stats.raw)

```

---

<div class="post-metadata">

**Author:** ![Jason\_Nance](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jason\_Nance](https://community.f5.com/u/Jason_Nance)\
**Post date:** [June 6, 2018, 2:36pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/3 "2018-06-06T14:36:18Z")

</div>

The stats are pulled from the pool or member itself. Try this for an example:

```tcl
!/usr/bin/env python3

from f5.bigip import ManagementRoot
from getpass import getpass
from pprint import pprint

hostname = 'my.f5.ltm.net'
username = 'foo'

mgmt = ManagmentRoot(hostname, username, getpass())

pool = mgmt.tm.ltm.pools.pool.load(name='my_pool_name')
poolstats = pool.stats.load()

pprint(poolstats.raw)

members = pool.members_s.get_collection()
member0_stats = members[0].stats.load()

pprint(member0_stats.raw)

```

---

<div class="post-metadata">

**Author:** ![Tim\_Harber](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Tim\_Harber](https://community.f5.com/u/Tim_Harber)\
**Post date:** [June 6, 2018, 4:38pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/4 "2018-06-06T16:38:10Z")

</div>

Thanks Jason. I am able to get stats the way you describe, but what I am trying to get is the actual connected clients connected to each pool member. For example from the CLI if I do a

```tcl
show sys connection cs-server-addr 10.69.67.92

```

I get the following resuts:’

```tcl
Sys::Connections
192.168.181.163:51952 10.69.67.92:443 10.69.67.15:4822 10.69.65.65:44301 tcp 3 (tmm: 10) none
192.168.181.160:62556 10.69.67.92:443 10.69.67.15:21454 10.69.65.64:44301 tcp 2 (tmm: 10) none
10.74.10.114:60012 10.69.67.92:443 10.69.67.15:4246 10.69.65.65:44301 tcp 11 (tmm: 11) none
192.168.181.162:57199 10.69.67.92:443 10.69.67.15:32841 10.69.65.63:44301 tcp 2 (tmm: 6) none
192.168.181.156:58295 10.69.67.92:443 10.69.67.15:57537 10.69.65.64:44301 tcp 1 (tmm: 1) none
10.69.53.175:52661 10.69.67.92:443 10.69.67.15:57967 10.69.65.63:44301 tcp 10 (tmm: 7) none
Total records returned: 6

```

I am trying to get this same data using the API. I can get it via REST using Postman, but cannot figure out how to do it using Python.

---

<div class="post-metadata">

**Author:** ![Tim\_Harber](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Tim\_Harber](https://community.f5.com/u/Tim_Harber)\
**Post date:** [June 6, 2018, 4:38pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/5 "2018-06-06T16:38:10Z")

</div>

Thanks Jason. I am able to get stats the way you describe, but what I am trying to get is the actual connected clients connected to each pool member. For example from the CLI if I do a

```tcl
show sys connection cs-server-addr 10.69.67.92

```

I get the following resuts:’

```tcl
Sys::Connections
192.168.181.163:51952 10.69.67.92:443 10.69.67.15:4822 10.69.65.65:44301 tcp 3 (tmm: 10) none
192.168.181.160:62556 10.69.67.92:443 10.69.67.15:21454 10.69.65.64:44301 tcp 2 (tmm: 10) none
10.74.10.114:60012 10.69.67.92:443 10.69.67.15:4246 10.69.65.65:44301 tcp 11 (tmm: 11) none
192.168.181.162:57199 10.69.67.92:443 10.69.67.15:32841 10.69.65.63:44301 tcp 2 (tmm: 6) none
192.168.181.156:58295 10.69.67.92:443 10.69.67.15:57537 10.69.65.64:44301 tcp 1 (tmm: 1) none
10.69.53.175:52661 10.69.67.92:443 10.69.67.15:57967 10.69.65.63:44301 tcp 10 (tmm: 7) none
Total records returned: 6

```

I am trying to get this same data using the API. I can get it via REST using Postman, but cannot figure out how to do it using Python.

---

<div class="post-metadata">

**Author:** ![Jason\_Nance](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jason\_Nance](https://community.f5.com/u/Jason_Nance)\
**Post date:** [June 6, 2018, 4:49pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/6 "2018-06-06T16:49:48Z")

</div>

You’re saying pool member but

```tcl
cs-server-addr

```

is virtual server.

If you want connections to the virtual server use:

```tcl
virtual = mgmt.tm.ltm.pools.pool.load(name='my_vs_name')
vsstats = virtual.stats.load()

```

If you want pool member stats they are in the

```tcl
member0_stats = members[0].stats.load()

```

example above (you will need to iterate the pool members) -

```tcl
member0_stats.entries['serverside.curConns']

```

.

Here’s a graphical breakdown of the various cs/ss arguments:

> **[View and Delete F5 Load Balancer Active Connections - WorldTech IT](https://wtit.com/blog/2017/01/20/view-delete-f5-load-balancer-active-connections/)**
>
> Once you start depending on the F5® BIG-IP® to deliver your applications you will soon ask yourself: How do I view and delete the current or active connections through my F5 Load Balancer?

---

<div class="post-metadata">

**Author:** ![Jason\_Nance\_333](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jason\_Nance\_333](https://community.f5.com/u/Jason_Nance_333)\
**Post date:** [June 6, 2018, 4:49pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/7 "2018-06-06T16:49:48Z")

</div>

You’re saying pool member but

```tcl
cs-server-addr

```

is virtual server.

If you want connections to the virtual server use:

```tcl
virtual = mgmt.tm.ltm.pools.pool.load(name='my_vs_name')
vsstats = virtual.stats.load()

```

If you want pool member stats they are in the

```tcl
member0_stats = members[0].stats.load()

```

example above (you will need to iterate the pool members) -

```tcl
member0_stats.entries['serverside.curConns']

```

.

Here’s a graphical breakdown of the various cs/ss arguments:

> **[View and Delete F5 Load Balancer Active Connections - WorldTech IT](https://wtit.com/blog/2017/01/20/view-delete-f5-load-balancer-active-connections/)**
>
> Once you start depending on the F5® BIG-IP® to deliver your applications you will soon ask yourself: How do I view and delete the current or active connections through my F5 Load Balancer?

---

<div class="post-metadata">

**Author:** ![Tim\_Harber](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Tim\_Harber](https://community.f5.com/u/Tim_Harber)\
**Post date:** [June 6, 2018, 8:32pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/8 "2018-06-06T20:32:12Z")

</div>

That example was a virtual IP, but was just the example IP I had in front on me. In reality I need this for both virtual servers and pool members.

But in any case, when I use your example for pool members I get the output of the value of the number of connected clients instead of the list of client IP’s connected to the pool member as I showed above. My results for that code give me:

```tcl
{'value': 5}

```

What I need is the list of those 5 IP’s that are currently connected to that pool member which I can get using the CLI command “show sys connection ss-server-addr x.x.x.x”

---

<div class="post-metadata">

**Author:** ![Tim\_Harber](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@Tim\_Harber](https://community.f5.com/u/Tim_Harber)\
**Post date:** [June 6, 2018, 8:32pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/9 "2018-06-06T20:32:12Z")

</div>

That example was a virtual IP, but was just the example IP I had in front on me. In reality I need this for both virtual servers and pool members.

But in any case, when I use your example for pool members I get the output of the value of the number of connected clients instead of the list of client IP’s connected to the pool member as I showed above. My results for that code give me:

```tcl
{'value': 5}

```

What I need is the list of those 5 IP’s that are currently connected to that pool member which I can get using the CLI command “show sys connection ss-server-addr x.x.x.x”

---

<div class="post-metadata">

**Author:** ![Jason\_Nance](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jason\_Nance](https://community.f5.com/u/Jason_Nance)\
**Post date:** [June 6, 2018, 9:47pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/10 "2018-06-06T21:47:23Z")

</div>

Ahhh… Okay, sorry, I’m picking up what you’re putting down now.

I don’t think that the Python SDK supports this but you can do it with REST calls (using

```tcl
requests

```

or your preference).

Here are a couple pages describing this:

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

[DevCentral](https://devcentral.f5.com/articles/demystifying-icontrol-rest-part-3-how-to-pass-query-parameters-and-tmsh-options) (example 4 is exactly what you’re trying to do, I think)

I suggest opening an RFE on the GitHub page:

> **[Issues · F5Networks/f5-common-python](https://github.com/F5Networks/f5-common-python/issues)**
>
> Python SDK for configuration and monitoring of F5® BIG-IP® devices via the iControl® REST API. - Issues · F5Networks/f5-common-python

---

<div class="post-metadata">

**Author:** ![Jason\_Nance\_333](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jason\_Nance\_333](https://community.f5.com/u/Jason_Nance_333)\
**Post date:** [June 6, 2018, 9:47pm UTC](https://community.f5.com/t/getting-active-pool-member-connections-using-python/62336/11 "2018-06-06T21:47:23Z")

</div>

Ahhh… Okay, sorry, I’m picking up what you’re putting down now.

¬†

I don’t think that the Python SDK supports this but you can do it with REST calls (using

```tcl
requests

```

or your preference).

¬†

Here are a couple pages describing this:

¬†

> **[Connection list via iControlREST API](https://community.f5.com/t/connection-list-via-icontrolrest-api)**
>
> Problem this snippet solves: This python script will retrieve a filtered list of active connections via the iControl REST API. It supports both the default connection list as well as the detailed list you get by specifying ‘all-properties’. It...

¬†

[https://devcentral.f5.com/s/articles/demystifying-icontrol-rest-part-3-how-to-pass-query-parameters-and-tmsh-optionss](https://devcentral.f5.com/s/articles/demystifying-icontrol-rest-part-3-how-to-pass-query-parameters-and-tmsh-options) (example 4 is exactly what you’re trying to do, I think)

¬†

I suggest opening an RFE on the GitHub page:

¬†

> **[Issues · F5Networks/f5-common-python](https://github.com/F5Networks/f5-common-python/issues)**
>
> Python SDK for configuration and monitoring of F5® BIG-IP® devices via the iControl® REST API. - Issues · F5Networks/f5-common-python

¬†
