使用redis-traffic-stats对k8s容器服务进行分析
github地址:https://github.com/hirose31/redis-traffic-stats
安装 :
# yum -y install perl-core perl-Net-Pcap
# git clone https://github.com/hirose31/redis-traffic-stats.git
# cd redis-traffic-stats/
# perl Build.PL
# ./Build
# ./Build test
# ./Build install
使用说明 :
直接抓包分析
# redis-traffic-stats -i eth0 -t 10 //-t指定持续时间(s)
通过tcpdumop抓包分析
# tcpdump -s 65535 tcp port 6379 -w redis.pcap -i eth0
(wait for a while and stop by ^C)
# redis-traffic-stats -r redis.pcap
容器服务分析 :
由于需要分析k8s集群内部容器服务,先获取pod的ip地址,然后再node节点通过cni0网卡进行抓包
# tcpdump -s 65535 tcp port 6379 and net 172.144.0.33 -i cni0 -w /tmp/redis_tcpdump/172.144.0.33.pcap
再进行分析即可
# redis-traffic-stats -r 172.144.0.33.pcap
多线程批量分析节点上的pod脚本 :
# cat check_redis_useinfo.sh
#!/bin/bash
NS=prod //输入对应的namespace
IPADDR=`ifconfig eth0 | grep inet | awk '{print $2}'`
NODE_PODLIST=`kubectl get pod -n $NS -o wide | grep $IPADDR | grep mypod awk -v CHECK_TIME=$1 '{printf "tcpdump -G %s -W 1 -s 65535 tcp port 6379 and net %s -i cni0 -w /tmp/redis_tcpdump/%s.pcap\n",CHECK_TIME,$6,$1}'`
[ -e /tmp/fd1 ] || mkfifo /tmp/fd1
exec 3<>/tmp/fd1
rm -rf /tmp/fd1
for ((i=1;i<=20;i++))
do
echo >&3
done
IFS=$'\n\n'
for i in $NODE_PODLIST
do
read -u3
{
echo "/usr/sbin/$i" | bash -x
}&
done
wait
exec 3<&-
exec 3>&-
# ./check_redis_useinfo.sh 10 //指定抓取时间(s)
抓取结果示例 :
# redis-traffic-stats
## Summary
* Duration:
* 2021-04-18 10:56:13 - 2021-04-18 11:05:59 (586s)
* Total Traffic:
* 8 bytes (0.01 bytes/sec)
* Total Requests:
* 20 requests (Avg 0.03 req/sec, Peak 20.00 req/sec)
## Top Commands
### By count
Command | Count | Pct| Req/sec
-----------------|-------:|-------:|---------:
INFO | 20 | 100.00 | 0.03
### By traffic
Command | Bytes | Byte/sec
-----------------|----------:|-------------:
INFO | 8 | 0.01
## Command Detail
### INFO
Key | Bytes | Byte/sec | Count | Pct| Req/sec
-|----------:|-------------:|-------:|-------:|---------:
## Slow Commands
Time | Command
------:|------------------------------------------------------------------------
586.596 | INFO

浙公网安备 33010602011771号