]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: adds counters on received syslog messages.
authorEmeric Brun <ebrun@haproxy.com>
Thu, 9 Jul 2020 21:23:34 +0000 (23:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 15 Jul 2020 15:50:12 +0000 (17:50 +0200)
This patch adds a global counter of received syslog messages
and this one is exported on CLI "show info" as "CumRecvLogs".

This patch also updates internal conn counter and freq
of the listener and the proxy for each received log message to
prepare a further export on the "show stats".

include/haproxy/log.h
include/haproxy/stats-t.h
src/log.c
src/stats.c

index d8b95a82bdaed907b2c53d69b17738a6c0bf12e3..981086906cbe0fc0ead4580aeceb773e242cf7f2 100644 (file)
@@ -49,6 +49,9 @@ extern struct proxy *cfg_log_forward;
 extern THREAD_LOCAL char *logline;
 extern THREAD_LOCAL char *logline_rfc5424;
 
+/* global syslog message counter */
+extern int cum_log_messages;
+
 /* syslog UDP message handler */
 void syslog_fd_handler(int fd);
 
@@ -165,6 +168,7 @@ static inline int build_logline(struct stream *s, char *dst, size_t maxsize, str
 }
 
 struct ist *build_log_header(enum log_fmt format, int level, int facility, struct ist *metadata, size_t *nbelem);
+
 #endif /* _HAPROXY_LOG_H */
 
 /*
index baf2fac5d0cde2024a8538dd762135c78a1ada33..139b5468b157abaf6ad66310a794f179190ced7a 100644 (file)
@@ -317,6 +317,7 @@ enum info_field {
        INF_TOTAL_SPLICED_BYTES_OUT,
        INF_BYTES_OUT_RATE,
        INF_DEBUG_COMMANDS_ISSUED,
+       INF_CUM_LOG_MSGS,
 
        /* must always be the last one */
        INF_TOTAL_FIELDS
index f8ac522010f904cde494c95a600510b5ee08ec90..495a672d24ee5a631dc3f7f89bab5b2d6c46c41f 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -45,6 +45,8 @@
 #include <haproxy/tools.h>
 #include <haproxy/version.h>
 
+/* global recv logs counter */
+int cum_log_messages;
 
 /* log forward proxy list */
 struct proxy *cfg_log_forward;
@@ -3538,6 +3540,10 @@ void syslog_fd_handler(int fd)
                        }
                        buf->data = ret;
 
+                       /* update counters */
+                       _HA_ATOMIC_ADD(&cum_log_messages, 1);
+                       proxy_inc_fe_conn_ctr(l, l->bind_conf->frontend);
+
                        parse_log_message(buf->area, buf->data, &level, &facility, metadata, &message, &size);
 
                        process_send_log(&l->bind_conf->frontend->logsrvs, level, facility, metadata, message, size);
index e8ea831a7e6c982cddc1c568c8d0d4aacbcb4729..d69c76462c23ffc7bfede70811ab4a8def46fb0c 100644 (file)
@@ -147,6 +147,7 @@ const struct name_desc info_fields[INF_TOTAL_FIELDS] = {
        [INF_TOTAL_SPLICED_BYTES_OUT]        = { .name = "TotalSplicdedBytesOut",       .desc = "Total number of bytes emitted by current worker process through a kernel pipe since started" },
        [INF_BYTES_OUT_RATE]                 = { .name = "BytesOutRate",                .desc = "Number of bytes emitted by current worker process over the last second" },
        [INF_DEBUG_COMMANDS_ISSUED]          = { .name = "DebugCommandsIssued",         .desc = "Number of debug commands issued on this process (anything > 0 is unsafe)" },
+       [INF_CUM_LOG_MSGS]                   = { .name = "CumRecvLogs",                 .desc = "Total number of log messages received by log-forwarding listeners on this worker process since started" },
 };
 
 const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
@@ -3523,6 +3524,7 @@ int stats_fill_info(struct field *info, int len)
        info[INF_TOTAL_SPLICED_BYTES_OUT]        = mkf_u64(0, global.spliced_out_bytes);
        info[INF_BYTES_OUT_RATE]                 = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32);
        info[INF_DEBUG_COMMANDS_ISSUED]          = mkf_u32(0, debug_commands_issued);
+       info[INF_CUM_LOG_MSGS]                   = mkf_u32(FN_COUNTER, cum_log_messages);
 
        return 1;
 }