为什么supervisord中的事件监听器只能自己监听?

时间:2018-03-16 08:45:34

标签: python listener alert supervisord

这是我的supervisor.cfg文件

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; (‘AUTO’ child log dir, default $TEMP)
directory=/home/debian/

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

[program:scheduler]
command=/usr/local/bin/airflow scheduler
user=debian
autostart=true
numprocs=1
stdout_logfile=/home/debian/logs/scheduler.log
stderr_logfile=/home/debian/logs/scheduler.log

[eventlistener:mylistener]
command=/home/debian/listener.py
events=PROCESS_STATE_STOPPED,PROCESS_STATE_EXITED,PROCESS_STATE_UNKNOWN,PROCESS_STATE_FATAL,PROCESS_STATE,TICK_60
stdout_logfile=/home/debian/logs/listener.log
stderr_logfile=/home/debian/logs/listener.log

以下是事件监听器的日志:

READY
RESULT 2
OK
READY
ver:3.0 server:supervisor serial:210 pool:mylistener poolserial:0 eventname:PROCESS_STATE_STARTING len:70
processname:mylistener groupname:mylistener from_state:STOPPED tries:0READY
RESULT 2
OK
READY
ver:3.0 server:supervisor serial:513 pool:mylistener poolserial:0 eventname:PROCESS_STATE_STARTING len:70
processname:mylistener groupname:mylistener from_state:STOPPED tries:0READY
RESULT 2
OK
READY
ver:3.0 server:supervisor serial:687 pool:mylistener poolserial:0 eventname:PROCESS_STATE_STARTING len:70
processname:mylistener groupname:mylistener from_state:STOPPED tries:0

调度程序进程按其每分钟失败的方式设置,但事件侦听器不会“看到”那些失败。

debian@8a517401c8a0:~$ sudo supervisorctl
mylistener                       RUNNING    pid 7307, uptime 1 day, 15:52:15
scheduler                        RUNNING    pid 3647, uptime 0:01:02 <-- short uptime
supervisor>

监听器本身就是supervisord文档的例子:

#!/usr/bin/python
import sys

def write_stdout(s):
    # only eventlistener protocol messages may be sent to stdout
    sys.stdout.write(s)
    sys.stdout.flush()

def write_stderr(s):
    sys.stderr.write(s)
    sys.stderr.flush()

def main():
    while 1:
        # transition from ACKNOWLEDGED to READY
        write_stdout('READY\n')

        # read header line and print it to stderr
        line = sys.stdin.readline()
        write_stderr(line)

        # read event payload and print it to stderr
        headers = dict([ x.split(':') for x in line.split() ])
        data = sys.stdin.read(int(headers['len']))
        write_stderr(data)

        # transition from READY to ACKNOWLEDGED
        write_stdout('RESULT 2\nOK')

if __name__ == '__main__':
    main()

那我做错了什么?为什么监听器只记录自己的事件?

1 个答案:

答案 0 :(得分:0)

好的,那是我的坏事。

在文档的示例代码中,我使用

更改了行
  

write_stdout('RESULT 2 \ nOK')

为了更好地形成输出,它打破了这个糟糕的行为。

    # transition from READY to ACKNOWLEDGED
    write_stdout('RESULT 2\nOK\n') <-------- NEVER DO THIS, IT ACCEPTS ONLY CERTAIN TEXTS

在切换到ACKNOWLEDGED之前,您可以打印出您喜欢的内容......通过write_stderr()