使用脚本获取实现docker stats数据收集,并在每行前面增加上采集数据是时间,方便分析及制作图表
#!/bin/bash
#num = ${1800} ## 30分钟*60秒
rm -rf ./testlog/*.log
#./nmon -s1 -c1800 -f -m ./testlog
for ((i=1; i<=1800; i++))
do
echo $i
#docker_id=docker ps|awk '{print $1}'
docker stats --no-stream | awk '/elasticsearch/ {print strftime("时间:%m-%d-%Y %H:%M:%S",systime()), $0}' >>./testlog/es.log
docker stats --no-stream | awk '/redis/ {print strftime("时间:%m-%d-%Y %H:%M:%S",systime()), $0}' >>./testlog/redis.log
sleep 1
done

本文介绍了一个使用bash脚本定时收集Docker容器统计数据的方法,通过脚本每秒采集一次数据,并将时间戳与DockerStats输出关联,分别记录到针对不同容器的日志文件中,便于后续的数据分析和图表制作。
2317

被折叠的 条评论
为什么被折叠?



