Forum Discussion
Getting active pool member connections using Python
The stats are pulled from the pool or member itself. Try this for an example:
!/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)
- Tim_HarberJun 06, 2018Cirrus
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
show sys connection cs-server-addr 10.69.67.92
I get the following resuts:'
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.
- Jason_Nance_333Jun 06, 2018Cirrus
You're saying pool member but
cs-server-addr
is virtual server.
If you want connections to the virtual server use:
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
member0_stats = members[0].stats.load()
example above (you will need to iterate the pool members) -
member0_stats.entries['serverside.curConns']
.
Here's a graphical breakdown of the various cs/ss arguments:
https://wtit.com/view-delete-f5-load-balancer-active-connections/
- Tim_HarberJun 06, 2018Cirrus
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:
{'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"
- Jason_Nance_333Jun 06, 2018Cirrus
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
or your preference).requests
 
Here are a couple pages describing this:
 
https://devcentral.f5.com/s/articles/connection-list-via-icontrolrest-api
 
https://devcentral.f5.com/s/articles/demystifying-icontrol-rest-part-3-how-to-pass-query-parameters-and-tmsh-optionss (example 4 is exactly what you're trying to do, I think)
 
I suggest opening an RFE on the GitHub page:
 
https://github.com/F5Networks/f5-common-python/issues
 
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com