[rsyslog]Setting log file size to 16Mb (#9504)

Why I did it
The existing log file size in sonic is 1 Mb. Over a period of time this leads to huge number of log files which becomes difficult for monitoring applications to handle.
Instead of large number of small files, the size of the log file is not set to 16 Mb which reduces the number of files over a period of time.

How I did it
Changed the size parameter and related macros in logrotate config for rsyslog

How to verify it
Execute logrotate manually and verify the limit when the file gets rotated.

Signed-off-by: Sudharsan Dhamal Gopalarathnam <sudharsand@nvidia.com>
This commit is contained in:
Sudharsan Dhamal Gopalarathnam 2022-01-14 10:24:07 -08:00 committed by Judy Joseph
parent 2348f17d64
commit 1524d6569d
4 changed files with 25 additions and 1 deletions

View File

@ -377,6 +377,10 @@ echo "system-health.service" | sudo tee -a $GENERATED_SERVICE_FILE
# Copy logrotate.d configuration files
sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate.d/
sudo cp $IMAGE_CONFIGS/logrotate/rsyslog.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.sh $FILESYSTEM_ROOT/usr/bin/
echo "logrotate-config.service" | sudo tee -a $GENERATED_SERVICE_FILE
# Copy systemd-journald configuration files
sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/

View File

@ -0,0 +1,12 @@
[Unit]
Description=Update logrotate configuration
Requires=updategraph.service
After=updategraph.service
[Service]
Type=oneshot
ExecStart=/usr/bin/logrotate-config.sh
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,4 @@
#!/bin/bash
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.j2 -a "{\"var_log_kb\":$(df -k /var/log | sed -n 2p | awk '{ print $2 }') }" > /etc/logrotate.d/rsyslog

View File

@ -35,7 +35,11 @@
/var/log/swss/swss*.rec
/var/log/swss/responsepublisher.rec
{
{% if var_log_kb <= 204800 %}
size 1M
{% else %}
size 16M
{% endif %}
rotate 5000
missingok
notifempty
@ -53,7 +57,7 @@
# should be disabled, just in case they get created and rotated
RESERVED_SPACE_KB=4096
VAR_LOG_SIZE_KB=$(df -k /var/log | sed -n 2p | awk '{ print $2 }')
VARL_LOG_SIZE_KB={{var_log_kb}}
# Limit usable space to 90% of the partition minus the reserved space for other logs
USABLE_SPACE_KB=$(( (VAR_LOG_SIZE_KB * 90 / 100) - RESERVED_SPACE_KB))