日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

为什么我们需要Logstash,Fluentd等日志摄取器?

發布時間:2023/12/4 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 为什么我们需要Logstash,Fluentd等日志摄取器? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前文傳送門:如何利用NLog輸出結構化日志,并在Kibana優雅分析日志?

疑問:既然應用能直接向ElasticSearch寫日志,為什么我們還需要Logstash,Fluentd等日志攝取器?而且這些日志攝取器組件還成為日志收集的事實標準?

  • 與成都大佬的溝通答疑:

  • 最近讀到的十二要素方法論第11點:Treat logs as event streams

  • A twelve-factor app never concerns itself with routing or storage of its output stream. It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout. During local development, the developer will view this stream in the foreground of their terminal to observe the app’s behavior.

    總結:您的應用不應該關注日志的路由和存儲(Elasticsearch / Graylog / ...),您的日志應該只輸出到stdout,整個系統所有應用保持統一輸出,由日志攝取器無侵入式收集

    在具有多種服務的dockerized環境中,每個容器都是隔離的并擁有自己的日志,我們需要一個接口來收集這些日志。
    Docker Logging Driver就是干這個的:每個docker守護程序都有一個日志驅動程序,所有容器的日志都會流經該驅動程序, Docker Logging Drive讓我們具備處理、轉發日志的能力。

    Fluent Bit vs Fluentd

    流行的庫是Fluentd, 這是一個開源的日志收集、處理、聚合組件,使用Ruby開發。
    Fluent-Bit是從同一項目中fok出來的,用C寫成的開源日志收集器。


    FluentdFluent Bit
    ScopeContainers / ServersContainers / Servers
    LanguageC & RubyC
    Memory~40MB~450KB
    PerformanceHigh PerformanceHigh Performance
    DependenciesBuilt as a Ruby Gem, it requires a certain number of gems.Zero dependencies, unless some special plugin requires them.
    PluginsMore than 650 plugins availableAround 50 plugins available
    LicenseApache License v2.0Apache License v2.0

    下面我們使用輕量級的Fluent-bit向ElasticSearch發送容器日志。

    可通過文件或者命令行配置Fluent-Bit,下面是關鍵的配置節:

    • Service:定義Fluent-Bit引擎的全局行為

    • Input:定義Fluent-Bit從什么地方收集數據

    • Parser:將非結構化日志轉換為結構化日志

    • Filter:修改Input插件收集的傳入數據

    • Output:定義Fluent Bit將數據輸出到哪里

    Fluent Bit as Docker Logging Driver

    為收集、轉發容器日志,我們需要將Fluent Bit設置為Docker Logging Driver。

    • 使用forward輸入插件,監聽Forward協議的轉發消息

    • 要將日志轉發到Elasticsearch,需設置es輸出插件

    fluent-bit.conf示例如下:

    [SERVICE]log_level?info[INPUT]Name?forwardListen?0.0.0.0port?24224[OUTPUT]Name?esMatch?**Host?127.0.0.1Port?9243#?When?Logstash_Format?is?enabled,?the?Index?name?is?composed?using?a?prefix?and?the?dateLogstash_Format?True#?HTTP_User?<user>#?HTTP_Passwd?<pw>#?Alternative?time?key,?useful?if?your?log?entries?contain?an?@timestamp?field?that?is?used?by?Elasticsearch#?Time_Key?es_time#?If?your?Elasticsearch?is?using?TLS,?configure?this#?tls?On#?tls.verify?Off

    啟動ES、Fluent-Bit和一個產生日志的測試項目:

    version:?"3.5" services:elasticsearch:image:?elasticsearch:7.6.2ports:-?"9200:9200"environment:-?"ES_JAVA_OPTS=-Xms512m?-Xmx512m"-?discovery.type=single-nodefluentbit:image:?fluent/fluent-bit:1.5.3volumes:-?type:?bindsource:?./fluent-bit.conftarget:?/fluent-bit/etc/fluent-bit.confports:-?"24224:24224"-?"24224:24224/udp"depends_on:-?elasticsearchubuntu:image:?ubuntucommand:?[/bin/echo,?"Dotnet Plus很干,值得關注!"]depends_on:-?fluentbitlogging:driver:?fluentdoptions:tag:?docker-ubuntu

    其中注意:

  • Fluent-Bit容器外掛pipeline配置文件

  • Fluentd和Fluent Bit均使用fluentd作為Docker Logging Driver。

  • 檢查ElasticSearch中的日志

    curl?localhost:9200/_cat/indices

    yellow open logstash-2020.08.22 vqoyvKE4SFCcJtfo6BRmQg 1 1 1 0 6.2kb 6.2kb

    ?curl?localhost:9200/logstash-2020.08.22/_search?pretty=true&q={'matchAll':{''}} {"took"?:?4,"timed_out"?:?false,"_shards"?:?{"total"?:?1,"successful"?:?1,"skipped"?:?0,"failed"?:?0},"hits"?:?{"total"?:?{"value"?:?1,"relation"?:?"eq"},"max_score"?:?1.0,"hits"?:?[{"_index"?:?"logstash-2020.08.22","_type"?:?"_doc","_id"?:?"z0WsFnQBU8QzIbCaBXGY","_score"?:?1.0,"_source"?:?{"@timestamp"?:?"2020-08-22T14:56:33.000Z","log"?:?"Dotnet Plus很干,值得關注!","container_id"?:?"e921435eb7b8dc61bbb8e938bf67cea2694e2afd699ca71c4ef5b6d7cca12e34","container_name"?:?"/ef_ubuntu_1","source"?:?"stdout"}}]} }

    docker應用僅使用stdout,docker logging driver將日志轉發至Fluent-Bit,Fluent-Bit將它們轉發給Elasticsearch。

    小編結束語

    以上就是利用Fluent-Bit從容器應用收集日志并發送到ElasticSearch的基本示例。

    我們再回顧下Fluent-Bit產生的背景和特性:
    如今,我們環境中的信息源在不斷增加,數據收集越來越復雜,需要解決

    • 不同的信息來源

    • 不同的數據格式

    • 數據可靠性

    • 安全

    • 靈活的路由

    • 多個目的地

    Fluent-Bit旨在成為日志收集和加工的通用瑞士軍刀, 同時Fluent Bit在設計時考慮了性能和低資源消耗。

    干貨周邊也很重要

  • [十二要素方法論] ? 十二要素App方法論

  • [如何利用NLog輸出結構化日志] ? https://github.com/nlog/nlog/wiki/How-to-use-structured-logging

  • [NLog to ES] ? https://github.com/markmcdowell/NLog.Targets.ElasticSearch

  • [被忽略的TraceId,可以用起來了]

  • Logging with ElasticSearch, Kibana, ASP.NET Core and Docker

  • 總結

    以上是生活随笔為你收集整理的为什么我们需要Logstash,Fluentd等日志摄取器?的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。