]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: report the number of dropped logs in the stats
authorWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 06:25:28 +0000 (07:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Nov 2018 17:37:55 +0000 (18:37 +0100)
It's easy to detect when logs on some paths are lost as sendmsg() will
return EAGAIN. This is particularly true when sending to /dev/log, which
often doesn't support a big logging capacity. Let's keep track of these
and report the total number of dropped messages in "show info".

include/proto/log.h
include/types/stats.h
src/log.c
src/stats.c

index b994470dd268c1a1c866dfd95d5c8312b20bcc0b..30d4dce7fb977b72ee75a3e26b499994cc62fa53 100644 (file)
@@ -46,6 +46,8 @@ extern char clf_http_log_format[];
 
 extern char default_rfc5424_sd_log_format[];
 
+extern unsigned int dropped_logs;
+
 extern THREAD_LOCAL char *logheader;
 extern THREAD_LOCAL char *logheader_rfc5424;
 extern THREAD_LOCAL char *logline;
index 2cb23bfdc5aa28b59354e4df87afec1f6d9545bc..75250447ec2d597290f5a1a0c9475746b2820cfd 100644 (file)
@@ -293,6 +293,7 @@ enum info_field {
        INF_LISTENERS,
        INF_ACTIVE_PEERS,
        INF_CONNECTED_PEERS,
+       INF_DROPPED_LOGS,
 
        /* must always be the last one */
        INF_TOTAL_FIELDS
index 24e4c3ff0248b7d3e2fc44bf7375aeb532d63380..3434550a387cfbda2b1ff99907911f43eb4443ef 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -210,6 +210,9 @@ char *log_format = NULL;
  */
 char default_rfc5424_sd_log_format[] = "- ";
 
+/* total number of dropped logs */
+unsigned int dropped_logs = 0;
+
 /* This is a global syslog header, common to all outgoing messages in
  * RFC3164 format. It begins with time-based part and is updated by
  * update_log_hdr().
@@ -1478,7 +1481,9 @@ send:
                if (sent < 0) {
                        static char once;
 
-                       if (!once) {
+                       if (errno == EAGAIN)
+                               HA_ATOMIC_ADD(&dropped_logs, 1);
+                       else if (!once) {
                                once = 1; /* note: no need for atomic ops here */
                                ha_alert("sendmsg() failed in logger #%d: %s (errno=%d)\n",
                                         nblogger, strerror(errno), errno);
index 78342cde7f0665442ab85d414326b078fe3d5802..07a5ef74ea61d0e9a7604d2e83feb903038ec132 100644 (file)
@@ -135,6 +135,7 @@ const char *info_field_names[INF_TOTAL_FIELDS] = {
        [INF_LISTENERS]                      = "Listeners",
        [INF_ACTIVE_PEERS]                   = "ActivePeers",
        [INF_CONNECTED_PEERS]                = "ConnectedPeers",
+       [INF_DROPPED_LOGS]                   = "DroppedLogs",
 };
 
 const char *stat_field_names[ST_F_TOTAL_FIELDS] = {
@@ -3302,6 +3303,7 @@ int stats_fill_info(struct field *info, int len)
        info[INF_LISTENERS]                      = mkf_u32(0, listeners);
        info[INF_ACTIVE_PEERS]                   = mkf_u32(0, active_peers);
        info[INF_CONNECTED_PEERS]                = mkf_u32(0, connected_peers);
+       info[INF_DROPPED_LOGS]                   = mkf_u32(0, dropped_logs);
 
        return 1;
 }