Skip to content
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]: Dynamically calculate file rotation thresholds based on /var/log/ partition size #851

Closed
wants to merge 11 commits into from

Conversation

jleveque
Copy link
Contributor

@jleveque jleveque commented Jul 28, 2017

  • Dynamically calculate file rotation thresholds based on /var/log/ partition size using new logrotate-config service
  • Force log rotation at size thresholds only (no longer also rotating logs daily), allowing for more consistent usage of /var/log partition space
  • Eliminate remaining duplicate log messages
    • Cron facility now only logs to cron.log (was also logging to syslog)
    • Debug, mail, news and user log facilities only log to syslog; no longer creating separate log files for these facilities
  • Cron job that calls logrotate every minute now uses the main /etc/logrotate.conf file so as to check/rotate all logs every minute, not just the logs specified in the rsyslog file. Also redirecting output of this command to /dev/null to prevent "(CRON) info (No MTA installed, discarding output)" messages in cron.log due to lack of a mail service

VAR_LOG_SIZE_KB=$(df /var/log | sed -n 2p | awk '{print $2}')
USABLE_SPACE_KB=$((VAR_LOG_SIZE_KB - RESERVED_SPACE_KB))

SIZE_LIMIT_SYSLOG_FILES_KB=$((USABLE_SPACE_KB / (NUM_LOG_FILES_SYSLOG * (NUM_ARCHIVES_PER_LOG_FILE + 1)) / 100 * PERCENT_ALLOCATED_SYSLOG))
Copy link
Contributor

@taoyl-ms taoyl-ms Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think / in bash is integer division. Shall we move * to the left of /100 to minimize truncation error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I reordered the operations to not only reduce the truncation, but also to make the operations more understandable.

ADDITIONAL_DATA_JSON+="\"size_limit_syslog_kb\":$SIZE_LIMIT_SYSLOG_FILES_KB,"
ADDITIONAL_DATA_JSON+="\"size_limit_quagga_teamd_kb\":$SIZE_LIMIT_QUAGGA_TEAMD_FILES_KB,"
ADDITIONAL_DATA_JSON+="\"size_limit_swss_kb\":$SIZE_LIMIT_SWSS_FILES_KB"
ADDITIONAL_DATA_JSON+="}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a lot of variables, another way is to save data into a json file and load in sonic-cfggen with -j. Not a big difference with -a, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. I think this solution is fine for the three variables. If it grows more, I'll keep that idea in mind.

@taoyl-ms
Copy link
Contributor

:shipit:

daily
maxsize 50M
rotate 1
size 10k
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10k [](start = 9, length = 3)

is 10k a good value for auth.log?


SIZE_LIMIT_SYSLOG_FILES_KB=$(((USABLE_SPACE_KB * PERCENT_ALLOCATED_SYSLOG / 100) / (NUM_LOG_FILES_SYSLOG * (NUM_ARCHIVES_PER_LOG_FILE + 1))))
SIZE_LIMIT_QUAGGA_TEAMD_FILES_KB=$(((USABLE_SPACE_KB * PERCENT_ALLOCATED_QUAGGA_TEAMD / 100) / (NUM_LOG_FILES_QUAGGA_TEAMD * (NUM_ARCHIVES_PER_LOG_FILE + 1))))
SIZE_LIMIT_SWSS_FILES_KB=$(((USABLE_SPACE_KB * PERCENT_ALLOCATED_SWSS / 100) / (NUM_LOG_FILES_SWSS * (NUM_ARCHIVES_PER_LOG_FILE + 1))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the actual sizes when the log partition size is 100M?

for example syslog log size limit is 102400 * 75 / 100 / (1 * ( 7 + 1) = 9600KB.
swss size limit is 10240010/100/(2(7+1)) = 640KB

since, the gzipped archive is much smaller than the actual log size. we might end up with not fully utilizing the /var/log partition.

Ideally, if we can rotate based on the free disk size, we can utilize the /var/log partition. however, we need to modify logrotate for that.

there are some discussion in here. https://serverfault.com/questions/372809/free-space-driven-log-rotation-on-linux

@jleveque
Copy link
Contributor Author

jleveque commented Aug 4, 2017

Abandoning in favor of #865

@jleveque jleveque closed this Aug 4, 2017
@jleveque jleveque deleted the improve_syslog branch August 10, 2017 23:26
pjaipakdee19 pushed a commit to pjaipakdee19/sonic-buildimage that referenced this pull request Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants