简体   繁体   English

使用 Logstash 可靠性和可用性记录到 elasticsearch,处理丢失的日志?

[英]Logging to elasticsearch using Logstash reliability and availability, handling missing logs?

I 'm following this article on ELK: Building Logging System in Microservice Architecture with ELK Stack and Serilog .NET Core , in this architecture, serilog logs to Logstash and then logstash pushes to Elastic search, what if the elastic search is not reachable or if the logstash service is down or if the network is down or the system is down, in short where I 'm heading to, how can I ensure my logs are not lost in all the scenarios, the logs should be available offline as well, I thought of storing first in log files and then processing the logs from file to elastic search however the files will grow over a period of time and then I have to take care that there are no duplicate messages and the messages needs to be deleted as well, and most importantly there is no deadlock kind of situation in reading and writing file, could you please help me to understand whether ELK takes care and instead of logstash if I use fluend or fluentbit, are they better??我正在关注关于 ELK 的这篇文章: 使用 ELK Stack 和 Serilog .NET Core 在微服务架构中构建日志系统,在这个架构中,serilog 记录到 Logstash,然后将 logstash 推送到 Elastic 搜索,如果无法访问弹性搜索或者如果logstash 服务已关闭或网络已关闭或系统已关闭,简而言之,我要去哪里,如何确保我的日志在所有情况下都不会丢失,日志也应该可以离线使用,我想首先存储在日志文件中,然后将日志从文件处理到弹性搜索,但是文件会在一段时间内增长,然后我必须注意没有重复的消息并且消息也需要删除,并且最重要的是在读写文件时没有死锁这种情况,请你帮我了解一下ELK是否照顾好,如果我使用fluend或fluentbit而不是logstash,它们会更好吗?

Code:代码:

var log = new LoggerConfiguration()
         .WriteTo.Console()
         .WriteTo.Http("http://localhost:8080")
         .CreateLogger();


while (true)
{
    var customer = Customer.Generate();
    log.Information("{@customer} registered", customer);
    Thread.Sleep(1000);
}

output: output:

[13:56:02 INF] {"FirstName": "Lourdes", "LastName": "Kreiger", "SSNumber": "350-11-7869", "$type": "Customer"} registered
[13:56:03 INF] {"FirstName": "Desmond", "LastName": "Balistreri", "SSNumber": "929-58-1854", "$type": "Customer"} registered
...

Sending logs using ELK使用 ELK 发送日志

Http input listening port 8080 Http输入监听端口8080

input {
    http {
        #default host 0.0.0.0:8080
        codec => json
    }
}

# Separate the logs
filter {
    split {
        field => "events"
        target => "e"
        remove_field => "events"
    }
}

# Send the logs to Elasticsearch
output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        index=>"customer-%{+xxxx.ww}"
    }
}

You have two main points of failure that could lead to data loss, the communication between logstash and elasticsearch and the communication between your service and logstash.您有两个可能导致数据丢失的主要故障点,logstash 和 elasticsearch 之间的通信以及您的服务和 logstash 之间的通信。

communication between logstash and elasticsearch logstash 和 elasticsearch 之间的通信

When sending data to elasticsearch logstash per default uses a memory queue between the input block and the filter block of your pipeline, this queue exists to store the events in the cases where logstash cannot talk with elasticsearch.当向 elasticsearch 发送数据时,默认情况下,logstash 在input块和管道的filter块之间使用 memory 队列,该队列用于在 logstash 无法与 Z18897DCFCE6A4E7AE68ZA3BAEED443 对话的情况下存储事件。

This memory queue has a fixed size of 1000 events, so it is not much help if you have a lot of events per second.这个 memory 队列有1000 个事件的固定大小,因此如果每秒有很多事件,它并没有多大帮助。 You can change your pipeline to use the persisted queue , this queue will do the same thing as the in-memory queue, but it will write to a file in the logstash server and you can change the file size to store more events.您可以更改管道以使用持久队列,此队列将执行与内存队列相同的操作,但它会写入 logstash 服务器中的文件,您可以更改文件大小以存储更多事件。

If the persisted queue fills up and elasticsearch is still down, logstash will stop accepting new events, when the queue will fill depends entirely on the size of the queue, the size of events and the rate of events, but the persisted queue is one of the things you can do to avoid data loss between logstash and elasticsearch.如果持久化队列已满且 elasticsearch 仍处于关闭状态,logstash 将停止接受新事件,队列何时填满完全取决于队列的大小、事件的大小和事件的速率,但持久化队列是其中之一你可以做些什么来避免logstash和elasticsearch之间的数据丢失。

communication between your service and logstash您的服务和 logstash 之间的通信

If your service cannot communicate with logstash, then you will need to implement some logic on it to to avoid data loss.如果您的服务无法与 logstash 通信,那么您需要在其上实现一些逻辑以避免数据丢失。 How to do that is entirely in your hands.如何做到这一点完全掌握在您的手中。

You could replicate the persisted queue that logstash uses and write to a file the events that weren't sent to logstash and then replay those events when logstash is back.您可以复制 logstash 使用的持久队列并将未发送到 logstash 的事件写入文件,然后在 logstash 返回时重播这些事件。

This will add a lot of extra things that you will need to implement by yourself.这将添加许多您需要自己实现的额外内容。

alternatives备择方案

I would say that the best approach would be to just write your logs to a log file and use filebeat to send these logs to logstash or even directly to elasticsearch if you do not want to use any filters in logstash, filebeat can automatically retry sending the logs in the case of the output service is not reacheable and it also track what was already send or not.我想说最好的方法是将日志写入日志文件并使用filebeat将这些日志发送到logstash,甚至直接发送到elasticsearch,如果您不想在logstash中使用任何过滤器,filebeat可以自动重试发送在 output 服务的情况下,日志无法访问,它还跟踪已经发送或未发送的内容。

Since you are using dotnet, you could use log4net to log, it will take care of the logging part and also rotate your logs when it reach some specified size.由于您使用的是 dotnet,因此您可以使用 log4net 进行日志记录,它会处理日志记录部分,并在达到某个指定大小时轮换您的日志。

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

相关问题 将日志重定向到logstash实例而不是ElasticSearch - Redirect logs to logstash instance instead of ElasticSearch 损坏状态异常处理的可靠性 - Reliability of corrupted state exception handling 使用 nLog 丢失日志和不一致的存档从多个进程进行日志记录 - Logging from multiple processes with nLog missing logs and inconsistent archives 使用 Serilog 记录 Elasticsearch 而无需 Microsoft 记录 - Using Serilog to log Elasticsearch without Microsoft logging 使用Enterprise Library进行异常处理日志记录 - Exception Handling Logging using Enterprise Library 使用分号(“:”)在使用c#SDK的Google云日志记录中过滤日志 - Filtering logs using semicolon (“:”) in Google cloud logging with c# SDK 使用EL 5.0的日志应用程序块基于日期生成日志? - generate logs based on date using logging application block for EL 5.0? 我正在使用 log4net 进行日志记录,但它没有写入日志 - i am using log4net for logging purpose but it is not writing the logs 如何在不使用 Kibana 的情况下直接从 elasticsearch 读取日志 - How to read logs directly from elasticsearch without using Kibana 使用过滤器的程序包中的错误处理,但缺少参考 - Error handling in package using a filter but missing reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM