How to make svlogd send logs via UDP

From: Nicolas de Bari Embriz Garcia Rojas <nbari_at_dalmp.com>
Date: Thu, 4 Feb 2016 15:11:27 +0100

I am currently using runit + svlogd <http://smarden.org/runit/> for
supervising some applications, but when deploying to multiple machines, I
have the need to centralize/unify the logs in a single place in order to
simplify things, otherwise login to each machine makes things very
complicated.

Instead of sending all the host logs via syslog with something like:

*.* remote.log.host

I would like to only send the logs related to the application, in theory
svlogd is capable of doing this, from the docs
<http://smarden.org/runit/svlogd.8.html>:

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.

The content of my config file /service/my-service/log/main/config:

u127.0.0.1:5514

or

U127.0.0.1:5514

For testing I created a very basic UDP server/client
<https://github.com/nbari/UDP-proxy/tree/develop>, but for an unknown
reason svlogd is not sending the logs, I also give a try with netcat using
this:

nc -ul 5514

The log run script I am using for this /service/my-service/log/run:

#!/bin/sh

exec svlogd -tt ./main

The only error message I get is:

warning: failure sending through udp:

A work around I have been using is to call logger within the log run
script, something like:

#!/bin/sh

exec chpst -u nobody logger -i -h remote.host.tld -P 42060 -t my-app

But with this approach I lose all the advantage of svlogd besides the sv
status . is always on/off (1,0) since logger don't run like daemon.

At the end I would like to continue having the logs from svlogd but been
available to make work the ua.b.c.d[:port] option.

*Update*: Doing a ktrace this is what I get:

  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 }

Any ideas ?
Received on Thu Feb 04 2016 - 14:11:27 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC