Skip to content

Instantly share code, notes, and snippets.

@Becram
Last active April 16, 2021 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Becram/7f1c10f7305a73cbe9b58ea76067da93 to your computer and use it in GitHub Desktop.
Save Becram/7f1c10f7305a73cbe9b58ea76067da93 to your computer and use it in GitHub Desktop.
script to find the tcp connection status
#!/bin/bash
pods=$(kubectl get po -nlinkerd -ojsonpath="{range .items[*]}{.metadata.name} {.metadata.namespace}{'\n'}{end}")
IFS=" "
while read name namespace; do
tcp=$(kubectl exec -n $namespace $name linkerd-proxy -- cat /proc/net/tcp)
close_wait=$(echo $tcp | awk 'BEGIN {cnt=0} $4==08 {cnt++} END {print cnt}')
fin_wait_2=$(echo $tcp | awk 'BEGIN {cnt=0} $4==05 {cnt++} END {print cnt}')
if [ "$close_wait" -gt "0" -o "$fin_wait_2" -gt "0" ]; then
echo "$name.$namespace has $close_wait sockets in CLOSE_WAIT and $fin_wait_2 sockets in FIN_WAIT_2"
else
echo "$name.$namespace is okay"
fi
done <<< "$pods"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment