简体   繁体   English

从 kafka 获取日志并发送到 loki

[英]Get logs from kafka and send to loki

hope you're all well during this pandemic.希望你们在这次疫情期间一切都好。

I've got a kubernetes cluster running.我有一个 kubernetes 集群正在运行。 The comunication between pods is done through kafka. Pod 之间的通信是通过 kafka 完成的。 It is currently logging to stdout only.它当前仅记录到标准输出。 No files.没有文件。 no kafka topic.没有卡夫卡主题。 This is obviously pretty bad.这显然很糟糕。

I want to setup a grafana instance that lets me centralize all logs there.我想设置一个 grafana 实例,让我在那里集中所有日志。 The storage would be Loki + S3存储将是 Loki + S3

In order to do that, I found that many people use tools like Fluentd, FluentBit and Promtail, which centralizes the logs and sends them to Loki.为了做到这一点,我发现很多人使用 Fluentd、FluentBit 和 Promtail 之类的工具,这些工具可以集中日志并将它们发送给 Loki。 However, I already have Kafka running.但是,我已经运行了 Kafka。 I can't see why I'd use some tool like fluentd if I can send all logs to kafka through a "logging" topic.如果我可以通过“日志记录”主题将所有日志发送到 kafka,我不明白为什么我会使用像 fluentd 这样的工具。

My question is: How could I send all messages inside the logging topic to Loki?我的问题是:如何将日志主题内的所有消息发送给 Loki? Fluentd cannot get input from kafka. Fluentd 无法从 kafka 获取输入。

Would I have to setup some script that runs periodically, sorts data and sends it to loki directly?我是否必须设置一些定期运行的脚本,对数据进行排序并将其直接发送给 loki?

I recommend you to use promtail because is also from Grafana and not use the kafka solution.我建议您使用 promtail,因为它也来自 Grafana,而不是使用 kafka 解决方案。

If you send the logs from your apps to kafka then you need to:如果您将应用程序中的日志发送到 kafka,那么您需要:

  • modify your apps to send to kafka instead of stdout修改您的应用程序以发送到 kafka 而不是标准输出
  • configure a log forwarder to send messages on kafka to loki (it can be fluentd)配置日志转发器以将 kafka 上的消息发送到 loki(可以流利)

And if you use one the normal proposed approach you need to:如果您使用一种通常建议的方法,您需要:

  • configure a log forwarder to send messages from docker stdout to loki (you can use promtail default configuration)配置日志转发器以将消息从 docker 标准输出发送到 loki(可以使用 promtail 默认配置)

But if you want to go for your solution with kafka in the middle there are some plugins of fluentd to configure kafka as input and output.但是,如果您想 go 为您的解决方案与 kafka 在中间有一些流利的插件配置 kafka 作为输入和 output。 https://github.com/fluent/fluent-plugin-kafka https://github.com/fluent/fluent-plugin-kafka

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

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