1. 程式人生 > 實用技巧 >獲取的日誌引數分離

獲取的日誌引數分離

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"
  }
}