gpt4 book ai didi

ruby-on-rails-3 - Logstasher+Kibana : message double quoted and hard to parse

转载 作者:行者123 更新时间:2023-12-02 03:32:14 24 4
gpt4 key购买 nike

我使用这个堆栈:

  • 在每台前端服务器上
    • 轨道
    • logstasher gem(格式化 json 中的 rails 日志)
    • 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 在网络服务器上

{
"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" }
}
]
}

我的配置文件主要来源于这个教程:https://www.digitalocean.com/community/tutorials/how-to-use-logstash-and-kibana-to-centralize-and-visualize-logs-on-ubuntu-14-04

最佳答案

我个人从未使用过 lumberjack 输入,但看起来它应该支持 codec=>json,所以我不确定为什么不支持。您可以尝试将其放入(在 /etc/logstash/conf.d/01-lumberjack-input.conf 中):

filter {
json {
source => 'message'
remove_field => [ 'message' ]
}
}

关于ruby-on-rails-3 - Logstasher+Kibana : message double quoted and hard to parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25910537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com