Node中统计每个容器总连接数
可以使用ss替代netstat
#if ! command -v jq &>/dev/null; then
# yum install -y jq
#fi
printf "| %-150s | %-15s |\n" "名称" "连接数"
docker ps --format "{{.ID}} {{.Names}}"|
while read cid cname; do
pid=$(docker inspect --format '{{.State.Pid}}' "${cid}")
r=`nsenter -t $pid -n netstat -anptu | wc -l`
printf "| %-150s | %-15s |\n" "$cname" "$r"
done
查找所有Node中所有的Docker容器连接中包含192.168.0.15
关键字的
#!/bin/bash
#if ! command -v jq &>/dev/null; then
# yum install -y jq
#fi
printf "| %-150s | %-15s |\n" "名称" "连接数"
docker ps --format "{{.ID}} {{.Names}}"|
while read cid cname; do
pid=$(docker inspect --format '{{.State.Pid}}' "${cid}")
r=`nsenter -t $pid -n netstat -anptu | grep -e '192.168.0.15' -e '192.168.0.17' |wc -l`
if [ "$r" -gt 0 ]; then
printf "| %-150s | %-15s |\n" "$cname" "$r"
fi
done