日志格式:
log_format usgateway '$http_clientip\t$http_ServiceName\t$http_uid\t$http_sid\t[$time_local]'
'\t$request\t$status\t$body_bytes_sent\t$connection_requests'
'\t$remote_addr\t$http_referer\t$http_user_agent'
'\t$request_body\t$request_time\t$msec';
日志实例:
10.10.45.152---[23/Jun/2017:17:37:42 +0800]POST /sg HTTP/1.14055765910.10.130.100-Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0){\x22mbrNetName\x22:\x22\xE9\x87\x91\xE6\x98\x9F\x22,\x22nameCn\x22:\x22\xE8\x8A\x92\xE6\x9E\x9C\xE7\xBD\x91\x22,\x22gender\x22:\x2211\x22,\x22birthday\x22:\x222010-10-01\x22,\x22mbrId\x22:\x2235954629\x22,\x22emailAddr\x22:\x22334740263@qq.com\x22,\x22mobileNo\x22:\x2215902074059\x22}0.0011498210662.427
logstash配置文件:
input {
file {
type => "uSG_gateway_access"
path => ["/usr/local/elk/elklog/nginxlog/log0/uSG_gateway_elk.log"]
}
}
filter {
ruby {
init => "@kname = ['http_clientip','http_ServiceName','http_uid','http_sid','time_local','request','status','body_bytes_sent','connection_requests','remote_addr','http_referer','http_user_agent','request_body','request_time','msec']"
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)
"
}
}
mutate {
convert => ["body_bytes_sent" , "integer", "content_length", "integer", "upstream_response_time", "float","request_time", "float"]
}
grok {
match => [ "message", "%{IPORHOST:clientip}%{USER}%{USER}%{USER}\[%{HTTPDATE:timestamp}\]"]
}
date {
match => [ "timestamp", "dd/MMM/YYYY:HH:mm:ss Z" ]
locale => "en"
}
geoip {
source => "clientip"
}
useragent {
source => "http_user_agent"
target => "useragent"
}
}
output {
elasticsearch {
hosts => "10.10.45.200:8201"
index => "logstash-gateway-frontend-%{+YYYY.MM.dd}"
}
}
注意:日志分隔符为table键。
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
创新互联公司长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为安化企业提供专业的
成都网站设计、网站制作,
安化网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。
网页标题:nginx访问日志logstash配置文件实例1-创新互联
文章地址:
http://cqcxhl.com/article/dcohis.html