最近又重新接触了一下elastisearch、logstash、kibana,蛮好用的一个日志框架。
同时好久没有更新网站内容、也没怎么关注,虽然有cnzz(umeng)的日志统计功能,但是毕竟是很小一段时间的。要是能够把日志都导出来,就可以用ELK来分析一下自己网站一年来文章的访问情况。
嗯,前阵子买了阿里云的一个VPN服务器,正好可以利用利用。把访问的日志情况通过http发送给logstash,然后存储下来,等过一段时间我们再回来分析分析这些日志。^^
~/logstash-6.1.2/bin/logstash -e '
input {
http {
port => 20000
response_headers => {
"Access-Control-Allow-Origin" => "*"
"Content-Type" => "application/json"
"Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type, Accept"
}
}
}
filter {
if [message] =~ /^\s*$/ {
drop { }
}
json {
source => "message"
}
json {
source => "location"
target => "location"
}
mutate {
remove_field => [ "headers" ]
}
}
output {
file {
path => "winse-accesslog-%{+YYYY-MM-dd}.log"
codec => json_lines
}
}
'
$.ajax({
type: "POST",
url: "http://SERVER:PORT",
data: JSON.stringify({
title: document.title,
location: JSON.stringify(location),
referrer: document.referrer,
userAgent: navigator.userAgent
}),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
–END