最常用的兩個輸出插件:
- redis
- es
一、redis
1、用法
1 output { 2 redis{ 3 batch => false 4 batch_events => 50 5 batch_timeout => 5 6 codec => plain 7 congestion_interval => 1 8 congestion_threshold => 0 9 data_type => list 10 db => 0 11 host => ["127.0.0.1:6379"] 12 key => xxx 13 password => xxx 14 port => 6379 15 reconnect_interval => 1 16 shuffle_hosts => true 17 timeout => 5 18 workers => 1 19 } 20 }
2、配置項
以上所有配置項都是可選的,沒有必須的。(以下4個紅色配置是最重要的4個配置)
- 批處理類(僅用於data_type為list)
- batch:設為true,通過發送一條rpush命令,存儲一批的數據
- 默認為false:1條rpush命令,存儲1條數據
- 設為true之后,1條rpush會發送batch_events條數據或發送batch_timeout秒(取決於哪一個先到達)
- batch_events:一次rpush多少條
- 默認50條
- batch_timeout:一次rpush最多消耗多少s
- 默認5s
- batch:設為true,通過發送一條rpush命令,存儲一批的數據
- 編碼類
- codec:對輸出數據進行codec,避免使用logstash的separate filter
- 擁塞保護(僅用於data_type為list)
- congestion_interval:每多長時間進行一次擁塞檢查
- 默認1s
- 設為0,表示對每rpush一個,都進行檢測
- congestion_threshold:list中最多可以存在多少個item數據
- 默認是0:表示禁用擁塞檢測
- 當list中的數據量達到congestion_threshold,會阻塞直到有其他消費者消費list中的數據
- 作用:防止OOM
- congestion_interval:每多長時間進行一次擁塞檢查
- data_type
- list:使用rpush
- channel:使用publish
- db:使用redis的數據庫,默認使用0號
- host:數組
- eg.["127.0.0.1:6380", "127.0.0.1"]
- 可以指定port,會覆蓋全局port
- port:全局port,默認6379
- key:list或channel的名字
- 支持動態key,例如:logstash-%{type}
- password:redis密碼,默認不使用密碼
- reconnect_interval:失敗重連的間隔,默認為1s
- timeout:連接超時,默認5s
二、es
1、使用方式
1 output { 2 elasticsearch { 3 hosts => ["127.0.0.1:9200"] 4 action => index 5 cacert => /xxx 6 codec => plain 7 doc_as_upsert => false 8 document_id => 1 9 document_type => xxx 10 flush_size => 500 11 idle_flush_time => 1 12 index => logstash-%{+YYYY.MM.dd} 13 keystore => /xxx 14 keystore_password => xxx 15 manage_template => true 16 max_retries => 3 17 parent => nil 18 password => xxx 19 path => / 20 proxy => xxx 21 retry_max_interval => 2 22 routing => xxx 23 script => xxx 24 script_lang => xxx 25 script_type => inline 26 script_var_name => event 27 scripted_upsert => false 28 sniffing => false 29 sniffing_delay => 5 30 ssl => false 31 ssl_certificate_verification => true 32 template => /xxx 33 template_name => logstash 34 template_overwrite => false 35 timeout => 5 36 truststore => /xxx 37 truststore_password => xxx 38 upsert => xxx 39 user => xxx 40 workers => 1 41 } 42 }
2、基本配置
以上配置全部都是可選的,沒有必須的。以下列出最重要的幾個。
- hosts:["127.0.0.1:9200","127.0.0.2:9200"]
- action:指定es的行為,
index
,delete
,create
,update
- 默認為index:index a document(該document就是一個來自於logstash的event)
- delete:通過id刪除一個document(需要指定document_id)
- create:index a document(如果該document已經在index中存在,則失敗)
- update:通過id更新一個document
- cacert:驗證server合法性的.cer或.pem文件路徑
- codec:
- document_id
- document_type
- index:默認值:logstash-%{+YYYY.MM.dd}
- 便於刪除老數據
- 在語法解析的時候,看到+號開頭的,會自動認為后面是時間格式,嘗試用時間格式來解析后續字符串。所以,之前處理過程中不要給自定義的字段起一個+號開頭的名字
- 索引名中不能有大寫字母
- 有時也會自定義為:logstash-%{servicename}-%{+YYYY.MM.dd}
- user:進入es cluster的用戶
- password:進入es cluster的密碼
- timeout:Set the timeout for network operations and requests sent Elasticsearch. If a timeout occurs, the request will be retried.
- flush_size:默認500,logstash攢夠500條數據再一次性向es發送
- idle_flush_time:默認1s,如果1s內沒攢夠500條還是會一次性將攢的數據發出去給es