AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 752839
Accepted
nbari
nbari
Asked: 2016-01-31 02:44:57 +0800 CST2016-01-31 02:44:57 +0800 CST 2016-01-31 02:44:57 +0800 CST

如何让 svlogd 通过 UDP 发送日志

  • 772

我目前正在使用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 }

有任何想法吗 ?

logging
  • 1 1 个回答
  • 1136 Views

1 个回答

  • Voted
  1. Best Answer
    nbari
    2016-03-07T06:42:06+08:002016-03-07T06:42:06+08:00

    添加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

    修补:

    --- src/svlogd.c.orig   2016-03-06 13:48:35 UTC
    +++ src/svlogd.c
    @@ -430,6 +430,7 @@ unsigned int logdir_open(struct logdir *
       ld->name =(char*)fn;
       ld->ppid =0;
       ld->match ='+';
    +  ld->udpaddr.sin_family =AF_INET;
       ld->udpaddr.sin_port =0;
       ld->udponly =0;
       while (! stralloc_copys(&ld->prefix, "")) pause_nomem();
    

    更新:作为当前使用https://immortal.run的此问题的替代方案

    • 0

相关问题

  • IIS 6 - 仅记录某些目录

  • 什么是好的日志查看器,例如 apache、postfix、syslog?

  • 如何提供可搜索的 IRC 日志?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

  • Tomcat 6 HTTP 日志滚动和清除

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve