溫馨提示×

CentOS中FileBeat如何自定義輸出格式

小樊
50
2025-08-16 16:45:25
欄目: 智能運維

在CentOS中,要自定義FileBeat的輸出格式,你需要修改FileBeat的配置文件filebeat.yml。以下是一個示例,展示了如何自定義輸出格式:

  1. 打開FileBeat配置文件:
sudo vi /etc/filebeat/filebeat.yml
  1. filebeat.yml文件中,找到output.elasticsearch部分。如果你還沒有配置輸出到Elasticsearch,請添加以下內容:
output.elasticsearch:
  hosts: ["localhost:9200"]
  index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
  1. 要自定義輸出格式,你需要使用processors功能。在filebeat.yml文件中,找到或添加processors部分。以下是一個示例,展示了如何添加一個名為custom_format的自定義處理器:
processors:
- add_fields:
    fields:
      custom_field: "custom_value"
  1. 然后,你需要創建一個自定義的模板文件,用于定義輸出格式。在/etc/filebeat/templates.d/目錄下創建一個名為custom_output_format.yml的新文件:
sudo vi /etc/filebeat/templates.d/custom_output_format.yml
  1. custom_output_format.yml文件中,添加以下內容,用于定義自定義輸出格式:
template.name: "custom_output_format"
template.pattern: "custom_output_format-*"
template.enabled: true
template.source: >
  {
    "template": {
      "index_patterns": ["{{ .IndexPattern }}"],
      "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
      },
      "mappings": {
        "_doc": {
          "properties": {
            "custom_field": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
  1. 保存并關閉文件。

  2. 重新啟動FileBeat服務以應用更改:

sudo systemctl restart filebeat

現在,FileBeat將使用自定義的輸出格式,并將數據發送到Elasticsearch。你可以根據需要修改custom_output_format.yml文件中的設置,以滿足你的需求。

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