我目前正在使用runit + svlogd来监督一些应用程序,但是当部署到多台机器时,我需要将日志集中/统一在一个地方以简化事情,否则登录到每台机器会使事情变得非常复杂。
而不是通过 syslog 发送所有主机日志,例如:
*.* remote.log.host
我只想发送与应用程序相关的日志,理论上 svlogd 能够做到这一点,来自文档:
ua.b.c.d[:port]
tells svlogd to transmit the first len characters of selected log messages to the IP address a.b.c.d, port number port. If port isn’t set, the default port for syslog is used (514). len can be set through the -l option, see below. If svlogd has trouble sending udp packets, it writes error messages to the log directory. Attention: logging through udp is unreliable, and should be used in private networks only.
Ua.b.c.d[:port]
is the same as the u line above, but the log messages are no longer written to the log directory, but transmitted through udp only. Error messages from svlogd concerning sending udp packages still go to the log directory.
我的配置文件的内容 /service/my-service/log/main/config
:
u127.0.0.1:5514
或者
U127.0.0.1:5514
为了测试,我创建了一个非常基本的UDP 服务器/客户端,但由于未知原因svlogd
没有发送日志,我也尝试netcat
使用它:
nc -ul 5514
我为此使用的日志运行脚本/service/my-service/log/run
:
#!/bin/sh
exec svlogd -tt ./main
我得到的唯一错误消息是:
warning: failure sending through udp:
我一直在使用的解决方法是logger
在日志运行脚本中调用,例如:
#!/bin/sh
exec chpst -u nobody logger -i -h remote.host.tld -P 42060 -t my-app
但是通过这种方法,我失去了 svlogd 的所有优势,除了sv status .
总是开/关(1,0),因为记录器不像守护进程那样运行。
最后,我想继续获得来自 svlogd 的日志,但可以让工作成为ua.b.c.d[:port]
选项。
更新:做一个 ktrace 这就是我得到的:
4909 svlogd CALL socket(PF_INET,SOCK_DGRAM,IPPROTO_IP)
4909 svlogd RET socket 7
4909 svlogd CALL fcntl(0x7,F_GETFL,0)
4909 svlogd RET fcntl 2
4909 svlogd CALL fcntl(0x7,F_SETFL,0x6<O_RDWR|O_NONBLOCK>)
4909 svlogd RET fcntl 0
4909 svlogd CALL sendto(0x7,0x609580,0x3c,0,0x609c3c,0x10)
4909 svlogd STRU struct sockaddr { AF_UNSPEC, unknown address family }
4909 svlogd RET sendto -1 errno 47 Address family not supported by protocol family
4909 svlogd CALL write(0x6,0x609760,0x62)
4909 svlogd GIO fd 6 wrote 98 bytes
"warning: failure sending through udp:
STRU struct sockaddr { AF_UNSPEC, unknown address family }
有任何想法吗 ?
添加
ld->udpaddr.sin_family =AF_INET;
到svlogd.c
http://skarnet.org/cgi-bin/archive.cgi?2:mss:1163:201602:gpiglpbjdemlioaeabbn
FreeBSD 补丁: https ://bugs.freebsd.org/bugzilla/show_bug.cgi?id=207747
修补:
更新:作为当前使用https://immortal.run的此问题的替代方案