3

我使用这个堆栈:

  • 在每台前端服务器上
    • 导轨
    • 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" }
    }
  ]
}

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

4

2 回答 2

1

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

filter {
  json {
    source => 'message'
    remove_field => [ 'message' ]
  }
}
于 2014-09-29T14:41:38.587 回答
0

最后一种方法是停止并启动logstash,否则(重新启动)配置似乎没有更新。

所以而不是:

sudo service logstash restart

我做了:

sudo service logstash stop

等待〜1分钟,然后

sudo service logstash start

不太明白原因(初始化脚本会这样做,但不会等待 1 分钟),但它对我有用。

于 2014-09-30T16:37:17.320 回答