【问题标题】:fluentd not showing output of python script流利的不显示python脚本的输出
【发布时间】:2021-06-19 03:53:21
【问题描述】:

我正在尝试在 fluentd 中运行 python 脚本。 Python 脚本只是将一些 json 写入标准输出。

Python 脚本 (events.py) :-

import sys
import json

for i in range(3):
    sys.stdout.write(json.dumps({"a":i,"b":i}))
    sys.stdout.write("\n")

fluentd 假设执行脚本并将 python 程序的输出写入标准输出,因为我正在使用 exec 输入插件和 stdout 输出插件。

fluentd config:- (events.py 在当前目录)

<source>
  @type exec
  tag pythonevents
  command python events.py
  run_interval 1m
  <parse>
    @type json
  </parse>
</source>

<match pythonevents> 
  @type stdout
</match>

以及我运行fluentd时的输出:-

fluentd -c /fluentd/etc/main-config.conf
2021-06-19 02:36:08 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/main-config.conf"
2021-06-19 02:36:08 +0000 [info]: gem 'fluent-plugin-pgjson' version '1.0.1'  
2021-06-19 02:36:08 +0000 [info]: gem 'fluent-plugin-postgres' version '0.1.0'
2021-06-19 02:36:08 +0000 [info]: gem 'fluent-plugin-sql' version '2.2.0'     
2021-06-19 02:36:08 +0000 [info]: gem 'fluentd' version '1.13.0'
2021-06-19 02:36:08 +0000 [info]: gem 'fluentd' version '1.12.4'
2021-06-19 02:36:08 +0000 [info]: using configuration file: <ROOT>
  <source>
    @type exec
    tag "pythonevents"
    command "python events.py"
    run_interval 1m
    <parse>
      @type "json"
    </parse>
  </source>
  <match pythonevents>
    @type stdout
  </match>
</ROOT>
2021-06-19 02:36:08 +0000 [info]: starting fluentd-1.13.0 pid=7 ruby="2.6.7"
2021-06-19 02:36:08 +0000 [info]: spawn command to main:  cmdline=["/usr/local/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/main-config.conf", "-p", "/fluentd/plugins", "--under-supervisor"]
2021-06-19 02:36:09 +0000 [info]: adding match pattern="pythonevents" type="stdout"
2021-06-19 02:36:09 +0000 [info]: adding source type="exec"
2021-06-19 02:36:09 +0000 [info]: #0 starting fluentd worker pid=16 ppid=7 worker=0
2021-06-19 02:36:09 +0000 [info]: #0 fluentd worker is now running worker=0

只有这么多的输出。 所以问题是 fluentd 没有在标准输出中显示预期的输出。

编辑 :: 我正在使用 docker。

【问题讨论】:

    标签: python fluentd


    【解决方案1】:

    这个配置对我有用。

    也许您应该为您的 python 二进制文件和脚本使用绝对路径。

    命令 /my/path/python /my/script/path/events.py

    命令的第一次执行是在第一个 run_interval 之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-22
      • 2020-04-10
      • 2017-06-15
      • 2019-03-31
      • 2013-04-20
      • 1970-01-01
      • 2019-04-10
      • 2017-10-02
      相关资源
      最近更新 更多