Beats — Filebeat 自定义标签+多日志采集

  • Post author:
  • Post category:其他






一、自定义采集数据标签



自定义标签

tags: [“nginx-access”] 自定义标签为 nginx-access

tags: [“error-access”] 自定义标签为 error-access



自定义字段
fields:
   from: nginx-access
   itcase: "192.168.168.13"


终端端显示信息

在这里插入图片描述



完整的一个 自定义标签、自定义字段的 filebeat采集日志
filebeat.inputs:
  - type: log
    enabled: true
    paths:
       - /usr/local/nginx/logs/access_json.log
    tags: ["nginx-access"]			#指定自定义标签
    fields:							#指定自定义字段
       from: nginx-access			#字段1	
       itcase: "192.168.168.13"		#字段2
# -------------———----------------- #
setup.template.settings:
  index.number_of_shards: 3
# --------------------------------- #
output.logstash:
    hosts: ["192.168.168.12:5044"]
    pretty: true
    enable: true


logstash 引用标签,对索引进行输出
input {
  beats {
    host => "0.0.0.0"
    port => 5044
 }
}

//filter 过滤先不管

output {
   if "nginx-access" in [tags] {		  // 匹配定义的第一个标签
     stdout { codec => rubydebug }		  // 在终端输出,查看结果
  }
   if "nginx-error" in [tags] {			  // 匹配定义的第二个标签
      stdout { codec => rubydebug }       
  }
}

// ----------  以下是往 ElasticSearch 中存储 ------------
output {
   if "nginx-access" in [tags] {
     elasticsearch {
        hosts => ["192.168.168.11"]
        index => "logstash-nginx-access-%{+YYYY.MM.dd}"
     } 
   }
   if "nginx-error" in [tags] {
     elasticsearch {
        hosts => ["192.168.168.11"]
        index => "logstash-nginx-error-%{+YYYY.MM.dd}"
     }
   }
}

在这里插入图片描述



二、Filebeat 采集多个日志配置

filebeat.inputs:
  - type: log
    enabled: true
    paths:
       - /usr/local/nginx/logs/access_json.log
    tags: ["nginx-access"]
    fields:
       from: nginx-access
       itcase: "192.168.168.13"
    #fields_under_root: true
# ------- 第二个日志 -----------#
  - type: log
    enabled: true
    paths:
      - /usr/local/nginx/logs/error_json.log
    tags: ["nginx-error"]
    fields:
      from: nginx-error
      itcase: "192.168.168.13"



版权声明:本文为shm19990131原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。