我想使用influxdb
从多个go服务中收集telegraf ``inputs.docker_log
中的日志。
我发现influxdb并不包含我在docker service logs
中可以看到的所有记录。
我做了简单的go脚本。并以不同的延迟进行几次实验。
package main
import (
"time"
"github.com/labstack/gommon/log"
)
func main() {
log.SetLevel(log.DEBUG)
for i := 0; i < 5; i++ {
writeSomething()
<-time.After(10 * time.Second)
}
}
func writeSomething() {
delay := 50 * time.Millisecond
log.Debug("A")
<-time.After(delay)
log.Debug("B")
<-time.After(delay)
log.Debug("C")
<-time.After(delay)
}
当延迟<1秒时,我发现了一个问题。
例如。延迟= 50毫秒
Docker service logs
5次显示所有3个变体(A,B,C)
liquineq_sender.1.0jvam7vg63cm@Ivan-Lenovo-ideapad | {"time":"2019-09-26T13:47:17.115060311Z","level":"DEBUG","prefix":"-","file":"main.go","line":"20","message":"A"}
liquineq_sender.1.0jvam7vg63cm@Ivan-Lenovo-ideapad | {"time":"2019-09-26T13:47:17.165383407Z","level":"DEBUG","prefix":"-","file":"main.go","line":"23","message":"B"}
liquineq_sender.1.0jvam7vg63cm@Ivan-Lenovo-ideapad | {"time":"2019-09-26T13:47:17.21562549Z","level":"DEBUG","prefix":"-","file":"main.go","line":"26","message":"C"}
但是我在influxdb中找不到其中的一些:
> select message from docker_log;
name: docker_log
time message
---- -------
1569505640000000000 2019-09-26T13:47:18Z I! Starting Telegraf 1.12.2
1569505640000000000 t=2019-09-26T13:47:12+0000 lvl=info msg="Starting Grafana" logger=server version=6.3.0-pre commit=unknown-dev branch=master compiled=2019-06-21T08:57:10+0000
1569505640000000000 {"time":"2019-09-26T13:47:17.115060311Z","level":"DEBUG","prefix":"-","file":"main.go","line":"20","message":"A"}
1569505647000000000 {"time":"2019-09-26T13:47:27.265995126Z","level":"DEBUG","prefix":"-","file":"main.go","line":"20","message":"A"}
1569505657000000000 {"time":"2019-09-26T13:47:37.417263994Z","level":"DEBUG","prefix":"-","file":"main.go","line":"20","message":"A"}
1569505658000000000 {"time":"2019-09-26T13:47:37.517861048Z","level":"DEBUG","prefix":"-","file":"main.go","line":"26","message":"C"}
1569505668000000000 {"time":"2019-09-26T13:47:47.568291482Z","level":"DEBUG","prefix":"-","file":"main.go","line":"20","message":"A"}
1569505678000000000 {"time":"2019-09-26T13:47:57.71926933Z","level":"DEBUG","prefix":"-","file":"main.go","line":"20","message":"A"}
如果增加延迟长达1秒,则influxdb包含所有记录。
有没有办法设置telegraf / influxdb来解析毫秒?
答案 0 :(得分:0)
我通过在Telegraf配置中添加以下设置解决了问题。
[agent]
precision = "100ns"
说明:
telegraf的日志累加器具有方法getTime
。该方法将日志的时间用precision
舍入。
从AgentConfig:
// By default or when set to "0s", precision will be set to the same
// timestamp order as the collection interval, with the maximum being 1s.
// ie, when interval = "10s", precision will be "1s"
// when interval = "250ms", precision will be "1ms"
// Precision will NOT be used for service inputs. It is up to each individual
// service input to set the timestamp at the appropriate precision.