【问题标题】:How to monitor and log networking latency between group of docker containers?如何监控和记录 docker 容器组之间的网络延迟?
【发布时间】:2019-07-24 09:57:44
【问题描述】:
我在 3 台机器上设置了 10 个来自不同图像的 docker 容器。我需要监控和记录每个容器之间的网络延迟/数据包延迟。有合适的工具吗?
我可以实现类似的东西
while true; for host in "${my_hosts[*]}"; do ping -c 1 "$host" > latency.log; done done
并在每台机器上启动它,跟踪latency.log 以像Prometheus 一样进行监控。但这感觉就像重新发明了一个方形轮子。
【问题讨论】:
标签:
docker
networking
monitoring
prometheus
latency
【解决方案1】:
我希望我了解您的需求,我自己正在实施这样的事情。
我用 prometheus 和 graphana 测试了 netdata,用 elastic 和 kibana 测试了 metricbeat\filebeat
我们选择使用弹性(ELK 堆栈),因为在同一个数据库中您可以处理指标和文本数据。
希望我给了你一些指示。
【解决方案2】:
我最后的设置是:
-
volume 在容器之间共享 hosts,
- 测量将
hosts 馈送到fping 的延迟,
- 将
fping 输出写入日志文件,
- 通过
mtail将此日志文件提供给Prometheus。
我已经围绕fping 实现了包装器,让它与mtail 一起工作:
#!/usr/bin/env bash
# It wraps `fping -lDe` to give output for multiple hosts one line at time (for `mtail` parser)
# Default `fping -lDe` behavior produce X lines at time where X = number of hosts to ping
# This waits for hosts file with `# docker` section as described in usage guide
echo "Measuing time delays to docker hosts from '$1'"
# take hostnames after '# docker' comment line
hosts=$(cat $1 | sed -n '/# docker/,$p' | sed 1,1d)
trap "exit" INT # exit loop by SIGINT
# start `fping` and write it's output to stdout line by line
stdbuf -oL fping -lDe $hosts |
while IFS= read -r line
do
echo $line
done
日志文件有mtail解析器:
gauge delay by host
gauge loss by host
# [<epoch_time>] <host> : [2], 84 bytes, <delay> ms (0.06 avg, 0% loss)
/\[(?P<epoch_time>\d+\.\d+)\] (?P<host>[\w\d\.]*) : \[\d+\], \d+ \w+, (?P<delay>\d+\.\d+) ms \(\d+\.\d+ avg, (?P<loss>\d+)% loss\)/ {
delay[$host]=$delay
loss[$host]=$loss
}
现在您可以将fping 和mtail 添加到您的图像中,让它为Prometheus 提供延迟和损失指标。
参考资料:
- mtail:https://github.com/google/mtail
- fping:https://fping.org/