docker - 从外部容器向 docker 上的 statsd/ Graphite 数据库发送数据时出现问题

标签 docker graphite statsd

我在将数据发送到 statsd 容器时遇到问题。我可以在容器本身的命令行上成功发送数据。我需要能够从主机或另一个 Docker 容器向它发送统计数据。

我正在使用 Kitematic,我可以看到在两个容器上都检查了“桥”网络的选择。使用桥接网络是我为这个问题找到的建议。

我还尝试在运行构建容器的命令时将“-P”传递给 Docker,因为这应该暴露端口。从另一个容器发送数据时,我没有注意到它的行为方式有什么不同。

使用 localhost 上的端口 8125 创建虚假统计信息的代码示例(取自此 Docker 容器网页 https://hub.docker.com/r/graphiteapp/graphite-statsd)

Let's fake some stats with a random counter to prove things are working.


while true; do echo -n "example:$((RANDOM % 100))|c" | nc -w 1 -u     127.0.0.1 8125; done

使用以下命令创建容器:
docker run -d --name graphite --restart=always -p 80:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 graphiteapp/graphite-statsd

我试过确保两者都在同一个“桥”网络上。我在 Windows 10 Enterprise 上运行 Docker Desktop。我在 Linux 上找到了几个处理 iptables 和网络的命令,但我觉得我错过了一些东西。我还可能会提到 statsd 默认在端口 8125 上使用 UDP 连接。

如果我尝试从桥接网络上的另一个容器运行示例命令,我不会得到任何结果。我知道数据(来自另一个容器)没有正确传递,因为我在 statsd 仪表板上收到的指标中看不到它。

我可以ping localhost:8125并从另一个容器中获得响应。从外部(主机上的 Powershell 窗口)它不会解决。
 PING localhost:8125 (127.0.0.1): 56 data bytes
 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.024 ms
 64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.052 ms
 64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.031 ms
 ^C
 --- localhost:8125 ping statistics ---
 3 packets transmitted, 3 packets received, 0% packet loss
 round-trip min/avg/max = 0.024/0.035/0.052 ms>

如果我运行 docker container ls然后我得到以下信息:

updated container ls screenshot

最佳答案

发现需要获取每个容器的具体IP地址,运行docker inspect (name of network)可以找到.在这种情况下,bridge .

然后我需要指定容器的 IP 地址。我用该 IP 地址替换了建议的地址,它起作用了。

container reachable from another on the bridge network

关于docker - 从外部容器向 docker 上的 statsd/ Graphite 数据库发送数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57015254/

相关文章:

docker - 无法构建克隆的 Jekyll 站点 - jekyll 3.8.5 |错误 : Permission denied @ dir_s_mkdir -/srv/jekyll/_site

mongodb - 如何将卷添加到docker mongo容器

Graphite :将与模式匹配的所有统计信息相加?

javascript - RUM(真实用户监控)用户感知的加载时间和位置

scale - 使用多台服务器扩展statsd

Docker 运行和体积说明

java - 在 docker 镜像中部署 WAR 文件的正确方法

postgresql - 使用 postgres 存储时删除 Graphite 中的系列?

ruby - redis batsd (statsd) 计数器