Fluentd日誌處理-外掛使用和除錯問題(四)
阿新 • • 發佈:2018-11-21
fluentd一些外掛的使用
geoip的配置模版
<filter request> @type geoip geoip_lookup_keys ip backend_library geoip_c geoip2_database /fluentd/plugin/GeoLite2-City.mmdb geoip2_database /fluentd/plugin/GeoLiteCity.dat <record> location '[${location.latitude["ip"]},${location.longitude["ip"]}]' </record> </filter>
健康日誌的過濾模版
<filter request>
@type grep
<exclude>
key message
pattern /.*healthcheck.*|.*prometheusMetrics.*|.*(v1+\/)+(configurations)+(\/+versions).*/
</exclude>
</filter>
刪除某些欄位
<filter *> @type record_transformer remove_keys message </filter>
fluentd優化的問題。
1.有日誌有些會丟失,
path /log-dir/*-app.log
pos_file /log-dir/app.log.pos
多個日誌檔案的位置記錄寫入一個位置記錄檔案,會導致日誌位置記錄的錯誤,想的辦法:為每個日誌檔案單獨配置一個位置記錄的檔案。
path /log-dir/*-app.log
pos_file ${path}.ops
想通過引用的方式來為每個path建立一個ops,但是結局不生效通過仔細閱讀官方文件,發現一個in_tail程序裡的ops是可以存放多個path
2.日誌會在一分鐘後傳輸到ES上
我把日誌寫入docker日誌檔案,發現fluentd處理讀取和處理速度並不慢,猜測可能是fluentd傳輸到ES過程中的問題。
通過在在match輸出上面重新整理緩衝區,及時把緩衝區的資料送到ES,
<match app.*>
@type elasticsearch
host elasticsearchlog-lb.elasticsearch-log
index_name s3-fluentd-idaas
type_name s3-fluentd-idaas
flush_interval 2s
include_timestamp true
ssl_verify false
</match>
第二個方法就是找到衝突的地方刪除掉衝突點(僅僅是個想法)
3.fluentd報警刷屏
id和key都沒問題,因為昨天晚上我從S3上拉取下來過,
今天s3的桶裡面加上了路徑
Amazon S3 logstash-idaas/2018/10/20/
容器日誌報出的錯誤
error_class=Aws::S3::Errors::NoSuchKey error="The specified key does not exist."
(1)測試沒有字首的時候是否會報錯
結局:報錯少了一些,但是還是會報錯
(2)排錯過程:
1.我想看看logstash中S3外掛是否會給我產生靈感 否
2.我想測試fluentd中是否有外掛導致了這個問題 否
通過把原有外掛解除安裝,使用最簡外掛方案來執行這個配置檔案
3.Google搜尋看看 否
4.SQS佇列裡含有各桶的資料,相互之間衝突,新建一個SQS解決這個問題 nice
測試出來的原因就是SQS處理多個S3桶資料的時候,每個桶之間的資料會相互雜糅,促使fluentd拉去資料的時候字首路徑衝突,這個時候我們每一個桶分配一個SQS解決這個問題
4.這個佇列無法訪問
2018/11/12 上午11:52:552018-11-12 11:52:55 +0800 [error]: #0 unexpected error error_class=Aws::SQS::Errors::NonExistentQueue error="The specified queue does not exist or you do not have access to it
檢查佇列名字和SQS的許可權配置,還有需要檢查S3桶的事件通知
5.報出一個錯誤
2018/11/15 下午7:00:222018-11-15 19:00:22 +0800 [warn]: #0 dump an error event: error_class=Fluent::Plugin::ElasticsearchErrorHandler::ElasticsearchError error="400 - Rejected by Elasticsearch" location=nil tag="app.idaas"
通過觀看,發現這個問題主要是app.idaas標籤產生的,因為這個標籤沒有filter,後來對app.idaas進行一次filter後,這個警告問題可以大大緩解。
<filter app.idaas>
@type parser
key_name thread_name
reserve_data yes
<parse>
@type regexp
expression /(?<thread_name>[\d\D]+)/
</parse>
</filter>
6.ES報出的錯誤
2018/11/16 下午4:16:072018-11-16 16:16:07 +0800 [warn]: #0 Could not push logs to Elasticsearch, resetting connection and trying again. read timeout reached
2018-11-16 16:16:44 +0800 [warn]: #0 buffer flush took longer time than slow_flush_log_threshold: elapsed_time=66.07182049937546 slow_flush_log_threshold=20.0 plugin_id="object:2ac85a0bd4a0"
去除下面buffer中的timekey和timekey_wait
index_name s3-fluentd-request-%Y%m%d
<buffer tag,time>
timekey 4s
timekey_wait 1s
</buffer>