logstash + influxdb

1,安裝logstash output influxdb的插件

官網插件下載地址:
https://www.elastic.co/guide/en/logstash/current/output-plugins.html
官網influxdb output配置介紹:
[https://www.elastic.co/guide/en/logstash/current/plugins-outputs-influxdb.html#plugins-outputs-influxdb-data_points]
如果通過官網下載插件,請注意把下載文件放到 logstash/lib/logstash/outputs目錄下

推薦使用快速安裝插件

#查看目前是否有influxdb的插件
bin/logstash-plugin list --group output

#如果沒有的話,運行此命令安裝
bin/logstash-plugin install logstash-output-influxdb

在這裏插入圖片描述
如果安裝執行不成功,建議使用上文中官網下載的方法,不建議修改源

2,logstash配置 + influx輸出
input{
file {
path => ["/zork/aaa.log"]
type => “testjson”
start_position => “beginning”
codec => “json”
}
}
#讀取本地日誌文件,指定json輸出
filter{
ruby {
code => "
cwd = event.get(’[system_info][process][cwd]’) #獲取json串中cwd的值
event.set(‘system_info.process.cwd’,cwd) #添加時間
"
remove_field => ["@version",“message”,“system_info”] #不必要事件全部移除
}
}
#過濾,截取cwd

output{
stdout { codec => rubydebug}
influxdb {
db => “logstash_test” #庫名
host => “192.168.2.175” #influx主機ip
port => “8086” #默認端口,可以不寫
measurement => “mytable” #指定數據要進入的表
data_points => {
#“timestamp” => “%{@timestamp}” #可以不添加時間列,時間列自動獲取@timestasmp
“path” => “%{path}”
“system_info.process.cwd” => “%{system_info.process.cwd}”
“type” => “%{type}”
“host” => “%{host}”
}
}
}
logstash控制檯輸出:

influx查看:
在這裏插入圖片描述

另一種logstash過濾方式,json過濾:
input{
file {
path => ["/zork/software/testjson.log"]
type => “testjson”
start_position => “beginning”
#codec => “json” #註釋掉
}
}

filter{
json {
source => “message”
target => “jsoncontent”
add_field => {
“system_info.process.cwd” => “%{[jsoncontent][system_info][process][cwd]}”
}
remove_field => [“message”, “jsoncontent”,"@version"]
}
}
output輸出不變

發佈了42 篇原創文章 · 獲贊 32 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章