Skip to content

Commit

Permalink
log/stats: allow longer counter names
Browse files Browse the repository at this point in the history
With the addition of exception policy stats counters, the human readable
version of the sats log was mis-aligned, when counters for per-app-proto
were enabled.

Width change made large enough to accomodate a counter as long as
"app_layer.error.bittorrent-dht.exception_policy.pass_packet" which
could be valid.

Task OISF#5816
  • Loading branch information
jufajardini authored and victorjulien committed Apr 11, 2024
1 parent 0f6dbf6 commit 172b55c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/log-stats.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2014 Open Information Security Foundation
/* Copyright (C) 2014-2024 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -89,17 +89,16 @@ static int LogStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *s
int days = in_hours / 24;

MemBufferWriteString(aft->buffer, "----------------------------------------------"
"--------------------------------------\n");
"-----------------------------------------------------\n");
MemBufferWriteString(aft->buffer, "Date: %" PRId32 "/%" PRId32 "/%04d -- "
"%02d:%02d:%02d (uptime: %"PRId32"d, %02dh %02dm %02ds)\n",
tms->tm_mon + 1, tms->tm_mday, tms->tm_year + 1900, tms->tm_hour,
tms->tm_min, tms->tm_sec, days, hours, min, sec);
MemBufferWriteString(aft->buffer, "----------------------------------------------"
"--------------------------------------\n");
MemBufferWriteString(aft->buffer, "%-45s | %-25s | %-s\n", "Counter", "TM Name",
"Value");
"-----------------------------------------------------\n");
MemBufferWriteString(aft->buffer, "%-60s | %-25s | %-s\n", "Counter", "TM Name", "Value");
MemBufferWriteString(aft->buffer, "----------------------------------------------"
"--------------------------------------\n");
"-----------------------------------------------------\n");

/* global stats */
uint32_t u = 0;
Expand All @@ -112,7 +111,7 @@ static int LogStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *s
continue;

char line[256];
size_t len = snprintf(line, sizeof(line), "%-45s | %-25s | %-" PRIu64 "\n",
size_t len = snprintf(line, sizeof(line), "%-60s | %-25s | %-" PRIu64 "\n",
st->stats[u].name, st->stats[u].tm_name, st->stats[u].value);

/* since we can have many threads, the buffer might not be big enough.
Expand Down Expand Up @@ -206,7 +205,7 @@ TmEcode LogStatsLogThreadDeinit(ThreadVars *t, void *data)

/** \brief Create a new http log LogFileCtx.
* \param conf Pointer to ConfNode containing this loggers configuration.
* \return NULL if failure, LogFileCtx* to the file_ctx if succesful
* \return NULL if failure, LogFileCtx* to the file_ctx if successful
* */
static OutputInitResult LogStatsLogInitCtx(ConfNode *conf)
{
Expand Down

0 comments on commit 172b55c

Please sign in to comment.