mirror of
https://github.com/rsyslog/rsyslog.git
synced 2026-04-23 12:38:12 +02:00
Better observability: expose per-file ingestion metrics so operators can see if a specific file is active and how much data it contributes over time. BEFORE: impstats had no per-file imfile metrics. AFTER: impstats reports per-file bytes.processed and lines.processed. Impact: New impstats objects per watched file; minor per-line overhead. This change introduces a stats object per active imfile file. The object is named with the file path and marked with origin "imfile". Two new resettable counters are registered: bytes.processed (offset delta per read) and lines.processed (incremented on each submitted line). Counters use atomic helpers to remain thread-safe. Objects are constructed when a file is opened and destructed when it is closed; associated counter mutexes are released to avoid leaks. The module now acquires/releases the statsobj interface during init/exit. A new test (imfile-statistics.sh) validates single- and multi-file cases and checks that impstats outputs the expected counters. Build glue is updated to include and run the new test.
53 lines
1.8 KiB
Bash
Executable File
53 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# This is part of the rsyslog testbench, licensed under ASL 2.0
|
|
. ${srcdir:=.}/diag.sh init
|
|
export NUMMESSAGES=1000
|
|
generate_conf
|
|
# NOTE: do NOT set a working directory!
|
|
add_conf '
|
|
module(load="../plugins/imfile/.libs/imfile")
|
|
|
|
# Enable impstats to see the stats
|
|
module(load="../plugins/impstats/.libs/impstats"
|
|
log.file="./'$RSYSLOG_DYNNAME'.stats.log"
|
|
log.syslog="off"
|
|
format="json"
|
|
resetCounters="off"
|
|
interval="1"
|
|
)
|
|
|
|
input(type="imfile" File="./'$RSYSLOG_DYNNAME'_*.input" tag="file:")
|
|
input(type="imfile" File="./'$RSYSLOG_DYNNAME'.input_3" tag="file:")
|
|
|
|
template(name="outfmt" type="string" string="%msg:F,58:2%\n")
|
|
if $msg contains "msgnum:" then
|
|
action(type="omfile" file="'$RSYSLOG_OUT_LOG'" template="outfmt")
|
|
else
|
|
action(type="omfile" file="'$RSYSLOG_DYNNAME'.othermsgs")
|
|
'
|
|
# make sure file(s) exists when rsyslog starts up
|
|
touch "$RSYSLOG_DYNNAME"_1.input
|
|
touch "$RSYSLOG_DYNNAME"_2.input
|
|
touch "$RSYSLOG_DYNNAME".input_3
|
|
startup
|
|
./msleep 2000
|
|
./inputfilegen -m $NUMMESSAGES -i 0 >> "$RSYSLOG_DYNNAME"_1.input
|
|
./inputfilegen -m $NUMMESSAGES -i 1000 >> "$RSYSLOG_DYNNAME"_2.input
|
|
./inputfilegen -m $NUMMESSAGES -i 2000 >> "$RSYSLOG_DYNNAME".input_3
|
|
|
|
wait_file_lines
|
|
shutdown_when_empty
|
|
wait_shutdown
|
|
seq_check 0 2999
|
|
content_check "imfile: no working or state file directory set" $RSYSLOG_DYNNAME.othermsgs
|
|
|
|
EXPECTED_BYTES=$((17 * NUMMESSAGES)) # Test data is 17 bytes per line
|
|
EXPECTED_LINES=$((NUMMESSAGES))
|
|
|
|
for f in "${RSYSLOG_DYNNAME}_1.input" "${RSYSLOG_DYNNAME}_2.input" "${RSYSLOG_DYNNAME}.input_3"; do
|
|
content_check --regex '^.*{ \"name\": \".*'"$f"'\", \"origin\": \"imfile\".*\"bytes.processed\": '"$EXPECTED_BYTES"'.*$' "$RSYSLOG_DYNNAME".stats.log
|
|
content_check --regex '^.*{ \"name\": \".*'"$f"'\", \"origin\": \"imfile\".*\"lines.processed\": '"$EXPECTED_LINES"'.*$' "$RSYSLOG_DYNNAME".stats.log
|
|
done
|
|
|
|
exit_test
|