Forum Discussion

zielik88_270153's avatar
zielik88_270153
Icon for Nimbostratus rankNimbostratus
Jun 15, 2016

Get current connection of pool members

Hi, I tried write a script (python) to checking numeber current connection and when is 0 mark member 'disabled'.

How can I get only value of current connection and then check is 0 ?

   member_stat = b.LocalLB.Pool.get_member_statistics( ['/Common/' + pool], [[{'address': member, 'port': port}]])
   for statistic in member_stat:
   ....     
   if ( 'STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS' == 0 ) :
      pl.set_member_session_enabled_state(['/Common/' + pool ], [[{'address': member, 'port': port}]], [['STATE_DISABLED']])
      pl.set_member_monitor_state(['/Common/' + pool ], [[{'address': member, 'port': port}]], [['STATE_DISABLED']])

2 Replies

  • no a python expert but here is loop example :

    res = b.LocalLB.Pool.get_all_member_statistics(pool_names = ['/Common/pool_turnkey'])
    
    for statistic in res[0].statistics:
        print "member ip:port " + statistic.member.address  + ":%s"  % statistic.member.port
        print statistic.statistics[4].type 
        print statistic.statistics[4].value 
        if statistic.statistics[4].value.high == 0: print "can be disabled"
    

    output:

    member ip:port: /Common/172.16.20.1
    STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS
    (Common.ULong64){
       high = 0
       low = 0
     }
    can be disabled
    member ip:port: /Common/172.16.20.3
    STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS
    (Common.ULong64){
       high = 0
       low = 0
     }
    can be disabled
    
  • I can't call attribute like statistics,type,value

      for statistic in res[0].statistics:
    AttributeError: 'dict' object has no attribute 'statistics'