簡體   English   中英

使用filebeat,logstash和elasticsearch將json格式日志發送到kibana?

[英]Sending json format log to kibana using filebeat, logstash and elasticsearch?

我有這樣的日志:

{"logId":"57aaf6c8d32fb","clientIp":"127.0.0.1","time":"03:11:29 pm","uniqueSubId":"57aaf6c98963b","channelName":"JSPC","apiVersion":"v1","modulName":null,"actionName":"apiRequest","typeOfError":"","statusCode":"","message":"In Auth","exception":"In Auth","logType":"Info"}

{"logId":"57aaf6c8d32fb","clientIp":"127.0.0.1","time":"03:11:29 pm","uniqueSubId":"57aaf6c987206","channelName":"JSPC","apiVersion":"v2","modulName":null,"actionName":"performV2","typeOfError":"","statusCode":"","message":"in inbox api v2 5","exception":"in inbox api v2 5","logType":"Info"}

我想把他們推到kibana 我使用filebeat將數據發送到logstash,使用以下配置:

filebeat.yml

 ### Logstash as output
logstash:
# The Logstash hosts
hosts: ["localhost:5044"]

# Number of workers per Logstash host.
#worker: 1

現在使用以下配置,我想更改編解碼器類型:

input {

     beats {
     port => 5000
     tags => "beats"
     codec => "json_lines"
     #ssl  => true
     #ssl_certificate => "/opt/filebeats/logs.example.com.crt"
     #ssl_key => "/opt/filebeats/logs.example.com.key"
     }


     syslog {
        type => "syslog"
        port => "5514"

    }

}

但是,我仍然以字符串格式獲取日志:

“message”:“{\\”logId \\“:\\”57aaf6c96224b \\“,\\”clientIp \\“:\\”127.0.0.1 \\“,\\”time \\“:\\”03:11:29 pm \\“,\\ “CHANNELNAME \\”:\\ “JSPC \\”,\\ “apiVersion \\”:空,\\ “modulName \\”:空,\\ “actionName \\”:\\ “404 \\” \\ “typeOfError \\”:\\ “例外\\” ,“statusCode \\”:0,\\“message \\”:\\“404頁面遇到http:\\ / \\ / localjs.com \\ / uploads \\ / NonScreenedImages \\ / profilePic120 \\ / 16 \\ / 29 \\ /15997002iicee52ad041fed55e952d4e4e163d5972ii4c41f8845105429abbd11cc184d0e330.jpeg \\ “\\ ”日志類型\\“:\\ ”錯誤\\“}”,

請幫我解決這個問題。

要解析從Filebeat發送的Logstash中的JSON日志行,您需要使用json過濾器而不是編解碼器。 這是因為Filebeat將其數據作為JSON發送,並且日志行的內容包含在message字段中。

Logstash配置:

input {
  beats {
    port => 5044
  }   
}   

filter {
  if [tags][json] {
    json {
      source => "message"
    }   
  }   
}   

output {
  stdout { codec => rubydebug { metadata => true } } 
}

Filebeat配置:

filebeat:
  prospectors:
    - paths:
        - my_json.log
      fields_under_root: true
      fields:
        tags: ['json']
output:
  logstash:
    hosts: ['localhost:5044']

在Filebeat配置中,我為事件添加了一個“json”標記,以便可以有條件地將json過濾器應用於數據。

Filebeat 5.0能夠在不使用Logstash的情況下解析JSON,但它目前仍然是alpha版本。 這篇名為“ 使用Filebeat進行結構化日志記錄”的博客文章演示了如何使用Filebeat 5.0解析JSON。

從FileBeat 5.x您可以在不使用Logstash的情況下執行此操作。

Filebeat配置:

filebeat.prospectors:
- input_type: log
  paths: ["YOUR_LOG_FILE_DIR/*"]
  json.message_key: logId
  json.keys_under_root: true

output.elasticsearch:
  hosts: ["<HOSTNAME:PORT>"]
  template.name: filebeat
  template.path: filebeat.template.json

Filebeat比Logstash更輕量級。 此外,即使你需要插入elasticsearch版本2.x你可以使用FileBeat 5.x的這個功能真實的例子可以在這里找到

我已經在互聯網上搜索了你遇到的完全相同的問題,並嘗試了各種建議,包括上述建議。 然而,沒有人幫助我,所以我采用老式的方式。 我繼續關於filebeat配置的elasticsearch文檔

以及所需的一切(在logstash中不需要過濾器配置)

Filebeat配置:

filebeat.prospectors:
- input_type: log
  document_type: #whatever your type is, this is optional
  json.keys_under_root: true
  paths:
    - #your path goes here

keys_under_root

將嵌套的json鍵復制到輸出文檔的頂層。

我的filebeat版本是5.2.2。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM