我使用这个堆栈:
- 在每台前端服务器上
- 导轨
- logstasher gem(格式rails log in json)
- logstash-forwarder(只是将日志转发到中央服务器上的 logstash)
- 在日志服务器上:
- logstash(集中和索引日志)
- 要显示的 kibana
Kibana 可以很好地与 JSON 格式配合使用。但是“消息”数据是由字符串提供的,而不是作为 json 提供的(参见提供的片段)。有没有办法解决这个问题?例如,访问状态有点棘手
这是一个消息示例
{
_index: logstash-2014.09.18
_type: rails
_id: RHJgU2L_SoOKS79pBzU_mA
_version: 1
_score: null
_source: {
message: "{"@source":"unknown","@tags":["request"],"@fields":{"method":"GET","path":"/foo/bar","format":"html","controller":"items","action":"show","status":200,"duration":377.52,"view":355.67,"db":7.47,"ip":"123.456.789.123","route":"items#show","request_id":"021ad750600ab99758062de60102da8f"},"@timestamp":"2014-09-18T09:07:31.822782+00:00"}"
@version: 1
@timestamp: 2014-09-18T09:08:21.990Z
type: rails
file: /home/user/path/logstash_production.log
host: webserver.example.com
offset: 23200721
format: json_event
}
sort: [
rails
]
}
谢谢你的帮助 ;)。
编辑1:添加logstash配置文件:
/etc/logstash/conf.d/01-lumberjack-input.conf
input {
lumberjack {
port => 5000
type => "logs"
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
codec => "json"
}
}
/etc/logstash/conf.d/10-syslog.conf
filter {
if [type] == "syslog" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
syslog_pri { }
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
}
/etc/logstash/conf.d/30-lumberjack-output.conf
output {
elasticsearch { host => localhost }
# stdout { codec => rubydebug }
}
如果有用,logstash-forwarder 配置:
/etc/logstash-forwarder
在 Web 服务器上
{
"network": {
"servers": [ "123.465.789.123:5000" ],
"timeout": 45,
"ssl ca": "/etc/pki/tls/certs/logstash-forwarder.crt"
},
"files": [
{
"paths": [
"/var/log/messages",
"/var/log/secure"
],
"fields": { "type": "syslog" }
},
{
"paths": [
"/home/xnxx/gportal/shared/log/logstash_production.log"
],
"fields": { "type": "rails", "format": "json_event" }
}
]
}