【问题标题】:How to get a program's std-out to fluentd (without docker)如何让程序的标准输出流利(没有 docker)
【发布时间】:2020-06-04 21:51:53
【问题描述】:

场景:

您用 R 或 Python 编写了一个程序,该程序需要在 Linux 或 Windows 上运行,您想从该程序记录(JSON 结构化和非结构化)std-out 和(主要是非结构化)std-error 到 Fluentd 实例。添加新程序或启动另一个实例不需要更新 Fluentd 配置,并且应用程序将不会(尚未)在 docker 环境中运行。

问题:

如何将“日志”从一堆程序发送到 fluentd 实例,而无需为您的应用程序最初写入标准输出的每个日志条目执行 curl 调用?

当应用程序运行需要 UDP 或 TCP 连接时,它似乎变得不那么容易调试,并且返回 std-out 的程序的任何依赖项都需要被解析,只是为了得到它的日志记录通过了。

想法:

另外,一个问题可能是,如何接受可以指向文件或 TCP 连接的“连接”对象?因此,在标准输出或 TCP 目标之间切换只需更改单个值?

我喜欢'tail'输入插件,这可能是我正在寻找的,但是:

  1. 原始日志文件似乎永远不会停止增长(当它被简单地删除时,跟踪位置值会重置吗?我找不到这种行为),并且
  2. 似乎需要为您在该服务器上启动的每个新程序重新配置 fluentd(如果它登录另一个文件),我非常希望将该配置保留在程序端...

我构建了一个 EFK 堆栈,将 docker logdriver 设置为 fluentd,which does not seem to have an optimal solid solution either,但没有 docker,我已经无法设置基本配置(此处不指 fluent.conf)。

【问题讨论】:

    标签: fluentd


    【解决方案1】:

    TL;DR

    • std-out -> fluentd:在启动程序时将程序输出重定向到文件。在 linux 上,使用 logrotate,你会喜欢的。
    • Windows:使用fluent-bit
    • 应用端配置:使用单一(或可预测的)日志位置,以及 fluentd/fluent-bit 'in_tail' 插件。

    日志一般:

    如果必须将标准输出写入文件pipe it's output at program startup,建议始终将应用程序输出写入文件。为了使 fluentd 配置更加灵活,请将它们通过管道传输到单独的文件中(就像 'Apache' 所做的那样):

    My_program.exe Do some crazy stuf > my_out_file.txt 2> my_error_file.txt
    

    这会打开 fluentd 从这个/这些文件中读取的选项。

    窗户:

    对于 Windows 系统,使用fluent-bit,它可能会解决聚合 Windows 操作系统程序日志的问题。最近刚刚实现了对 Windows 的支持。

    fluent-bit 支持:

    1. 'tail' 插件,它在一个sqllite3数据库,处理不可处理的数据,分配给某个key(默认为'log')
    2. 适用于 Windows 机器,但请注意它不能 buffer to disk,因此请确保及时重新建立或修复丢失的连接或其他输出问题,以免遇到 OOM 问题。李>

    应用程序。侧面配置:

    tail 插件可以监控文件夹,这使得将配置保留在程序一侧几乎成为可能。只需确保将不同应用程序的日志写入可预测的目录即可。

    Fluent 位设置/配置:

    对于 Linux,只需使用 fluentd(需要每秒发送unless > 100000 条消息,这就是 fluent-bit 成为您唯一选择的地方)。

    对于 Windows,安装 Fluent-bit,并使其作为守护进程运行(几乎很有趣 sollution)。

    有2种执行方式:

    1. 直接通过命令行提供配置
    2. 使用配置文件(zip 中包含的示例),并使用 -c 标志引用它。

    直接从命令行

    可以在此处找到一些示例执行(不使用使用配置文件的选项):

    PS .\bin\fluent-bit.exe -i winlog -p "channels=Setup,Windows PowerShell" -p "db=./test.db" -o stdout -m '*'
    

    -i 声明输入法。目前,只实现了几个插件,请参阅下面的手册页。

    PS fluent-bit.exe --help
    
    Available Options
      -b  --storage_path=PATH       specify a storage buffering path
      -c  --config=FILE     specify an optional configuration file
      -f, --flush=SECONDS   flush timeout in seconds (default: 5)
      -F  --filter=FILTER    set a filter
      -i, --input=INPUT     set an input
      -m, --match=MATCH     set plugin match, same as '-p match=abc'
      -o, --output=OUTPUT   set an output
      -p, --prop="A=B"      set plugin configuration property
      -R, --parser=FILE     specify a parser configuration file
      -e, --plugin=FILE     load an external plugin (shared lib)
      -l, --log_file=FILE   write log info to a file
      -t, --tag=TAG         set plugin tag, same as '-p tag=abc'
      -T, --sp-task=SQL     define a stream processor task
      -v, --verbose         increase logging verbosity (default: info)
      -s, --coro_stack_size Set coroutines stack size in bytes (default: 98302)
      -q, --quiet           quiet mode
      -S, --sosreport       support report for Enterprise customers
      -V, --version         show version number
      -h, --help            print this help
    
    Inputs
      tail                  Tail files
      dummy                 Generate dummy data
      statsd                StatsD input plugin
      winlog                Windows Event Log
      tcp                   TCP
      forward               Fluentd in-forward
      random                Random
    
    Outputs
      counter               Records counter
      datadog               Send events to DataDog HTTP Event Collector
      es                    Elasticsearch
      file                  Generate log file
      forward               Forward (Fluentd protocol)
      http                  HTTP Output
      influxdb              InfluxDB Time Series
      null                  Throws away events
      slack                 Send events to a Slack channel
      splunk                Send events to Splunk HTTP Event Collector
      stackdriver           Send events to Google Stackdriver Logging
      stdout                Prints events to STDOUT
      tcp                   TCP Output
      flowcounter           FlowCounter
    
    Filters
      aws                   Add AWS Metadata
      expect                Validate expected keys and values
      record_modifier       modify record
      rewrite_tag           Rewrite records tags
      throttle              Throttle messages using sliding window algorithm
      grep                  grep events by specified field values
      kubernetes            Filter to append Kubernetes metadata
      parser                Parse events
      nest                  nest events by specified field values
      modify                modify records by applying rules
      lua                   Lua Scripting Filter
      stdout                Filter events to STDOUT
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多