Example: Save all statistics into a file in JSON format
The following configuration increases the stats-level() option to 3, and generates a JSON-formatted message every 10 seconds. The generated message contains every available statistics, and is saved into the /var/log/syslog-ng-statistics.log file.
@version: 7.0
options {
stats-level(3);
keep-hostname(no);
};
source s_monitor { monitoring(
query("*")
freq(1)
message-template("$(format-flat-json --scope nv_pairs)")
);
};
destination d_file {
file("/var/log/syslog-ng-statistics.log");
};
log {
source(s_monitor);
destination(d_file);
};
The generated message is similar to this one:
[2021-09-02T13:30:18.003557] Outgoing message; message='Sep 2 13:30:18 test-host syslog-ng[71345]: {"tag..source.s_monitor.processed":"111","src.severity.7.processed":"0","src.severity.6.processed":"111","src.severity.5.processed":"0","src.severity.4.processed":"0","src.severity.3.processed":"0","src.severity.2.processed":"0","src.severity.1.processed":"0","src.severity.0.processed":"0","src.sender.s_monitor#0.test-host.stamp":"1630582216","src.sender.s_monitor#0.test-host.processed":"111","src.sender.test-host.stamp":"1630582216","src.sender.test-host.processed":"111","src.program.syslog-ng.stamp":"1630582216","src.program.syslog-ng.processed":"111","src.monitoring.s_monitor#0.stamp":"1630582216","src.monitoring.s_monitor#0.processed":"111","src.host.s_monitor#0.test-host.stamp":"1630582216","src.host.s_monitor#0.test-host.processed":"111","src.host.test-host.stamp":"1630582216","src.host.test-host.processed":"111","src.facility.other.pr'
For reference, the JSON part in a readable format is:
{ "tag..source.s_monitor.processed": "111", "src.severity.7.processed": "0", "src.severity.6.processed": "111", "src.severity.5.processed": "0", "src.severity.4.processed": "0", "src.severity.3.processed": "0", "src.severity.2.processed": "0", "src.severity.1.processed": "0", "src.severity.0.processed": "0", "src.sender.s_monitor#0.test-host.stamp": "1630582216", "src.sender.s_monitor#0.test-host.processed": "111", "src.sender.test-host.stamp": "1630582216", "src.sender.test-host.processed": "111", "src.program.syslog-ng.stamp": "1630582216", "src.program.syslog-ng.processed": "111", "src.monitoring.s_monitor#0.stamp": "1630582216", "src.monitoring.s_monitor#0.processed": "111", "src.host.s_monitor#0.test-host.stamp": "1630582216", "src.host.s_monitor#0.test-host.processed": "111", "src.host.test-host.stamp": "1630582216", "src.host.test-host.processed": "111", "src.facility.other.processed": "0", "src.facility.9.processed": "0", "src.facility.8.processed": "0", "src.facility.7.processed": "0", "src.facility.6.processed": "0", "src.facility.5.processed": "111", "src.facility.4.processed": "0", "src.facility.3.processed": "0", "src.facility.23.processed": "0", "src.facility.22.processed": "0", "src.facility.21.processed": "0", "src.facility.20.processed": "0", "src.facility.2.processed": "0", "src.facility.19.processed": "0", "src.facility.18.processed": "0", "src.facility.17.processed": "0", "src.facility.16.processed": "0", "src.facility.15.processed": "0", "src.facility.14.processed": "0", "src.facility.13.processed": "0", "src.facility.12.processed": "0", "src.facility.11.processed": "0", "src.facility.10.processed": "0", "src.facility.1.processed": "0", "src.facility.0.processed": "0", "source.s_monitor.processed": "111", "global.sdata_updates.processed": "0", "global.scratch_buffers_count.queued": "280", "global.scratch_buffers_bytes.queued": "50944", "global.payload_reallocs.processed": "557", "global.msg_clones.processed": "0", "global.msg_allocated_bytes.value": "1056", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.written": "111", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.truncated_count": "0", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.truncated_bytes": "0", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.queued": "0", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.processed": "111", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.msg_size_max": "3019", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.msg_size_avg": "2991", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.memory_usage": "0", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.eps_since_start": "1", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.eps_last_24h": "1", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.eps_last_1h": "1", "dst.file.d_file#0./var/log/syslog-ng-statistics.log.dropped": "0", "destination.d_file.processed": "111", "center.received.processed": "111", "center.queued.processed": "111", "PROGRAM": "syslog-ng", "PID": "71345" }