input { file { path => ["/root/nerv-app/nerv-rds/log/*.log"] } }
filter { grok{ // 自定义grok,如果日志中有时间,将匹配结果存入log_timestamp,其余字段,存入[log_content][*]下 match => { "message" => "time=\"%{NOTSPACE:log_timestamp}\" level=%{NOTSPACE:[log_content][level]} msg=\"%{GREEDYDATA:[log_content][msg]}\" file=\"%{NOTSPACE:[log_content][file]}\""} } mutate { remove_field => ["host", "path", "tags", "@version"] // 删除无用字段,由于需要删除tags,grok必须放在该mutate上面,因为如果没有匹配成功,会生成_grokparsefailure的tag,其他会生成tag的,也一同放在该mutate上面 rename => { "message" => "[log_content][message]" } // 如果不需要保留原始采集日志,请删除此行 add_field => {"region" => "cn_hb_01"} // 地域 add_field => {"zone" => "cn_hb_01_xy"} // 可用区 add_field => {"service_type" => "nerv-rds"} // 服务类型 add_field => {"service" => "nerv-rds"} // 服务名称 add_field => {"cluster" => "rds-manager"} // 集群名称,对应到模版中${nerv_node_name} add_field => {"ip" => "100.73.45.4"} // 采集源主机地址 add_field => {"hostname" => "nerv"} // 采集源主机名称 add_field => {"project_id" => 10} // 采集服务所属的项目ID add_field => {"tenant" => "gongxtao"} // 采集服务所属的租户名称 } date { match => [ "log_timestamp" , "ISO8601"] // 格式化日期字段,如果日志中的日期,没有时区信息,需要设置timezone target => "log_timestamp" } if ![log_timestamp] { // 如果没有日期字段,使用采样时间,作为日志时间 mutate { copy => { "@timestamp" => "log_timestamp" } } } ruby { // 用于生成索引的日期后缀 code => "event.set('index_day', event.get('log_timestamp').time.localtime.strftime('%Y-%m-%d'))" } }
output { elasticsearch { hosts => ["100.73.18.12:9200", "100.73.18.15:9200"] // 集群ES节点host index => "%{tenant}-%{project_id}-%{service}-%{cluster}-%{index_day}" // 分隔符可自定义 } } |
4. Logstash 系统服务设备日志格式 API 对接
最新推荐文章于 2023-11-30 23:54:57 发布