溫馨提示×

如何自定義Debian上Filebeat的輸出格式

小樊
37
2025-07-29 04:07:13
欄目: 智能運維

在Debian上自定義Filebeat的輸出格式,您需要修改Filebeat的配置文件filebeat.yml

  1. 打開Filebeat配置文件:
sudo nano /etc/filebeat/filebeat.yml
  1. filebeat.yml文件中找到output.elasticsearch部分。如果您使用的是其他輸出模塊(如Logstash或Elasticsearch),請相應地修改該部分。

  2. output.elasticsearch部分下,您可以自定義輸出格式。例如,如果您想將日志發送到Elasticsearch并使用自定義字段,可以添加fields參數:

output.elasticsearch:
  hosts: ["localhost:9200"]
  index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
  pipeline: "my_custom_pipeline"
  fields:
    custom_field1: "value1"
    custom_field2: "value2"

在這個例子中,我們添加了兩個自定義字段custom_field1custom_field2,并分別設置了它們的值。

  1. 如果您想使用自定義的JSON模板作為輸出格式,可以使用template.nametemplate.content參數:
output.elasticsearch:
  hosts: ["localhost:9200"]
  index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
  template.name: "my_custom_template"
  template.content: >
    {
      "index_patterns": ["filebeat-*"],
      "template": {
        "mappings": {
          "_source": {
            "enabled": true
          },
          "properties": {
            "custom_field1": {
              "type": "keyword"
            },
            "custom_field2": {
              "type": "keyword"
            }
          }
        }
      }
    }

在這個例子中,我們定義了一個名為my_custom_template的模板,并為其指定了一個包含自定義字段的JSON映射。

  1. 保存并關閉filebeat.yml文件。

  2. 重新啟動Filebeat以應用更改:

sudo systemctl restart filebeat

現在,Filebeat將使用您自定義的輸出格式發送日志到Elasticsearch。請注意,根據您的需求和使用的輸出模塊,可能需要調整這些步驟。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女