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
Copyright © 运维知识库 all right reserved,powered by Gitbook文件修订时间: 2023-09-19 10:45:38

results matching ""

    No results matching ""