首页 > 技术文章 > 获取的日志参数分离

Applogize 2020-08-22 15:15 原文

1.方法一:

1)修改tomcat日志收集配置

[root@web01 ~]# vim /etc/logstash/conf.d/tomcat_json_es.conf

input {
  file {
    path => "/usr/local/tomcat/logs/tomcat_access_json.*.log"
    start_position => "beginning"
  }
}

#把收集到的数据进行处理
filter {
  json {
    source => "message"
  }
}

output {
  elasticsearch {
    hosts => ["10.0.0.51:9200"]
    index => "tomcat_json_%{+YYYY-MM-dd}.log"
  }
}

2)去掉多余数据

#message数据已经拆分,数据还在,去掉message数据
filter {
  json {
    source => "message"
    remove_field => ["message"]
  }
}

2.方法二:

1)修改收集Nginx日志的配置

#nginx不需要配置修改获取日志,只需要收集同时修改格式即可
[root@web01 ~]# vim /etc/logstash/conf.d/nginx_json.conf 
input {
  file {
    path => "/var/log/nginx/access.log"
    start_position => "beginning"
    codec => "json"
  }
}
output {
  elasticsearch {
    hosts => ["10.0.0.51:9200"]
    index => "nginx_json_%{+YYYY-MM-dd}.log"
  }
}

推荐阅读