Last active
February 22, 2018 18:08
-
-
Save iaon/cfcdd32031d93aab7120f4408a3efa9d to your computer and use it in GitHub Desktop.
Docker Netstat counts tcp connections by state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while : | |
do | |
date | |
containers=$(docker ps --format "{{.Names}}:{{.ID}}") | |
for c in $containers | |
do | |
echo $c | |
CID=$(echo $c | awk -F ":" '{print $2}') | |
nsenter -t $(docker inspect -f '{{.State.Pid}}' $CID) -n netstat -ant |tail -n +3|awk '{print $6}' | sort | uniq -c | |
echo ---------------------- | |
done | |
echo ================== | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output example