-
Notifications
You must be signed in to change notification settings - Fork 197
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
oldlog #65
Comments
I understand your idea. |
The problem is currently the whole rationale of log2ram to minimize flash writes is flawed because the hourly copy of logs that have changed in the majority of installs is likely no more beneficial than the actual log writes themselves. The stop function should be the one that writes current to hdd.log Also no-one should be telling anyone they need to modify logrotate configuration as the install.sh should add the olddir /var/log/oldlog directive and that is all that is need as /etc/logrotate.conf is global. It maybe a KISS project and the reality is that currently the whole project is an unnecessary addition as the hourly overwrite of log changes is still intensive. I never really thought until now, but we could be causing more flash wear than we are reducing and stealing memory for log drives for little benefit. Also oldlog should be transferred as by looking at https://github.com/armbian/build/blob/master/packages/bsp/common/usr/lib/armbian/armbian-ramlog and the RecreateLogs routine it looks like L2R will cause problems with some programs if the original log structure is not there on start. I wish they had maybe fed back a little but hey ho. |
The olddir directive is a single line at the top of /etc/logrotate.conf and because its there its global unless specific noolddir directives are given. The limitations of olddir is that it must be on the same device as logrotate only makes swift and efficient file allocation table changes and will no bulk file copies due to the I/O and load that will make. What it does is create a really simple container and separator of live logs and oldlogs that makes pruning a ramlog extremely easy as logrotate will do this for you via the noolddir directive. The hourly syncToDisk routine is a complete curveball to anyone employing L2R as L2R doesn't state anywhere that L2R is only beneficial for high frequency logging applications and the lesser your logging requirements the nearer you get to low qty log line inclusions being swapped for hourly large file bulk copies. syncToDisk should only be called by the stop command of the service so that L2R provides the minimum writes to hard media.
I apologise to be so critical as the easy answer is why is it there? It doesn't need to be and it shouldn't be and please remove. The hourly routine should be doing something far more important than creating redundant copies of live logs and that is pruning the critical small space of a memory disk log by moving oldlogs to hdd.log because this action of intense bulk copies across devices only needs to be done once for those logs. The hourly routine of syncToDisk should be changed to pruneOldLog and its a one line comparison.
The only additional parts I have added at my is the conversion of remaining size with suffix to bytes so that comparison is an easy one liner.
As the retention of old logs in live log memory is as wasteful and pointless as the writes of live logs to the redundant log hard media. I made one dumb boob as thought for some reason rm -rf $RAM_LOG/oldlog/ the default action would be to keep the root directory and forgot to check prob a rm -rf $RAM_LOG/oldlog/* should of been used doh! AlternativesEither that or create some form of cat to diff or cmp routine to just append to hhd.log but the problem with hourly schedules irrespective of what you do on a system crash the most critical log information close to crash is always lost and having the hours previous is of little gain for just negative effects on the main purpose of L2R. |
I agree with the idea of not holding the rotated files in RAM and have made changes to use olddir. Actually you can use the olddir to move the logs to a different partition if you use the Please ignore the changes to the log folder naming. I just preferred to find all my log files using something like As you can see I opted for a simple additional file to be dropped into logrotate.d so there is no editing required. The I also added a simple symlink so that all the rotated logs can be found in /var/log/rotated_logs too, hopefully even the users unfamiliar with log2ram should still be able to find the rotated logs without knowing about it's inner workings. I've also updated the installer and uninstaller to suit. Whilst I have configured Pi's to run (Raspbian) RO for years now, I'm fairly new to using log2ram so I cannot tell you how this works over time or with heavier traffic, but I have had it running for a while on a test RPi and it seems to work well. |
renamecopy setting ? olddir is just a logrotate directive that is set globally in /etc/logrotate.conf via sed. I can not find a renamecopy setting is that just a post-rotate script? Logrotate will do all the oldlog movement but as far as I know its limited to the same device so its making quick fat (file allocation table) edits and not bulk moves. The olddir directive just makes an easy container for oldlogs and should be only moved out on on low available log space. If you check https://github.com/StuartIanNaylor/zramdrive its a minimal and tidied log2ram for any directory as the whole action of writing out logs to another partition every hour is totally pointless as at any point you have up to an hours missing logs. Also using the reload function of systemd seems to periodically get triggered on boot and at times not by the cron job. Not sure why but check syslog and you will see it happening. https://github.com/StuartIanNaylor/log2zram |
This issue started out about not holding the rotated logs in RAM and using olddir to rotate them out, that is the discussion I was aiming my comments at.
olddir is indeed a logrotate directive and it CAN be set in /etc/logrotate.conf or as I have demonstrated, it can be set in a logrotate.d file too, this is how logrotate works! The use of sed is irrelevant to the discussion, it is one of many ways that a text file can be edited and has nothing directly to do with logrotate or log2ram.
https://manpages.debian.org/testing/logrotate/logrotate.8.en.html renamecopy
Not when you use
and gave you the code.
You are right it is easy, but I disagree with "only on low space", it's just as easy to read logfiles from disc as tmpfs IF you need to read the rotated logs at all. disc space is cheap, ram is less so, especially on older/smaller dev boards. I hope that clears up any confusion for you and gets the discussion back to potentially using olddir and rotating the logs out of ram in log2ram. My comments were more aimed at hopefully convincing @azlux to reconsider this option as it is not as complex as you first suggested, so it keeps in line with the KISS objectives whilst reducing the RAM occupied by the logs managed by log2ram. |
renamecopy must be a debian thing as doesn't seem to exist in https://linux.die.net/man/8/logrotate Not sure how it works though as some such as apache have postrotate scripts that would override? The global one? |
I think that is a documentation issue perhaps! It's been in the main source since Feb 2015 https://github.com/logrotate/logrotate/blob/master/ChangeLog.md#389---2015-02-13 Is it included in the output of I do not think https://www.die.net/ is the defining place to look for such things. Many online man pages are out of date or for specific distro's, you should always use the man pages installed to your system (sometimes as a separate package). the renamecopy entry in the man page source code https://github.com/logrotate/logrotate/blob/3.15.0/logrotate.8.in#L528-L534 The rotated logs will end up on disc sooner or later and by grouping them altogether and doing the lot in one move could actually write to fewer blocks than you think. We do not need to try and eradicate disk wear, just lower it enough so that the sdcards do not wear prematurely, no one expects an sdcard to last forever, but even with moderate writes an sdcard can last a significant time these days. Log2ram just needs to buffer and bulk write to make a serious impact on disk wear, to reduce it further gets more complex and has less gain per effort than the initial simple buffering. I see no reason why apache2 will override the olddir and renamecopy directives, but I haven't specifically tested it nor do I claim to be an expert. But I did research this for my own needs to get the rotated files out of ram. |
The question marks where questions on the info you provided that I wasn't aware of, not statements
The info is slightly confusing as to why the postrotate script is mentioned and where the directive should be placed as have never seen an example. Also reading through fBcreateolddir should be added also as its that would seem simpler and tidier than mkdir in scripts |
https://github.com/StuartIanNaylor/zram-config implemented renamecopy |
Same physical device. I wonder why ? |
I see a reason It will not work. Some software don't use logrotate but have it own rotation implemented. |
Possibly because
Indeed it may not fully work with some edge cases, but even those that currently self-rotate also get rotated by logrotates global settings unless an exclusion is added to logrotates conf. There will always be exceptions and edge cases but this method catches almost all as it's the more common practice for logrotations to be left to logrotate, and when this isn't the case, global rotations tend to not break anything despite some softwares self-rotating. The worse case scenario is that those specific self-rotated logs are not relocated on disk, but that still results on a significantly reduced size in RAM and also significantly reduced load time/effort at boot as well as potentially reduced save time/effort hourly and at shutdown.
Just install as per the software's guide or installer without concerning yourself with log2ram, it is totally transparent. The current position of retaining newly created logs providing the machine isn't stopped ungracefully before the next hourly log2ram runs is retained, users can manually run a log2ram as part of a install regime if they want to be sure the logfiles are definitely going to be there on the next reboot. (but that is standard with log2ran, not related to this olddir directive) All this change does is keeps the rotated logs (created by logrotate) out of RAM, the operation of the original logs are unaffected and any additional logrotate config files added by a software's package installer should be honoured, only the location of the rotated files is altered. |
Same physical device is default speed as files are not copied across devices as all that is needed is FAT changes on the same device. Also its only a 3 line insert in /etc/logrotate that is choice on start or install.
It would mean at least 50% space and likely much more. |
IMO that is a rather messy way of doing it. A file added to [edit] Plus if you wanted to make the install even neater you might consider having the eg
|
Guess so as that would prob override any existing and saves you having to molest /etc/logrotate.conf [edit] |
Because if another discussion about log2ram, I think I will reconsider this issue. |
Just a quick comment that may help someone in an edge use case like mine. Background: Because of the naming convention and other reasons, I didn't want to use logrotate, instead moving the logs to a different server every week using a script. Observation: My Work Around: After reboot, the logs are no longer restored back into /var/log/central/. |
log2ram keeps current logs in memory but also keeps old logs from logrotate and vastly increase mem usage via what are essentially old non current logs not in use and already copied to /var/hdd.log
logrotate has an oldlog directive that unfortunately can not be used with different devices.
There is a workaround though as postrotate can call scripts to mv the contents of /oldlog elsewhere
So use the oldlog directive with /var/log/oldlog
postrotate scripts could be used but log2ram has an hourly routine that could equally move old logs form /var/log/oldlog to /var/hdd.log
I am sat here awaiting my next hourly hoping a global oldlog directive in /etc/logrotate.conf will move all old logs to /var/log/oldlogs
via a simple olddir /var/log/oldlog inclusion to /etc/logrotate.conf
My optimism that it maybe that simple is likely just that and expecting it will not capture logs in /etc/logrotate.d
But its an example that really something should and that the oldlog directive can be used as a staging directory for log pruning and moving to /log/hdd.log and not just copying.
The text was updated successfully, but these errors were encountered: