Forum Discussion

syncretism's avatar
syncretism
Icon for Nimbostratus rankNimbostratus
Apr 13, 2017

Is There a "Key" to Rewriting TMSH Commands as RESTful Calls? +Example

Hiya,

 

I'm running this command remotely to get a pool member's active connections, but it's a) awfully kludgy and b) I'd like get the results from the RESTful API:

 

ssh $ID@$F5_HOST "show /ltm pool $POOL members { $POOL_MEMBER } default" | awk '/| Current Connections/ {print $(NF-1)}'

 

Awk grabs this line and returns the "ServerSide" stats for that pool:

 

| Current Connections 0 -

 

I've had some luck constructing URIs to pass into cURL from other TMSH commands, but I haven't really figured out a pattern I can follow to create arbitrary API requests. Do any of you have a handy trick or rule to follow?

 

Worst case, how the heck can I pull specific Traffic and Connection Queue statistics for pools and pool members via the API? Thanks?

 

3 Replies

  • Kevin_K_51432's avatar
    Kevin_K_51432
    Historic F5 Account

    Greetings, I've had good luck using most of the Rest API by simply appending "stats" to the end of a query. I'm by not means an expert here, but I do use Rest quite often due to its simplicity:

    So I would grab the stats for a pool named "default_gw" using the following:

    curl -sk -u admin:admin https://172.24.64.39/mgmt/tm/ltm/pool/~Common~default_gw/members/~Common~10.12.23.27:0/stats 
    

    The output would be similar to:

    "generation":1
    "selfLink":"https://localhost/mgmt/tm/ltm/pool/~Common~default_gw/members/~Common~10.12.23.27:0/stats?ver=12.0.0"
    "entries":{"https://localhost/mgmt/tm/ltm/pool/~Common~default_gw/members/~Common~10.12.23.27:0/~Common~10.12.23.27:0/stats":{"nestedStats":{"kind":"tm:ltm:pool:members:membersstats"
    "selfLink":"https://localhost/mgmt/tm/ltm/pool/~Common~default_gw/members/~Common~10.12.23.27:0/~Common~10.12.23.27:0/stats?ver=12.0.0"
    "entries":{"addr":{"description":"10.12.23.27"}
    "connq.ageEdm":{"value":0}
    "connq.ageEma":{"value":0}
    "connq.ageHead":{"value":0}
    "connq.ageMax":{"value":0}
    "connq.depth":{"value":0}
    "connq.serviced":{"value":0}
    "curSessions":{"value":0}
    "monitorRule":{"description":"/Common/gateway_icmp (pool monitor)"}
    "monitorStatus":{"description":"up"}
    "nodeName":{"description":"/Common/10.12.23.27"}
    "poolName":{"description":"/Common/default_gw"}
    "port":{"value":0}
    "serverside.bitsIn":{"value":175344}
    "serverside.bitsOut":{"value":215808}
    "serverside.curConns":{"value":0}
    "serverside.maxConns":{"value":10}
    "serverside.pktsIn":{"value":334}
    "serverside.pktsOut":{"value":240}
    "serverside.totConns":{"value":94}
    "sessionStatus":{"description":"enabled"}
    "status.availabilityState":{"description":"available"}
    "status.enabledState":{"description":"enabled"}
    "status.statusReason":{"description":"Pool member is available"}
    "totRequests":{"value":0}}}}}}
    
    • syncretism's avatar
      syncretism
      Icon for Nimbostratus rankNimbostratus

      Stats! I knew I had that somewhere in my notes. This is great - I'm passing the JSON object to jq and watching the number of connections in my script. Just what I needed. Thanks so much!

       

    • Kevin_K_51432's avatar
      Kevin_K_51432
      Historic F5 Account

      I was equally happy at discovering this one =) You're very welcome, glad this was helpful!