日志样例
查看 IIS 日志配置,选择格式为 W3C(默认字段设置)保存生效。
- [backcolor=transparent]2016[backcolor=transparent]-[backcolor=transparent]02[backcolor=transparent]-[backcolor=transparent]25[backcolor=transparent] [backcolor=transparent]01[backcolor=transparent]:[backcolor=transparent]27[backcolor=transparent]:[backcolor=transparent]04[backcolor=transparent] [backcolor=transparent]112.74[backcolor=transparent].[backcolor=transparent]74.124[backcolor=transparent] GET [backcolor=transparent]/[backcolor=transparent]goods[backcolor=transparent]/[backcolor=transparent]list[backcolor=transparent]/[backcolor=transparent]0[backcolor=transparent]/[backcolor=transparent]1.html[backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]80[backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]66.249[backcolor=transparent].[backcolor=transparent]65.102[backcolor=transparent] [backcolor=transparent]Mozilla[backcolor=transparent]/[backcolor=transparent]5.0[backcolor=transparent]+([backcolor=transparent]compatible[backcolor=transparent];+[backcolor=transparent]Googlebot[backcolor=transparent]/[backcolor=transparent]2.1[backcolor=transparent];++[backcolor=transparent]http[backcolor=transparent]:[backcolor=transparent]//www.google.com/bot.html) 404 0 2 703
采集配置
- [backcolor=transparent]input [backcolor=transparent]{
- [backcolor=transparent] file [backcolor=transparent]{
- [backcolor=transparent] type [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"iis_log_1"
- [backcolor=transparent] path [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]"C:/inetpub/logs/LogFiles/W3SVC1/*.log"[backcolor=transparent]]
- [backcolor=transparent] start_position [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"beginning"
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
- [backcolor=transparent]filter [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]type[backcolor=transparent]][backcolor=transparent] [backcolor=transparent]==[backcolor=transparent] [backcolor=transparent]"iis_log_1"[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]#ignore log comments
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]message[backcolor=transparent]][backcolor=transparent] [backcolor=transparent]=~[backcolor=transparent] [backcolor=transparent]"^#"[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] drop [backcolor=transparent]{}
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] grok [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]# check that fields match your IIS log settings
- [backcolor=transparent] match [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]"message"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"%{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}"[backcolor=transparent]]
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] date [backcolor=transparent]{
- [backcolor=transparent] match [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent][[backcolor=transparent] [backcolor=transparent]"log_timestamp"[backcolor=transparent],[backcolor=transparent] [backcolor=transparent]"YYYY-MM-dd HH:mm:ss"[backcolor=transparent] [backcolor=transparent]]
- [backcolor=transparent] timezone [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"Etc/UTC"
- [backcolor=transparent] [backcolor=transparent]}[backcolor=transparent]
- [backcolor=transparent] useragent [backcolor=transparent]{
- [backcolor=transparent] source[backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"useragent"
- [backcolor=transparent] prefix[backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"browser"
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] mutate [backcolor=transparent]{
- [backcolor=transparent] remove_field [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent][[backcolor=transparent] [backcolor=transparent]"log_timestamp"[backcolor=transparent]]
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
- [backcolor=transparent]output [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]if[backcolor=transparent] [backcolor=transparent][[backcolor=transparent]type[backcolor=transparent]][backcolor=transparent] [backcolor=transparent]==[backcolor=transparent] [backcolor=transparent]"iis_log_1"[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] logservice [backcolor=transparent]{
- [backcolor=transparent] codec [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"json"
- [backcolor=transparent] endpoint [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"***"
- [backcolor=transparent] project [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"***"
- [backcolor=transparent] logstore [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"***"
- [backcolor=transparent] topic [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]""
- [backcolor=transparent] source [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]""
- [backcolor=transparent] access_key_id [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"***"
- [backcolor=transparent] access_key_secret [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]"***"
- [backcolor=transparent] max_send_retry [backcolor=transparent]=>[backcolor=transparent] [backcolor=transparent]10
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}
注意:
- 配置文件格式必须以 UTF-8 无 BOM 格式编码,可以通过notepad++修改文件编码格式。
- path 填写文件路径时请使用UNIX模式的分隔符,如:C:/test/multiline/*.log,否则无法支持模糊匹配。
- type 字段需要统一修改并在该文件内保持一致,如果单台机器存在多个 Logstash 配置文件,需要保证各配置 type 字段唯一,否则会导致数据处理的错乱。
相关插件:
file、
grok。
重启 Logstash 生效
创建配置文件到 conf 目录,参考
配置Logstash 重启 Logstash 生效。