【问题标题】:How to continuously delete old fluentd logs from elasticsearch?如何从elasticsearch中连续删除旧的流利日志?
【发布时间】:2017-12-05 09:42:32
【问题描述】:

Fluentd 日志收集器写入 Elasticsearch,最终填满磁盘。例如,如何将它们限制为一个月?

Fluentd 配置的一部分(使用 Kubernetes):

<match kubernetes.**>
  @type elasticsearch_dynamic
  host elasticsearch.default.svc.cluster.local
  port 9200
  include_tag_key true
  logstash_format true
  logstash_prefix kubernetes-${record['kubernetes']['pod_name']}
</match>

Elasticsearch 的“Curator”,可以删除“索引”,但我不知道 Fluentd 创建了哪些索引,何时停止使用它们,以及当索引中仍有有用的新日志时删除索引是什么意思?

【问题讨论】:

  • 见下方答案
  • @untergeek,我无法将答案应用于手头的任务。
  • 给我展示一个创建的索引的例子。您可以使用 Elasticsearch 的 _cat API 来显示: curl localhost:9200/_cat/indices(将 localhost 替换为 elasticsearch.default.svc.cluster.local,或者您使用的任何 dns 或 ip)
  • 像这样:kubernetes-elasticsearch-2173889150-fj2gh-2017.11.30。我已经实现了一个删除旧任务的 cron 任务。它大致完成了所需的工作。
  • 我会用一个例子来编辑答案以适应这种模式

标签: elasticsearch logging fluentd elasticsearch-curator


【解决方案1】:

Curator 将为您删除索引,无论是 Logstash、fluentd 还是其他一些应用程序制作的索引。此示例将使用您在上述 cmets 中提供的索引模式。

---
actions:
  1:
    action: delete_indices
    description: >-
      Delete indices older than 30 days (based on index name), for kubernetes-elasticsearch-
      prefixed indices. Ignore the error if the filter does not result in an
      actionable list of indices (ignore_empty_list) and exit cleanly.
    options:
      ignore_empty_list: true
      disable_action: true
    filters:
      - filtertype: pattern
        kind: prefix
        value: kubernetes-elasticsearch-
      - filtertype: age
        source: name
        direction: older
        timestring: '%Y.%m.%d'
        unit: days
        unit_count: 30

【讨论】:

    猜你喜欢
    • 2018-04-15
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 2022-10-11
    • 2013-05-25
    相关资源
    最近更新 更多