In the next step, I wanted to go ahead an add a bucketing script. Basically, if I hand it a log, a time to start and a time interval, it will put events into time intervals.
For example, if I want to put events into 5 minute buckets:
fortalt bucket log test.bucket "/test" 1697736400 600
This would say to pull from log
, write results to test.bucket
, the events on /test
starting from 19. October 2023 at 17:26:00 UTC, and proceeding every 5 minutes thereafter.
So I have this log:
/test|1697736412
/test|1697736419
/test|1697736420
/test|1697736422
/foobar|1697736427
/foobar|1697736428
/test|1697736432
/test|1697807418
and this is the test.bucket
output:
1697736412|5
1697807212|1
1697736400|5
1697807200|1
You can imagine how this could be used: a cronscript or daemon that can continually aggregate events from a given line:
line_count=$(wc -l | cut -d' ' -f1)
curr_pointer=$1
mkfifo fortalt.pipe
tail -n $((line_count-curr_pointer)) log > fortalt.pipe &
fortalt bucket log fortalt.pipe "/test" first 600 # didn't implement saying "first" as the time ... something to add ...
echo $((line_count+1)) # for updating $curr_pointer
This would probably need to use flock(1)
to put an exclusive lock on this script so that the current line outputs correctly.
As this starts to come together, these have been the ideas that have been floating in my mind:
grep
and the O() of sort
at the moment)time between (A,B) && path is '/test'
)Made with Bootstrap and my site generator script.