Logstash 收集 IIS 日志

日志样例

查看 IIS 日志配置,选择格式为 W3C(默认字段设置)保存生效。

  1. 2016-02-25 01:27:04 112.74.74.124 GET /goods/list/0/1.html - 80 - 66.249.65.102 Mozilla/5.0+(compatible;+Googlebot/2.1;++http://www.google.com/bot.html) 404 0 2 703

采集配置

  1. input {
  2. file {
  3. type => "iis_log_1"
  4. path => ["C:/inetpub/logs/LogFiles/W3SVC1/*.log"]
  5. start_position => "beginning"
  6. }
  7. }
  8. filter {
  9. if [type] == "iis_log_1" {
  10. #ignore log comments
  11. if [message] =~ "^#" {
  12. drop {}
  13. }
  14. grok {
  15. # check that fields match your IIS log settings
  16. match => ["message", "%{TIMESTAMP_ISO8601:log_timestamp} %{IPORHOST:site} %{WORD:method} %{URIPATH:page} %{NOTSPACE:querystring} %{NUMBER:port} %{NOTSPACE:username} %{IPORHOST:clienthost} %{NOTSPACE:useragent} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:time_taken}"]
  17. }
  18. date {
  19. match => [ "log_timestamp", "YYYY-MM-dd HH:mm:ss" ]
  20. timezone => "Etc/UTC"
  21. }
  22. useragent {
  23. source=> "useragent"
  24. prefix=> "browser"
  25. }
  26. mutate {
  27. remove_field => [ "log_timestamp"]
  28. }
  29. }
  30. }
  31. output {
  32. if [type] == "iis_log_1" {
  33. logservice {
  34. codec => "json"
  35. endpoint => "***"
  36. project => "***"
  37. logstore => "***"
  38. topic => ""
  39. source => ""
  40. access_key_id => "***"
  41. access_key_secret => "***"
  42. max_send_retry => 10
  43. }
  44. }
  45. }

注意:

  • 配置文件格式必须以 UTF-8 无 BOM 格式编码,可以通过notepad++修改文件编码格式。
  • path 填写文件路径时请使用UNIX模式的分隔符,如:C:/test/multiline/*.log,否则无法支持模糊匹配。
  • type 字段需要统一修改并在该文件内保持一致,如果单台机器存在多个 Logstash 配置文件,需要保证各配置 type 字段唯一,否则会导致数据处理的错乱。

相关插件:filegrok

重启 Logstash 生效

创建配置文件到 conf 目录,参考 配置Logstash 重启 Logstash 生效。

 
posted @ 2018-01-08 17:31  a-du  阅读(596)  评论(0编辑  收藏  举报