如何使流利的发送日志更快到Elasticsearch?

时间:2019-10-03 06:00:27

标签: elasticsearch fluentd

我已经设置了一些Docker容器,其中流畅的容器将JSON格式的日志发送到Elasticsearch容器(然后由Kibana读取)。由于我们的应用通过发送UDP消息进行日志记录,因此我已经设置流利的UDP接收日志。它可以工作,但是由于某些原因,会有很大的延迟,流利的日志只能在5分钟后到达ES。

我流利的配置是:

<system>
  log_level debug
</system>

<source>
  @type udp
  @label @udp_stream
  tag ma.udp_events
  <parse>
    @type json
    time_key $.log.@timestamp
    keep_time_key true
  </parse>
  port 20001
  bind 0.0.0.0
  message_length_limit 1MB
  source_hostname_key client_host
  source_address_key  client_addr
</source>

<label @udp_stream>
  <match **>
    @type copy
    <store>
      @type elasticsearch
      host elastic
      port 9200
      index_name logs.${app_environment}.${app_category}.${app_area}.${app_name}
      include_tag_key true
      reload_connections true
      reconnect_on_error false
      reload_on_failure false
      <buffer tag, app_environment, app_category, app_area, app_name>
        flush_at_shutdown true
        flush_mode immediate
        flush_thread_count 8
        flush_thread_interval 1
        flush_thread_burst_interval 1
        retry_forever true
        retry_type exponential_backoff
        retry_max_interval 30
        retry_wait 1
        chunk_limit_size 1K
        queue_limit_length 8
      </buffer>
    </store>
  </match>
</label>

除了这些设置之外,还有相同的TCP来源和另一个tail来源。我曾尝试删除它们,但问题似乎是另外一回事。我已经了解到有关缓冲区的5分钟延迟,但是我希望更详细的刷新策略会有所帮助。

日志只有1Kb到2Kb,我正在通过手动发送日志进行测试,因此那里没有任何开销,我每分钟只发送一些日志。 我想流利地尽快刷新其缓冲区。在对SO和一些博客进行了一些研究之后,我对缓冲区部分进行了调整,但无济于事。当然,我犯了一个错误,但是找不到。任何帮助将不胜感激。

编辑:

似乎我无法在不到5分钟的时间内从流利的日志中获取日志。但是,我尝试删除缓冲区部分,希望它更快。虽然我看到了有关冲洗和清除块的流利日志,但由于某种原因它们并未立即交付。我的测试配置与原始文章有所不同,因为我在JSON上设置了新密钥(我将其称为“ @es_index_name”),并且还删除了缓冲区部分。

我已经读过here

“ td-agent每5分钟连续上传一次日志。您可以通过发送SIGUSR1信号来强制td-agent将缓冲的日志刷新到云中。”

无论如何,我当前的测试配置是:

<label @udp_stream>
  <match **>
    @type copy
    <store>
      @type elasticsearch
      host elastic
      port 9200
      prefer_oj_serializer true
      target_index_key @es_index_name
      include_tag_key true
      reload_connections true
      reconnect_on_error false
      reload_on_failure false
      flush_interval 5s
    </store>
    <store>
      @type stdout
    </store>
  </match>
</label>

除了我在尝试简化时已删除的行之外,此处重要的行是:

target_index_key @es_index_name

编辑2:由于某种原因,在我将该容器部署为Kubernetes工作负载之后,日志开始按预期刷新。我不知道为什么会这样,但是最后,我希望这样运行。现在,我们的一个应用程序将UDP日志发送到我们的Fluentd,而Kibana只需几秒钟即可在其仪表板中显示它。

0 个答案:

没有答案
相关问题