日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

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

前文傳送門:如何利用NLog輸出結(jié)構(gòu)化日志,并在Kibana優(yōu)雅分析日志?

疑問:既然應(yīng)用能直接向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.

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

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

    Fluent Bit vs Fluentd

    流行的庫是Fluentd, 這是一個開源的日志收集、處理、聚合組件,使用Ruby開發(fā)。
    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發(fā)送容器日志。

    可通過文件或者命令行配置Fluent-Bit,下面是關(guān)鍵的配置節(jié):

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

    • Input:定義Fluent-Bit從什么地方收集數(shù)據(jù)

    • Parser:將非結(jié)構(gòu)化日志轉(zhuǎn)換為結(jié)構(gòu)化日志

    • Filter:修改Input插件收集的傳入數(shù)據(jù)

    • Output:定義Fluent Bit將數(shù)據(jù)輸出到哪里

    Fluent Bit as Docker Logging Driver

    為收集、轉(zhuǎn)發(fā)容器日志,我們需要將Fluent Bit設(shè)置為Docker Logging Driver。

    • 使用forward輸入插件,監(jiān)聽Forward協(xié)議的轉(zhuǎn)發(fā)消息

    • 要將日志轉(zhuǎn)發(fā)到Elasticsearch,需設(shè)置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和一個產(chǎn)生日志的測試項目:

    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很干,值得關(guān)注!"]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很干,值得關(guān)注!","container_id"?:?"e921435eb7b8dc61bbb8e938bf67cea2694e2afd699ca71c4ef5b6d7cca12e34","container_name"?:?"/ef_ubuntu_1","source"?:?"stdout"}}]} }

    docker應(yīng)用僅使用stdout,docker logging driver將日志轉(zhuǎn)發(fā)至Fluent-Bit,Fluent-Bit將它們轉(zhuǎn)發(fā)給Elasticsearch。

    小編結(jié)束語

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

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

    • 不同的信息來源

    • 不同的數(shù)據(jù)格式

    • 數(shù)據(jù)可靠性

    • 安全

    • 靈活的路由

    • 多個目的地

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

    干貨周邊也很重要

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

  • [如何利用NLog輸出結(jié)構(gòu)化日志] ? 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

  • 總結(jié)

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

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。