将Docker容器日志发送到Elasticsearch的最佳方法是什么?

huangapple go评论75阅读模式
英文:

What is the best way to get Docker container logs into Elasticsearch?

问题

我有一个在容器中运行的Go应用程序,它有很多日志记录:

log.Println("Something happened!")

由于我可以通过ssh登录到运行该应用程序的服务器,我可以使用docker logs -f [id]来查看stderr输出,这一切都很好。

但现在我想将日志记录到Elasticsearch中。

怎样才是最好的方法呢?我看到了很多复杂的方法。

一种方法是使用GELF日志格式和Logstash,但我能找到的唯一的Go GELF格式化程序已经很老了。

或者将日志记录到文件中,然后使用Filebeat。但是我不想要跳过这个文件步骤,对吗?

英文:

I've got a Go app running in a container, and it does a lot of logging:

log.Println("Something happened!")

Since I can ssh into the server it's running on I can do docker logs -f [id] to look at the stderr output, that's all fine.

But now I want the logs to go into Elasticsearch.

What's the best way to do that? I've been seeing so many complicated ways to do it.

One way was to use the GELF logging format and Logstash, but the only Go GELF formatter I can find is super old.

Or log to a file and use Filebeat. But would I not want to skip that file step?

答案1

得分: 0

我会尝试使用Docker来设置Fluentd:

https://www.fluentd.org/guides/recipes/docker-logging

https://docs.docker.com/config/containers/logging/fluentd/

然后,将Fluentd配置为将日志推送到Elasticsearch:

https://docs.fluentd.org/output/elasticsearch

英文:

I would try to set up fluentd with docker:

https://www.fluentd.org/guides/recipes/docker-logging

https://docs.docker.com/config/containers/logging/fluentd/

And then make fluentd to push to elasticsearch:

https://docs.fluentd.org/output/elasticsearch

huangapple
  • 本文由 发表于 2022年11月19日 02:56:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/74494217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定