1. 程式人生 > >Fluentd日誌處理-插件使用和調試問題(四)

Fluentd日誌處理-插件使用和調試問題(四)

logstash health grep have gin data mdb eth -i

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>

fluentd日誌處理-安裝配置(一)
http://blog.51cto.com/11078047/2316881
Fluentd 日誌處理-S3拉取日誌處理(二)
http://blog.51cto.com/11078047/2316910
Fluentd日誌處理-tail拉取(三)
http://blog.51cto.com/11078047/2316958

Fluentd日誌處理-插件使用和調試問題(四)