简体   繁体   English

如何将日志发送到 Graylog (Docker)?

[英]How to send logs to Graylog (Docker)?

I'm new to both Docker and Graylog.我是 Docker 和 Graylog 的新手。 Can anyone show me an example of how to send log data to the Graylog server?谁能告诉我如何将日志数据发送到 Graylog 服务器的示例?

Actually, it is pretty easy!其实,这很容易! Graylog's preferred Log Format - GELF - is supported by Docker natively. Graylog 的首选日志格式 - GELF - 由 Docker 原生支持。 So if you are using Docker logs already (Docker's internal logging functionality) you can just use Docker's built-in support, that will forward all logs from your container to the specified GELF endpoint.因此,如果您已经在使用 Docker 日志(Docker 的内部日志记录功能),您可以只使用 Docker 的内置支持,它将所有日志从您的容器转发到指定的 GELF 端点。 You will have to create a GELF UDP input on the Graylog server.您必须在 Graylog 服务器上创建 GELF UDP 输入。

https://docs.docker.com/engine/admin/logging/overview/ https://docs.docker.com/engine/admin/logging/overview/

For running a container from command line that sends all logs to Graylog via GELF just use the options log-driver and gelf-address :要从命令行运行容器,通过 GELF 将所有日志发送到 Graylog,只需使用选项log-drivergelf-address

docker run -dit \
--log-driver=gelf \
--log-opt gelf-address=udp://192.168.0.42:12201 \
alpine sh

If Graylog exposes a syslog listener you could send them with Docker syslog logging driver.如果 Graylog 公开了 syslog 侦听器,您可以将它们与 Docker syslog 日志记录驱动程序一起发送。 But since you say you are new to Graylog, have a look at https://github.com/sematext/sematext-agent-docker which should work for you with minimal effort and will be able to also capture Docker metrics and events, not just logs, which is handy.但是,既然您说您是 Graylog 的新手,请查看https://github.com/sematext/sematext-agent-docker ,它应该以最少的努力为您工作,并且还能够捕获 Docker 指标和事件,而不是只是日志,这很方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM