如何使程序的标准输出流利(没有 docker)

How to get a program's std-out to fluentd (without docker)

场景:

你用 R 或 Python 写了一个程序,它需要 运行 on Linux 或 Windows,你想记录(JSON 结构化和非结构化的)std-out 和(大部分是非结构化的)std-error 从这个程序到 Fluentd 实例。添加新程序或启动另一个实例不需要更新 Fluentd 配置,应用程序将不会(还)运行在 docker 环境中运行。

问题:

如何将一堆程序的“日志”发送到一个 fluentd 实例,而不需要对您的应用程序最初写入 std-out 的每个日志条目执行 curl 调用?

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

想法:

或者,问题可能是,如何接受可以指向文件或 TCP 连接的 'connection' 对象?所以在 std-out 或 TCP 目标之间切换是改变单个值的问题?

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

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

我构建了一个 EFK 堆栈,其中 docker logdriver 设置为 fluentd,which does not seem to have an optimal solid solution either,但没有 docker,我已经有点难以设置基本配置(不是参考这里fluent.conf)。

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 从 this/these 个文件中读取的选项。

Windows:

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

流利位支持:

  1. 'tail' 插件,它记录了 'inode' 值(唯一的,重命名不敏感,文件指针)和 'index' (称为 'pos' 完整-blown 'fluent' application) value in a sqllite3 database and deals un-processable data, which is allocated to a certain key ('log' by default)
  2. 适用于 Windows 台机器,但请注意它不能 buffer to disk,因此请确保丢失的连接或输出的其他问题已及时重新建立或修复,这样您就不会运行陷入 OOM 问题。

申请。侧面配置:

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

流利位setup/config:

对于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