nginx访问日志 logstash 配置文件实例2
admin
2023-03-19 05:41:28
0
日志格式:
log_format elk "$http_clientip | $http_x_forwarded_for | $time_local | $request | $status | $body_bytes_sent | "
                  " $request_body | $content_length | $http_referer | $http_user_agent | "
                  "$http_cookie | $remote_addr | $hostname | $upstream_addr | $upstream_response_time | $request_time";
日志实例:
36.110.211.42 | 10.10.130.101 | 23/Jun/2017:17:51:01 +0800 | GET /lvyou/dongjing/ HTTP/1.1 | 200 | 73181 | - | 0 | - | Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36 | JSESSION_O2O=0000F0jMLw1MnT6SFCvhcqW3oP9:19h7oe5dr; SessionID=10.10.130.101.1498210484146456; sCityCode=SZX; sCityName=%E6%B7%B1%E5%9C%B3; vac_ss_sid=4441002; vac_ss_uid=4441 | 10.10.130.100 | www1-n01 | 10.10.130.237:80 | 0.808 | 0.809
logstash实例:
input {  
        file {  
                type => "www1_access"  
                path => ["/usr/local/elk/elklog/nginxlog/log0/www1.log","/usr/local/elk/elklog/nginxlog/log1/www1.log"]  
        }
        file {
                type => "flight1_access"
                path => ["/usr/local/elk/elklog/nginxlog/log0/flight1.log","/usr/local/elk/elklog/nginxlog/log1/flight1.log"]
        }
        file {
                type => "m_access"
                path => ["/usr/local/elk/elklog/nginxlog/log0/m.log"]
        }
}  
filter {
ruby {
init => "@kname = ['http_clientip','http_x_forwarded_for','time_local','request','status','body_bytes_sent','request_body','content_length','http_referer','http_user_agent','http_cookie','remote_addr','hostname','upstream_addr','upstream_response_time','request_time']"
code => "new_event = LogStash::Event.new(Hash[@kname.zip(event.get('message').split(' | '))])
new_event.remove('@timestamp')
event.append(new_event)"
}
if [request] {
ruby {
init => "@kname = ['method','uri','verb']"
code => "new_event = LogStash::Event.new(Hash[@kname.zip(event.get('request').split(' '))])
new_event.remove('@timestamp')
event.append(new_event)
"
}
if [uri] {
ruby {
init => "@kname = ['url_path','url_args']"
code => "new_event = LogStash::Event.new(Hash[@kname.zip(event.get('uri').split('?'))])
new_event.remove('@timestamp')
event.append(new_event)
"
}
kv {
prefix => "url_"
source => "url_args"
field_split => "& "
remove_field => [ "url_args","uri","request" ]
}
}
}
mutate {
convert => ["body_bytes_sent" , "integer", "content_length", "integer", "upstream_response_time", "float","request_time", "float"]
}
        grok {
              match => [ 
"message", "%{IP:clientip} \| %{USER} \| %{HTTPDATE:timestamp}"
 ]
}
date {
match => [ "timestamp", "dd/MMM/YYYY:HH:mm:ss Z" ]
locale => "en"
}
        geoip 
{
        source => "clientip"
        }
mutate {    
                remove_field => "timestamp"      
                remove_field => "http_clientip"      
}
useragent {
    source => "http_user_agent"
    target => "useragent"
  } 
}
output {
        redis {  
                host => "10.10.45.200"  
                data_type => "list"  
                key => "elk_frontend_access:redis"  
                port=>"5379"  
        }  
}
注意:分隔符为“空格+table+空格”

相关内容

热门资讯

重达11000克拉!缅甸发现“... 【环球网报道】美国哥伦比亚广播公司、英国天空新闻网等媒体援引缅甸官方媒体8日消息报道称,缅甸发现一块...
玻璃缝隙漏水怎么处理 1、检查窗户玻璃附近墙体的防水层,重新做防水层。2、查找原先的密封物,检查门窗与墙体的密封度,如果密...
热水器侧面的缝隙漏水可以修好吗 问题:热水器侧面的缝隙漏水可以修好吗回答:如果热水器侧面出现缝隙漏水的情况基本上都是可以修好的。首先...
洗面盆和台面缝隙漏水怎么办 洗菜盆漏水的修补方法1、如果是洗菜盆和台面衔接松动:如果是因为洗菜盆安装时没安装好,与台面缝隙过大,...
空调缝隙漏水怎么办 空调在一定的年限服务后,会出现一些问题,例如漏水。空调漏水是比较常见的问题,但有许多原因可能导致空调...
不用电的情况下空气开关跳闸是怎... 家用空气断路器跳闸的原因很好判断,如果漏电断路器脱扣后复位按钮突出,则可以断定电路有漏电,需要注意的...
宏福苑母亲节晚宴,女儿希望火中... 凤凰卫视记者在香港报道:有慈善机构为大埔宏福苑居民举办母亲节晚宴,参加的居民表示,经历大火后更深刻体...
顺风车乘客拒付高速费,00后车... 近日,江苏苏州一00后车主接了一单顺风车,车主称下单时乘客已经点击确定承担全部高速费,可下高速时乘客...
圣罗兰“拉黑”杭州一条街道?记... 澎湃新闻记者 王选辉 实习生 俞涵因“恶意退货太多整条街道被商家拉黑”一事持续发酵,近日有网友反映,...
局地可达35℃以上!今年首轮高... 热起来了!今天(10日)起至13日,北方迎来今年首场大范围高温天气,大部地区气温将超30℃,刷新今年...