1662cb04cSPoul-Henning Kamp.\" Copyright (c) 2008 Poul-Henning Kamp 2662cb04cSPoul-Henning Kamp.\" All rights reserved. 3662cb04cSPoul-Henning Kamp.\" 4662cb04cSPoul-Henning Kamp.\" Redistribution and use in source and binary forms, with or without 5662cb04cSPoul-Henning Kamp.\" modification, are permitted provided that the following conditions 6662cb04cSPoul-Henning Kamp.\" are met: 7662cb04cSPoul-Henning Kamp.\" 1. Redistributions of source code must retain the above copyright 8662cb04cSPoul-Henning Kamp.\" notice, this list of conditions and the following disclaimer. 9662cb04cSPoul-Henning Kamp.\" 2. Redistributions in binary form must reproduce the above copyright 10662cb04cSPoul-Henning Kamp.\" notice, this list of conditions and the following disclaimer in the 11662cb04cSPoul-Henning Kamp.\" documentation and/or other materials provided with the distribution. 12662cb04cSPoul-Henning Kamp.\" 13662cb04cSPoul-Henning Kamp.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14662cb04cSPoul-Henning Kamp.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15662cb04cSPoul-Henning Kamp.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16662cb04cSPoul-Henning Kamp.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17662cb04cSPoul-Henning Kamp.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18662cb04cSPoul-Henning Kamp.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19662cb04cSPoul-Henning Kamp.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20662cb04cSPoul-Henning Kamp.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21662cb04cSPoul-Henning Kamp.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22662cb04cSPoul-Henning Kamp.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23662cb04cSPoul-Henning Kamp.\" SUCH DAMAGE. 24662cb04cSPoul-Henning Kamp.\" 25662cb04cSPoul-Henning Kamp.\" $FreeBSD$ 26662cb04cSPoul-Henning Kamp.\" 27662cb04cSPoul-Henning Kamp.Dd Feb 9, 2008 28662cb04cSPoul-Henning Kamp.Os FreeBSD 8.0 29662cb04cSPoul-Henning Kamp.Dt FIFOLOG 1 30662cb04cSPoul-Henning Kamp.Sh NAME 31662cb04cSPoul-Henning Kamp.Nm fifolog_create 32662cb04cSPoul-Henning Kamp.Nd Initialize storage for fifolog 33662cb04cSPoul-Henning Kamp.br 34662cb04cSPoul-Henning Kamp.Nm fifolog_write 35662cb04cSPoul-Henning Kamp.Nd Write data to fifolog 36662cb04cSPoul-Henning Kamp.br 37662cb04cSPoul-Henning Kamp.Nm fifolog_read 38662cb04cSPoul-Henning Kamp.Nd Seek and extract data from fifolog 39662cb04cSPoul-Henning Kamp.Sh SYNOPSIS 40662cb04cSPoul-Henning Kamp.Nm fifolog_create 41662cb04cSPoul-Henning Kamp.Op Fl l Ar record-size 42662cb04cSPoul-Henning Kamp.Op Fl r Ar record-count 43662cb04cSPoul-Henning Kamp.Op Fl s Ar size 44662cb04cSPoul-Henning Kamp.Ar file 45662cb04cSPoul-Henning Kamp.Nm fifolog_reader 46662cb04cSPoul-Henning Kamp.Op Fl t 47662cb04cSPoul-Henning Kamp.Op Fl b Ar tstart 48662cb04cSPoul-Henning Kamp.Op Fl B Ar Tstart 49662cb04cSPoul-Henning Kamp.Op Fl e Ar tend 50662cb04cSPoul-Henning Kamp.Op Fl E Ar Tend 51662cb04cSPoul-Henning Kamp.Op Fl o Ar ofile 52662cb04cSPoul-Henning Kamp.Op Fl R Ar regexp 53662cb04cSPoul-Henning Kamp.Op Fl T Ar timefmt 54662cb04cSPoul-Henning Kamp.Ar file 55662cb04cSPoul-Henning Kamp.Nm fifolog_writer 56662cb04cSPoul-Henning Kamp.Op Fl w Ar write-rate 57662cb04cSPoul-Henning Kamp.Op Fl s Ar sync-rate 58662cb04cSPoul-Henning Kamp.Op Fl z Ar compression 59662cb04cSPoul-Henning Kamp.Ar file 60662cb04cSPoul-Henning Kamp.Sh DESCRIPTION 61662cb04cSPoul-Henning KampFifologs provide a compact round-robin circular storage for 62662cb04cSPoul-Henning Kamprecording text and binary information to permanent storage in a bounded 63662cb04cSPoul-Henning Kampand predictable fashion, time and space wise. 64662cb04cSPoul-Henning Kamp.Pp 65662cb04cSPoul-Henning KampA fifolog can be stored either directly on a disk partition or in a 66662cb04cSPoul-Henning Kampregular file. 67662cb04cSPoul-Henning Kamp.Pp 68662cb04cSPoul-Henning KampThe input data stream is encoded, compressed and marked up with 69662cb04cSPoul-Henning Kamptimestamps before it is written to storage, such that it is possible 70662cb04cSPoul-Henning Kampto seek out a particular time interval in the stored data, without 71662cb04cSPoul-Henning Kamphaving to decompress the entire logfile. 72662cb04cSPoul-Henning Kamp.Pp 73662cb04cSPoul-Henning Kamp.Nm Fifolog_create 74662cb04cSPoul-Henning Kampis used to initialize the first sector of a disk device 75662cb04cSPoul-Henning Kampor filesystem file to make it a fifolog and should be called only 76662cb04cSPoul-Henning Kamponce. 77662cb04cSPoul-Henning Kamp.Pp 78662cb04cSPoul-Henning KampRunning 79662cb04cSPoul-Henning Kamp.Nm 80662cb04cSPoul-Henning Kampon an existing fifolog will reset it so that 81662cb04cSPoul-Henning Kamp.Nm fifolog_reader 82662cb04cSPoul-Henning Kampand 83662cb04cSPoul-Henning Kamp.Nm fifolog_writer 84662cb04cSPoul-Henning Kampwill not see the previous contents. 85662cb04cSPoul-Henning Kamp(The previos contents is not physically erased, and with a bit 86662cb04cSPoul-Henning Kampof hand-work, all but the first record can be easily recovered). 87662cb04cSPoul-Henning Kamp.Pp 88662cb04cSPoul-Henning KampIf the file does not already exist 89662cb04cSPoul-Henning Kamp.Nm 90662cb04cSPoul-Henning Kampwill attempt to create and 91662cb04cSPoul-Henning Kamp.Xr ftruncate 3 92662cb04cSPoul-Henning Kampit to the specified size, defaulting to 86400 records of 512 bytes 93662cb04cSPoul-Henning Kampif the 94662cb04cSPoul-Henning Kamp.Fl r , 95662cb04cSPoul-Henning Kamp.Fl l 96662cb04cSPoul-Henning Kampor 97662cb04cSPoul-Henning Kamp.Fl s 98662cb04cSPoul-Henning Kamparguments do not specify otherwise. 99662cb04cSPoul-Henning Kamp.Pp 100662cb04cSPoul-Henning Kamp.Nm Fifolog_writer 101662cb04cSPoul-Henning Kampwill read standard input and write it to the end of the fifolog 102662cb04cSPoul-Henning Kampaccording to the parameters given. 103662cb04cSPoul-Henning Kamp.Pp 104662cb04cSPoul-Henning KampWrites happen whenever the output buffer is filled with compressed 105662cb04cSPoul-Henning Kampdata or when either of two timers expire, forcing a partially filled 106662cb04cSPoul-Henning Kampbuffer to be written. 107662cb04cSPoul-Henning Kamp.Pp 108662cb04cSPoul-Henning KampThe first and faster timer, 109662cb04cSPoul-Henning Kamp.Fl w write-rate , 110662cb04cSPoul-Henning Kampforces available data to be written 111662cb04cSPoul-Henning Kampbut does not flush and reset the compression dictionary. 112662cb04cSPoul-Henning KampThis timer is intended to minimize the amount of logdata lost in RAM 113662cb04cSPoul-Henning Kampin case of a crash and by default it fires 10 seconds after 114662cb04cSPoul-Henning Kampthe previous write. 115662cb04cSPoul-Henning Kamp.Pp 116662cb04cSPoul-Henning KampThe second and slower timer, 117662cb04cSPoul-Henning Kamp.Fl s sync-rate , 118662cb04cSPoul-Henning Kampforces a full flush and reset of the compression 119662cb04cSPoul-Henning Kampengine and causes the next record written to be a synchronization 120662cb04cSPoul-Henning Kamppoint with an uncompressed timestamp, making it possible to start 121662cb04cSPoul-Henning Kampreading the logfile from that record. 122662cb04cSPoul-Henning KampBy default this timer fires a minute after the previous sync. 123662cb04cSPoul-Henning Kamp.Pp 124662cb04cSPoul-Henning KampThe 125662cb04cSPoul-Henning Kamp.Fl z compression 126662cb04cSPoul-Henning Kampargument controls the 127662cb04cSPoul-Henning Kamp.Xr zlib 3 128662cb04cSPoul-Henning Kampcompression level, legal values are zero to nine which is the default. 129662cb04cSPoul-Henning Kamp.Pp 130662cb04cSPoul-Henning Kamp.Nm Fifolog_reader 131662cb04cSPoul-Henning Kampwill retrieve records from the fifolog according to the specified 132662cb04cSPoul-Henning Kampparameters and write them either to stdout or the file specified 133662cb04cSPoul-Henning Kampwith 134662cb04cSPoul-Henning Kamp.Fl o . 135662cb04cSPoul-Henning Kamp.Pp 136662cb04cSPoul-Henning KampIt is possible to specify a start and end time to limit the amount 137662cb04cSPoul-Henning Kampof data 138662cb04cSPoul-Henning Kamp.Nm fifolog_reader 139662cb04cSPoul-Henning Kampwill report. 140662cb04cSPoul-Henning KampThe lower-case variants 141662cb04cSPoul-Henning Kamp.Fl b 142662cb04cSPoul-Henning Kampand 143662cb04cSPoul-Henning Kamp.Fl e 144662cb04cSPoul-Henning Kamptake a 145662cb04cSPoul-Henning Kamp.Xr time_t 146662cb04cSPoul-Henning Kampvalue, whereas the upper-case variants 147662cb04cSPoul-Henning Kamp.Fl B 148662cb04cSPoul-Henning Kampand 149662cb04cSPoul-Henning Kamp.Fl E 150662cb04cSPoul-Henning Kamptake human redable specifications such as "1 hour ago". 151662cb04cSPoul-Henning Kamp.Pp 152662cb04cSPoul-Henning KampThe 153662cb04cSPoul-Henning Kamp.Fl t 154662cb04cSPoul-Henning Kampargument forces timestamps to be formatted as "YYYYMMDDhhmmss" instead 155662cb04cSPoul-Henning Kampof as time_t, and 156662cb04cSPoul-Henning Kamp.Fl T 157662cb04cSPoul-Henning Kampallows the specification of a 158662cb04cSPoul-Henning Kamp.Xr strftime 3 159662cb04cSPoul-Henning Kampformatting string. 160662cb04cSPoul-Henning Kamp.Pp 161662cb04cSPoul-Henning KampFinally, records can be filtered such that only records matching the 162662cb04cSPoul-Henning Kamp(REG_BASIC) regular expression specified with 163662cb04cSPoul-Henning Kamp.Fl R 164662cb04cSPoul-Henning Kampis output. 165662cb04cSPoul-Henning Kamp.Sh IMPLEMENTATION NOTES 166662cb04cSPoul-Henning KampThe data stored in the fifolog consists of three layers, an outher 167662cb04cSPoul-Henning Kamplayer that allows searches to synchronization points based on timestamps 168662cb04cSPoul-Henning Kampwithout having to decompress and decode the actual contents, a 169662cb04cSPoul-Henning Kampcompression layer implemented with 170662cb04cSPoul-Henning Kamp.Xr zlib 3 171662cb04cSPoul-Henning Kampand an inner serialization and timestamping layer. 172662cb04cSPoul-Henning Kamp.Pp 173662cb04cSPoul-Henning KampThe exact encoding is described in the fifolog.h file. 174662cb04cSPoul-Henning Kamp.Pp 175662cb04cSPoul-Henning KampFifolog is particularly well suited for use on Flash based media, where 176662cb04cSPoul-Henning Kampit results in much lower write-wear, than a filesystem with regular 177662cb04cSPoul-Henning Kamplogfiles rotated with 178662cb04cSPoul-Henning Kamp.Xr newsyslog 8 179662cb04cSPoul-Henning Kampetc. 180662cb04cSPoul-Henning Kamp.Sh EXAMPLES 181662cb04cSPoul-Henning KampCreate a fifolog with 1024*1024 records of 512 bytes: 182662cb04cSPoul-Henning Kamp.Bd -literal 183662cb04cSPoul-Henning Kampfifolog_create -r 10m /tmp/fifolog 184662cb04cSPoul-Henning Kamp.Ed 185662cb04cSPoul-Henning Kamp.Pp 186662cb04cSPoul-Henning KampWrite a single record to this file: 187662cb04cSPoul-Henning Kamp.Bd -literal 188662cb04cSPoul-Henning Kampdate | fifolog_writer /tmp/fifolog 189662cb04cSPoul-Henning Kamp.Ed 190662cb04cSPoul-Henning Kamp.Pp 191662cb04cSPoul-Henning KampRead it back with human readable timestamps: 192662cb04cSPoul-Henning Kamp.Bd -literal 193662cb04cSPoul-Henning Kampfifolog_reader -t /tmp/fifolog 194662cb04cSPoul-Henning Kamp.Ed 195662cb04cSPoul-Henning Kamp.Pp 196662cb04cSPoul-Henning KampOne particular useful use of 197662cb04cSPoul-Henning Kamp.Nm fifolog_writer 198662cb04cSPoul-Henning Kampis with 199662cb04cSPoul-Henning Kamp.Xr syslogd 8 200662cb04cSPoul-Henning Kampusing a line such as this in 201662cb04cSPoul-Henning Kamp.Xr /etc/syslog.conf 5 : 202662cb04cSPoul-Henning Kamp.Bd -literal 203662cb04cSPoul-Henning Kamp*.* |fifolog_writer /var/log/syslog_fifolog 204662cb04cSPoul-Henning Kamp.Ed 205662cb04cSPoul-Henning Kamp.Sh HISTORY 206662cb04cSPoul-Henning KampThe fifolog tools have been liberated from an open source SCADA applications 207662cb04cSPoul-Henning Kampcalled "measured", which monitors and controls remote radio navigation 208662cb04cSPoul-Henning Kamptransmitters for the Danish Air Traffic Control system. 209662cb04cSPoul-Henning Kamp.Sh AUTHORS 210662cb04cSPoul-Henning KampThe fifolog tools were written by Poul-Henning Kamp 211