ubuntu

ubuntu filebeat如何定制报告模板

小樊
40
2025-11-09 09:29:08
栏目: 智能运维

Ubuntu下Filebeat定制报告模板(索引模板)的步骤

1. 准备自定义模板文件(可选但推荐)

若需完全自定义模板的字段映射、设置等,可创建JSON格式的模板文件(如/etc/filebeat/custom-template.json),内容需包含索引模式、设置(如分片数)、映射(如字段类型)。示例如下:

{
  "index_patterns": ["custom-report-*"],  // 索引匹配模式
  "settings": {
    "number_of_shards": 3,                // 主分片数(根据数据量调整)
    "number_of_replicas": 1               // 副本数(高可用需求)
  },
  "mappings": {
    "_source": {"enabled": true},         // 是否存储原始数据
    "properties": {
      "@timestamp": {"type": "date"},     // 时间戳字段类型
      "message": {"type": "text"},        // 日志消息字段类型
      "log_level": {"type": "keyword"},   // 日志级别(精确匹配)
      "source_ip": {"type": "ip"}         // IP地址(支持聚合)
    }
  }
}

2. 修改Filebeat配置文件

编辑/etc/filebeat/filebeat.yml,通过以下参数关联自定义模板或直接定义模板内容:

3. 关联Kibana Dashboard(可选,用于可视化)

若需在Kibana中可视化报告数据,需配置Dashboard索引并导入模板:

setup.dashboards.enabled: true               # 启用Dashboard配置
setup.dashboards.index: "custom-report-*"    # Dashboard索引匹配规则(需与模板pattern一致)
setup.kibana:                                # Kibana连接配置
  host: "localhost:5601"                     # Kibana地址
  username: "elastic"                        # 认证用户(若有)
  password: "your_password"                  # 认证密码(若有)

4. 应用配置并重启Filebeat

保存filebeat.yml后,重启Filebeat服务使配置生效:

sudo systemctl restart filebeat

5. 验证模板是否生效

注意事项

0
看了该问题的人还看了