I need to process large (~ 100) syslog messages using Perl and Linux :: Inotify2 .
I wrote a test script that continuously generates log messages. For event handling, my Perl script looks like this:
#!/usr/bin/perl use Linux::Inotify2 ; use Time::HiRes qw(usleep nanosleep); # create a new object my $inotify = new Linux::Inotify2 or die "Unable to create new inotify object: $!" ; # create watch $inotify->watch ("/var/log/messages", IN_ACCESS|IN_OPEN|IN_CLOSE|IN_MODIFY|IN_Q_OVERFLOW) or die "watch creation failed" ; my $count=0; while () { my @events = $inotify->read; unless (@events > 0) { print "read error: $!"; last ; } #printf "mask\t%d\n", $_->mask foreach @events ; $count++; print $count."\n"; usleep(100000); }
If I do not comment on the usleep function to simulate processing, I notice that when I stop the script log generator, the inotify script does not catch up with it. In other words, the inotify Perl script loses events.
I also do not see overflow messages.
How to make sure that even if my processing is slow, I do not lose the message. In other words, how to define a โbufferโ where messages can be temporarily stored?
source share