-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[System logs]: Improvements to prevent filling /var/log partition #865
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
25e8c88
[System logs]: Delete archive files based on remaining /var/log parti…
jleveque 4748768
Add custom logrotate files for apt, dpkg and monit to rotate based on…
jleveque 87ca754
Update sonic-sairedis and sonic-swss submodules to incorporate record…
jleveque a87e0e7
Remove debug echo statements
jleveque 50b0b3b
Limit usable space to 95% of the partition
jleveque 7b71ff2
Increase log rotation size threshold to 1M
jleveque f8c5f6f
Consistent spacing
jleveque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Build system related | ||
.platform | ||
.screen | ||
|
||
# Build artifacts | ||
fsroot/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Attempt to rotate system logs once per minute | ||
* * * * * root /usr/sbin/logrotate /etc/logrotate.d/rsyslog | ||
* * * * * root /usr/sbin/logrotate /etc/logrotate.conf > /dev/null 2>&1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# see "man logrotate" for details | ||
# Rotate log files daily by default | ||
daily | ||
|
||
# Keep 4 days worth of backlogs by default | ||
rotate 4 | ||
|
||
# create new (empty) log files after rotating old ones | ||
create | ||
|
||
# uncomment this if you want your log files compressed | ||
#compress | ||
|
||
# packages drop log rotation information into this directory | ||
include /etc/logrotate.d | ||
|
||
# no packages own wtmp, or btmp -- we'll rotate them here | ||
/var/log/wtmp { | ||
missingok | ||
size 100k | ||
create 0664 root utmp | ||
rotate 1 | ||
} | ||
|
||
/var/log/btmp { | ||
missingok | ||
size 100k | ||
create 0660 root utmp | ||
rotate 1 | ||
} | ||
|
||
# system-specific logs may be configured here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/var/log/apt/term.log { | ||
size 100k | ||
rotate 1 | ||
compress | ||
missingok | ||
notifempty | ||
} | ||
|
||
/var/log/apt/history.log { | ||
size 100k | ||
rotate 1 | ||
compress | ||
missingok | ||
notifempty | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/var/log/dpkg.log { | ||
size 100k | ||
rotate 1 | ||
compress | ||
delaycompress | ||
missingok | ||
notifempty | ||
create 644 root root | ||
} | ||
/var/log/alternatives.log { | ||
size 100k | ||
rotate 1 | ||
compress | ||
delaycompress | ||
missingok | ||
notifempty | ||
create 644 root root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/var/log/monit.log { | ||
size 100k | ||
rotate 1 | ||
missingok | ||
create 640 root adm | ||
notifempty | ||
compress | ||
delaycompress | ||
postrotate | ||
invoke-rc.d monit reload > /dev/null | ||
endscript | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# These logs should no longer get created. However, in case they do get created, | ||
# we should keep them to a small size and rotate them also. | ||
/var/log/mail.info | ||
/var/log/mail.warn | ||
/var/log/mail.err | ||
/var/log/mail.log | ||
/var/log/daemon.log | ||
/var/log/kern.log | ||
/var/log/user.log | ||
/var/log/lpr.log | ||
/var/log/debug | ||
/var/log/messages | ||
{ | ||
size 10k | ||
rotate 1 | ||
missingok | ||
notifempty | ||
compress | ||
delaycompress | ||
sharedscripts | ||
postrotate | ||
# calling kill directly instead of 'service rsyslog rotate >/dev/null' due | ||
# to bug in init-system-helpers. bug has apparently been fixed in v1.47. | ||
# however, debian jessie is still using v1.22. | ||
# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672218 | ||
kill -hup $(cat /var/run/rsyslogd.pid) | ||
endscript | ||
} | ||
|
||
/var/log/auth.log | ||
/var/log/cron.log | ||
/var/log/syslog | ||
/var/log/teamd.log | ||
/var/log/quagga/bgpd.log | ||
/var/log/quagga/zebra.log | ||
/var/log/swss/sairedis.rec | ||
/var/log/swss/swss.rec | ||
{ | ||
size 512k | ||
rotate 5000 | ||
missingok | ||
notifempty | ||
compress | ||
delaycompress | ||
nosharedscripts | ||
prerotate | ||
# Adjust NUM_LOGS_TO_ROTATE to reflect number of log files that trigger this block specified above | ||
NUM_LOGS_TO_ROTATE=8 | ||
|
||
# Reserve space for btmp, wtmp, dpkg.log, monit.log, etc., as well as logs that | ||
# 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}') | ||
|
||
# Limit usable space to 95% of the partition minus the reserved space for other logs | ||
USABLE_SPACE_KB=$(( (VAR_LOG_SIZE_KB * 95 / 100) - RESERVED_SPACE_KB)) | ||
|
||
# Set our threshold so as to maintain enough space to write all logs from empty to full | ||
# Most likely, some logs will have non-zero size when this is called, so this errs on the side | ||
# of caution, giving us a bit of a cushion if a log grows quickly and passes its rotation size | ||
THRESHOLD_KB=$((USABLE_SPACE_KB - (512 * NUM_LOGS_TO_ROTATE * 2))) | ||
|
||
while true; do | ||
USED_KB=$(du -s /var/log | awk '{ print $1; }') | ||
|
||
if [ $USED_KB -lt $THRESHOLD_KB ]; then | ||
break | ||
else | ||
OLDEST_ARCHIVE_FILE=$(find /var/log -type f -printf '%T+ %p\n' | grep -E '.+\.[0-9]+(\.gz)?$' | sort | head -n 1 | awk '{ print $2; }') | ||
|
||
if [ -z "$OLDEST_ARCHIVE_FILE" ]; then | ||
logger -p syslog.err -t "logrotate" "No archive file to delete -- potential for filling up /var/log partition!" | ||
break | ||
fi | ||
|
||
logger -p syslog.info -t "logrotate" "Deleting archive file $OLDEST_ARCHIVE_FILE to free up space" | ||
rm -rf "$OLDEST_ARCHIVE_FILE" | ||
fi | ||
done | ||
endscript | ||
postrotate | ||
if [ $(echo $1 | grep -c "/var/log/swss/") -gt 0 ]; then | ||
pgrep -x orchagent | xargs /bin/kill -HUP 2>/dev/null || true | ||
else | ||
# Calling kill directly instead of 'service rsyslog rotate >/dev/null' due | ||
# to bug in init-system-helpers. Bug has apparently been fixed in v1.47. | ||
# However, Debian Jessie is still using v1.22. | ||
# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=672218 | ||
kill -HUP $(cat /var/run/rsyslogd.pid) | ||
fi | ||
endscript | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sonic-sairedis
updated
from b86591 to 7e70b4
Submodule sonic-swss
updated
from 27c49a to ab31a9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if 1M would be better, resulting less log files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it would result in less log files total. However, I was trying to find a balance between reasonable log file size and supporting as small a partition as possible, while also maximizing the used space of smaller partitions.
Increasing the file size to 1M will increase the minimum /var/log partition size to ~32MB, but will require that we maintain ~20MB free space to ensure we always keep at least one archived copy of each log and have enough free space to potentially fill all logs before the next rotation (vs. a minimum partition size of ~18MB maintaining ~12MB free space with 512k files). If you don't see a problem with this, I will make the change and test it ASAP.