Skip to content

Commit bd0a19a

Browse files
authored
[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 <[email protected]>
1 parent ca36b4a commit bd0a19a

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

files/build_templates/sonic_debian_extension.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ echo "system-health.service" | sudo tee -a $GENERATED_SERVICE_FILE
377377

378378
# Copy logrotate.d configuration files
379379
sudo cp -f $IMAGE_CONFIGS/logrotate/logrotate.d/* $FILESYSTEM_ROOT/etc/logrotate.d/
380+
sudo cp $IMAGE_CONFIGS/logrotate/rsyslog.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
381+
sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
382+
sudo cp $IMAGE_CONFIGS/logrotate/logrotate-config.sh $FILESYSTEM_ROOT/usr/bin/
383+
echo "logrotate-config.service" | sudo tee -a $GENERATED_SERVICE_FILE
380384

381385
# Copy systemd-journald configuration files
382386
sudo cp -f $IMAGE_CONFIGS/systemd/journald.conf $FILESYSTEM_ROOT/etc/systemd/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Update logrotate configuration
3+
Requires=updategraph.service
4+
After=updategraph.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/bin/logrotate-config.sh
9+
10+
[Install]
11+
WantedBy=multi-user.target
12+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
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
4+

files/image_config/logrotate/logrotate.d/rsyslog renamed to files/image_config/logrotate/rsyslog.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
/var/log/swss/swss*.rec
3636
/var/log/swss/responsepublisher.rec
3737
{
38+
{% if var_log_kb <= 204800 %}
3839
size 1M
40+
{% else %}
41+
size 16M
42+
{% endif %}
3943
rotate 5000
4044
missingok
4145
notifempty
@@ -53,7 +57,7 @@
5357
# should be disabled, just in case they get created and rotated
5458
RESERVED_SPACE_KB=4096
5559

56-
VAR_LOG_SIZE_KB=$(df -k /var/log | sed -n 2p | awk '{ print $2 }')
60+
VARL_LOG_SIZE_KB={{var_log_kb}}
5761

5862
# Limit usable space to 90% of the partition minus the reserved space for other logs
5963
USABLE_SPACE_KB=$(( (VAR_LOG_SIZE_KB * 90 / 100) - RESERVED_SPACE_KB))

0 commit comments

Comments
 (0)