Forum Discussion

Blue_whale's avatar
Blue_whale
Icon for Cirrocumulus rankCirrocumulus
Jun 28, 2024

Need help on CLI command to fetch < VIP Name + current connections >

Hello Experts , 

I need help in modifying below command which should also give me information of VIP name along with current connection . 

 

show ltm virtual recursive all | grep 'Availability\|Current Connections'

 

 

As you can see this command only gives info of current connection but it will not tell which VIP has the current connection value ... 


blue.whale@(F5-BIGIP-ACT)(cfg-sync In Sync)(Active)(/Common)(tmos)# show ltm virtual recursive all | grep 'Availability\|Current Connections'
Display all 1942 items? (y/n) y
  Availability     : available
  Current Connections                        0          0        -
  Availability     : available
  Current Connections                       38          0        -
  Availability     : available
  Current Connections                        0          0        -
  Availability     : available
  Current Connections                       73          0        -
  Availability     : available
  Current Connections                        0          0        -
  Availability     : available
  Current Connections                        0          0        -

  • Hi Blue_whale you could use a bash script to do this pretty easily (or write a tmsh script to do the same, but bash might be a little easier if you're not familiar with the tmsh scripting):

    #!/bin/bash
    
    tmsh_show=$(tmsh show ltm virtual recursive all field-fmt)
    
    vipname=""
    vipconns=""
    vipstate=""
    
    echo "$tmsh_show" | while IFS= read -r line; do
        line=$(echo "$line" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
    
        if [ -z "$line" ]; then
            continue
        fi
    
        if [[ "$line" =~ ^ltm\ virtual\ ([^\ ]+) ]]; then
            vipname="${BASH_REMATCH[1]}"
        fi
    
        if [[ "$line" =~ ^clientside\.cur-conns\ ([0-9]+) ]]; then
            vipconns="${BASH_REMATCH[1]}"
        fi
    
        if [[ "$line" =~ ^status\.availability-state\ ([^\ ]+) ]]; then
            vipstate="${BASH_REMATCH[1]}"
        fi
    
        if [[ "$line" == "}" ]]; then
            printf "Vip Name: %s\n" "$vipname"
            printf "Current Connections: %s\n" "$vipconns"
            printf "Availability State: %s\n" "$vipstate"
            printf "\n"
    
            vipname=""
            vipconns=""
            vipstate=""
        fi
    done

    which on my fairly empty test box running 15.1.x shows results like this:

    [root@ltm15:LICENSE EXPIRES IN 1 DAYS:Active:Standalone] tmp # ./vip-glance.sh
    Vip Name: acme_handler_vip
    Current Connections: 9
    Availability State: available
    
    Vip Name: nginx-vip-tls
    Current Connections: 0
    Availability State: available
    
    Vip Name: self.listener
    Current Connections: 0
    Availability State: unknown
    
    Vip Name: tcp_duplication
    Current Connections: 0
    Availability State: offline

     

  • Hi Blue_whale you could use a bash script to do this pretty easily (or write a tmsh script to do the same, but bash might be a little easier if you're not familiar with the tmsh scripting):

    #!/bin/bash
    
    tmsh_show=$(tmsh show ltm virtual recursive all field-fmt)
    
    vipname=""
    vipconns=""
    vipstate=""
    
    echo "$tmsh_show" | while IFS= read -r line; do
        line=$(echo "$line" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
    
        if [ -z "$line" ]; then
            continue
        fi
    
        if [[ "$line" =~ ^ltm\ virtual\ ([^\ ]+) ]]; then
            vipname="${BASH_REMATCH[1]}"
        fi
    
        if [[ "$line" =~ ^clientside\.cur-conns\ ([0-9]+) ]]; then
            vipconns="${BASH_REMATCH[1]}"
        fi
    
        if [[ "$line" =~ ^status\.availability-state\ ([^\ ]+) ]]; then
            vipstate="${BASH_REMATCH[1]}"
        fi
    
        if [[ "$line" == "}" ]]; then
            printf "Vip Name: %s\n" "$vipname"
            printf "Current Connections: %s\n" "$vipconns"
            printf "Availability State: %s\n" "$vipstate"
            printf "\n"
    
            vipname=""
            vipconns=""
            vipstate=""
        fi
    done

    which on my fairly empty test box running 15.1.x shows results like this:

    [root@ltm15:LICENSE EXPIRES IN 1 DAYS:Active:Standalone] tmp # ./vip-glance.sh
    Vip Name: acme_handler_vip
    Current Connections: 9
    Availability State: available
    
    Vip Name: nginx-vip-tls
    Current Connections: 0
    Availability State: available
    
    Vip Name: self.listener
    Current Connections: 0
    Availability State: unknown
    
    Vip Name: tcp_duplication
    Current Connections: 0
    Availability State: offline