Skip to content

[System logs]: Dynamically calculate file rotation thresholds based on /var/log/ partition size#851

Closed
jleveque wants to merge 11 commits intosonic-net:masterfrom
jleveque:improve_syslog
Closed

[System logs]: Dynamically calculate file rotation thresholds based on /var/log/ partition size#851
jleveque wants to merge 11 commits intosonic-net:masterfrom
jleveque:improve_syslog

Conversation

@jleveque
Copy link
Copy Markdown
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

Copy link
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

:shipit:

daily
maxsize 50M
rotate 1
size 10k
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
dgsudharsan pushed a commit to dgsudharsan/sonic-buildimage that referenced this pull request Mar 17, 2025
…lly (sonic-net#851)

#### Why I did it
src/sonic-swss
```
* bb317bb - (HEAD -> 202412, origin/202412) [code sync] Merge code from sonic-net/sonic-swss:202411 to 202412 (#57) (21 hours ago) [mssonicbld]
```
#### How I did it
#### How to verify it
#### Description for the changelog
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