Telegraf守护程序未从与Dokku一起部署的应用程序接收度量 [英] Telegraf daemon not receiving metrics from app deployed with Dokku
问题描述
过去我已经使用Telegraf + InfluxDB + Grafana监视过NodeJS应用程序,但这是我第一次尝试监视Dokku应用程序,但到目前为止没有成功.
I've already monitored NodeJS apps in the past with Telegraf+InfluxDB+Grafana, but it's the first time I try to monitor a Dokku app, without success so far.
我有以下设置
app server monitoring serveur
- telegraf daemon (listening on udp 8125) ------> InfluxDB + Grafana
- dokku
- myapp : sending metrics on localhost:udp:8125
我有一个问题,telegraf
无法接收从udp://localhost:8125
上的myapp
发送的度量.
I have the issue that metrics sent from myapp
on udp://localhost:8125
are not received by telegraf
.
从telegraf到influxdb和grafana的连接是可以的,因为我在应用服务器上运行了以下命令:
The connectivity from telegraf to influxdb and grafana is ok, because I ran the following command on the app server:
echo "foobar:1|c" | nc -u -w0 127.0.0.1 8125
我可以在Grafana内部看到foobar
计数器增量.
And I could visualize inside Grafana the foobar
counter increment.
所以我猜这是由于myapp
或我配置Dokku引起的.
So I'm guessing the issue is due to myapp
or how I configured Dokku.
在myapp(节点JS应用)中,我正在使用热门图片包以发送指标(也尝试使用 lynx 失败).
In myapp (a node JS app), I'm using the hot-shots package to send metrics (also tried with lynx without success).
这是我用于实例化statsd客户端的代码.
This is the code I use to instanciate the statsd client.
var StatsD = require('hot-shots');
var client = new StatsD();
// Attaching an error handler to client's socket
client.socket.on('error', function(error) {
console.error('StatsD client error in socket: ', error);
});
我会在应用启动时增加一个计数器,以表示重新启动.这是通过以下代码完成的:
I increment a counter on app startup to signal a restart. This is done with the following code:
metrics.increment('server_restart', function(err, bytes) {
if (err) {
console.log(err);
} else {
console.log('StatsD sent : ', bytes);
}
});
在应用服务器内部,执行部署后,我运行了dokku logs myapp
.
Inside the app server, I ran dokku logs myapp
after performing a deployment.
我得到以下输出
$ dokku logs myapp
2017-05-06T14:51:19.977938845Z app[web.1]:
2017-05-06T14:51:19.977996938Z app[web.1]: > myapp@1.0.0 start /app
2017-05-06T14:51:19.978002950Z app[web.1]: > node .
2017-05-06T14:51:19.978005766Z app[web.1]:
2017-05-06T14:51:21.849086537Z app[web.1]: StatsD sent : 18
$
因此,指标有效负载似乎已在正确的端口上正确发送,但从未到达Telegraf.
So it seems that the metrics payload is properly sent on the right port, but it never reaches telegraf.
- Dokku中是否有任何配置可以授权向本地主机的外部UDP请求?
- 我该怎么做才能进一步调试?
推荐答案
按照作者在另一个线程中的要求,解决方案似乎是:
As the author requested in another thread the solution seems to be:
通过默认情况下,Docker容器可以调用主机的localhost UDP吗?
仅当您要侦听未发送的请求时才需要打开端口.默认情况下,Docker为您的容器提供必要的网络名称空间,以使其与主机或外界通信.
Opening ports is only needed when you want to Listen for the requests not sending. By default Docker provides the necessary network namespace for your container to communicate to the host or outside world.
因此,您可以通过两种方式做到这一点:
So, you could do it in two ways:
-
在
docker run
中使用--net host
并将请求发送到localhost:8125
,在这种情况下,您的容器化应用有效地共享了主机的网络堆栈.因此,localhost指向主机中已在运行的守护程序.
use
--net host
in yourdocker run
and send requests tolocalhost:8125
in this case you containerized app is effectively sharing the host's network stack. So localhost points to the daemon that's already running in your host.
与容器网络网关(通常为172.17.0.1
)或容器中主机的主机名对话.然后,您就可以将数据包发送到主机中的守护程序.
talk to the container network gateway (which is usually 172.17.0.1
) or your host's hostname from your container. Then your are able to send packets to your daemon in your host.
这篇关于Telegraf守护程序未从与Dokku一起部署的应用程序接收度量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!