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.\" 27a1e0a00fSRuslan Ermilov.Dd February 9, 2008 28a1e0a00fSRuslan Ermilov.Os 29662cb04cSPoul-Henning Kamp.Dt FIFOLOG 1 30662cb04cSPoul-Henning Kamp.Sh NAME 31c022d15eSRuslan Ermilov.Nm fifolog_create , fifolog_writer , fifolog_reader 32a1e0a00fSRuslan Ermilov.Nd "initialize, write, seek and extract data from a fifolog" 33662cb04cSPoul-Henning Kamp.Sh SYNOPSIS 34662cb04cSPoul-Henning Kamp.Nm fifolog_create 35662cb04cSPoul-Henning Kamp.Op Fl l Ar record-size 36662cb04cSPoul-Henning Kamp.Op Fl r Ar record-count 37662cb04cSPoul-Henning Kamp.Op Fl s Ar size 38662cb04cSPoul-Henning Kamp.Ar file 39662cb04cSPoul-Henning Kamp.Nm fifolog_reader 40662cb04cSPoul-Henning Kamp.Op Fl t 41662cb04cSPoul-Henning Kamp.Op Fl b Ar tstart 42662cb04cSPoul-Henning Kamp.Op Fl B Ar Tstart 43662cb04cSPoul-Henning Kamp.Op Fl e Ar tend 44662cb04cSPoul-Henning Kamp.Op Fl E Ar Tend 45662cb04cSPoul-Henning Kamp.Op Fl o Ar ofile 46662cb04cSPoul-Henning Kamp.Op Fl R Ar regexp 47662cb04cSPoul-Henning Kamp.Op Fl T Ar timefmt 48662cb04cSPoul-Henning Kamp.Ar file 49662cb04cSPoul-Henning Kamp.Nm fifolog_writer 50662cb04cSPoul-Henning Kamp.Op Fl w Ar write-rate 51662cb04cSPoul-Henning Kamp.Op Fl s Ar sync-rate 52662cb04cSPoul-Henning Kamp.Op Fl z Ar compression 53662cb04cSPoul-Henning Kamp.Ar file 54662cb04cSPoul-Henning Kamp.Sh DESCRIPTION 55662cb04cSPoul-Henning KampFifologs provide a compact round-robin circular storage for 56662cb04cSPoul-Henning Kamprecording text and binary information to permanent storage in a bounded 57662cb04cSPoul-Henning Kampand predictable fashion, time and space wise. 58662cb04cSPoul-Henning Kamp.Pp 59662cb04cSPoul-Henning KampA fifolog can be stored either directly on a disk partition or in a 60662cb04cSPoul-Henning Kampregular file. 61662cb04cSPoul-Henning Kamp.Pp 62662cb04cSPoul-Henning KampThe input data stream is encoded, compressed and marked up with 63662cb04cSPoul-Henning Kamptimestamps before it is written to storage, such that it is possible 64662cb04cSPoul-Henning Kampto seek out a particular time interval in the stored data, without 65662cb04cSPoul-Henning Kamphaving to decompress the entire logfile. 66662cb04cSPoul-Henning Kamp.Pp 67a1e0a00fSRuslan ErmilovThe 68a1e0a00fSRuslan Ermilov.Nm fifolog_create 69a1e0a00fSRuslan Ermilovutility 70662cb04cSPoul-Henning Kampis used to initialize the first sector of a disk device 71662cb04cSPoul-Henning Kampor file system file to make it a fifolog and should be called only 72662cb04cSPoul-Henning Kamponce. 73662cb04cSPoul-Henning Kamp.Pp 74662cb04cSPoul-Henning KampRunning 75a1e0a00fSRuslan Ermilov.Nm fifolog_create 76662cb04cSPoul-Henning Kampon an existing fifolog will reset it so that 77662cb04cSPoul-Henning Kamp.Nm fifolog_reader 78662cb04cSPoul-Henning Kampand 79662cb04cSPoul-Henning Kamp.Nm fifolog_writer 80662cb04cSPoul-Henning Kampwill not see the previous contents. 81a1e0a00fSRuslan Ermilov(The previous contents are not physically erased, and with a bit 82a1e0a00fSRuslan Ermilovof hand-work all but the first record can be easily recovered.) 83662cb04cSPoul-Henning Kamp.Pp 84a1e0a00fSRuslan ErmilovIf the 85a1e0a00fSRuslan Ermilov.Ar file 86a1e0a00fSRuslan Ermilovdoes not already exist, 87c022d15eSRuslan Ermilov.Nm fifolog_create 88662cb04cSPoul-Henning Kampwill attempt to create and 89a1e0a00fSRuslan Ermilov.Xr ftruncate 2 90662cb04cSPoul-Henning Kampit to the specified size, defaulting to 86400 records of 512 bytes 91662cb04cSPoul-Henning Kampif the 92a1e0a00fSRuslan Ermilov.Fl r , l 93662cb04cSPoul-Henning Kampor 94662cb04cSPoul-Henning Kamp.Fl s 95a1e0a00fSRuslan Ermilovoptions do not specify otherwise. 96662cb04cSPoul-Henning Kamp.Pp 97a1e0a00fSRuslan ErmilovThe 98a1e0a00fSRuslan Ermilov.Nm fifolog_writer 99a1e0a00fSRuslan Ermilovutility 100662cb04cSPoul-Henning Kampwill read standard input and write it to the end of the fifolog 101662cb04cSPoul-Henning Kampaccording to the parameters given. 102662cb04cSPoul-Henning Kamp.Pp 103662cb04cSPoul-Henning KampWrites happen whenever the output buffer is filled with compressed 104662cb04cSPoul-Henning Kampdata or when either of two timers expire, forcing a partially filled 105662cb04cSPoul-Henning Kampbuffer to be written. 106662cb04cSPoul-Henning Kamp.Pp 107662cb04cSPoul-Henning KampThe first and faster timer, 108a1e0a00fSRuslan Ermilov.Fl w Ar write-rate , 109662cb04cSPoul-Henning Kampforces available data to be written 110662cb04cSPoul-Henning Kampbut does not flush and reset the compression dictionary. 111662cb04cSPoul-Henning KampThis timer is intended to minimize the amount of logdata lost in RAM 112662cb04cSPoul-Henning Kampin case of a crash and by default it fires 10 seconds after 113662cb04cSPoul-Henning Kampthe previous write. 114662cb04cSPoul-Henning Kamp.Pp 115662cb04cSPoul-Henning KampThe second and slower timer, 116a1e0a00fSRuslan Ermilov.Fl s Ar sync-rate , 117662cb04cSPoul-Henning Kampforces a full flush and reset of the compression 118662cb04cSPoul-Henning Kampengine and causes the next record written to be a synchronization 119662cb04cSPoul-Henning Kamppoint with an uncompressed timestamp, making it possible to start 120662cb04cSPoul-Henning Kampreading the logfile from that record. 121662cb04cSPoul-Henning KampBy default this timer fires a minute after the previous sync. 122662cb04cSPoul-Henning Kamp.Pp 123662cb04cSPoul-Henning KampThe 124a1e0a00fSRuslan Ermilov.Fl z Ar compression 125a1e0a00fSRuslan Ermilovoption controls the 126662cb04cSPoul-Henning Kamp.Xr zlib 3 127a1e0a00fSRuslan Ermilovcompression level; legal values are zero to nine which is the default. 128662cb04cSPoul-Henning Kamp.Pp 129a1e0a00fSRuslan ErmilovThe 130a1e0a00fSRuslan Ermilov.Nm fifolog_reader 131a1e0a00fSRuslan Ermilovutility 132662cb04cSPoul-Henning Kampwill retrieve records from the fifolog according to the specified 133a1e0a00fSRuslan Ermilovparameters and write them either to standard output or the file specified 134662cb04cSPoul-Henning Kampwith 135662cb04cSPoul-Henning Kamp.Fl o . 136662cb04cSPoul-Henning Kamp.Pp 137662cb04cSPoul-Henning KampIt is possible to specify a start and end time to limit the amount 138662cb04cSPoul-Henning Kampof data 139662cb04cSPoul-Henning Kamp.Nm fifolog_reader 140662cb04cSPoul-Henning Kampwill report. 141662cb04cSPoul-Henning KampThe lower-case variants 142662cb04cSPoul-Henning Kamp.Fl b 143662cb04cSPoul-Henning Kampand 144662cb04cSPoul-Henning Kamp.Fl e 145662cb04cSPoul-Henning Kamptake a 146a1e0a00fSRuslan Ermilov.Vt time_t 147662cb04cSPoul-Henning Kampvalue, whereas the upper-case variants 148662cb04cSPoul-Henning Kamp.Fl B 149662cb04cSPoul-Henning Kampand 150662cb04cSPoul-Henning Kamp.Fl E 151a1e0a00fSRuslan Ermilovtake human-readable specifications such as 152a1e0a00fSRuslan Ermilov.Dq Li "1 hour ago" . 153662cb04cSPoul-Henning Kamp.Pp 154662cb04cSPoul-Henning KampThe 155662cb04cSPoul-Henning Kamp.Fl t 156a1e0a00fSRuslan Ermilovoption forces timestamps to be formatted as 157a1e0a00fSRuslan Ermilov.Dq Li "YYYYMMDDhhmmss" 158a1e0a00fSRuslan Ermilovinstead of as 159a1e0a00fSRuslan Ermilov.Vt time_t , 160a1e0a00fSRuslan Ermilovand 161662cb04cSPoul-Henning Kamp.Fl T 162a1e0a00fSRuslan Ermilovallows the specification of an 163662cb04cSPoul-Henning Kamp.Xr strftime 3 164662cb04cSPoul-Henning Kampformatting string. 165662cb04cSPoul-Henning Kamp.Pp 166662cb04cSPoul-Henning KampFinally, records can be filtered such that only records matching the 167a1e0a00fSRuslan Ermilov.Pq Dv REG_BASIC 168a1e0a00fSRuslan Ermilovregular expression specified with 169662cb04cSPoul-Henning Kamp.Fl R 170a1e0a00fSRuslan Ermilovare output. 171662cb04cSPoul-Henning Kamp.Sh IMPLEMENTATION NOTES 172a1e0a00fSRuslan ErmilovThe data stored in the fifolog consists of three layers, an outer 173662cb04cSPoul-Henning Kamplayer that allows searches to synchronization points based on timestamps 174662cb04cSPoul-Henning Kampwithout having to decompress and decode the actual contents, a 175662cb04cSPoul-Henning Kampcompression layer implemented with 176a1e0a00fSRuslan Ermilov.Xr zlib 3 , 177662cb04cSPoul-Henning Kampand an inner serialization and timestamping layer. 178662cb04cSPoul-Henning Kamp.Pp 179a1e0a00fSRuslan ErmilovThe exact encoding is described in the 180a1e0a00fSRuslan Ermilov.Pa fifolog.h 181a1e0a00fSRuslan Ermilovfile. 182662cb04cSPoul-Henning Kamp.Pp 183662cb04cSPoul-Henning KampFifolog is particularly well suited for use on Flash based media, where 184662cb04cSPoul-Henning Kampit results in much lower write-wear, than a file system with regular 185662cb04cSPoul-Henning Kamplog files rotated with 186662cb04cSPoul-Henning Kamp.Xr newsyslog 8 187662cb04cSPoul-Henning Kampetc. 188662cb04cSPoul-Henning Kamp.Sh EXAMPLES 189662cb04cSPoul-Henning KampCreate a fifolog with 1024*1024 records of 512 bytes: 190a1e0a00fSRuslan Ermilov.Pp 191a1e0a00fSRuslan Ermilov.Dl "fifolog_create -r 10m /tmp/fifolog" 192662cb04cSPoul-Henning Kamp.Pp 193662cb04cSPoul-Henning KampWrite a single record to this file: 194a1e0a00fSRuslan Ermilov.Pp 195a1e0a00fSRuslan Ermilov.Dl "date | fifolog_writer /tmp/fifolog" 196662cb04cSPoul-Henning Kamp.Pp 197662cb04cSPoul-Henning KampRead it back with human readable timestamps: 198a1e0a00fSRuslan Ermilov.Pp 199a1e0a00fSRuslan Ermilov.Dl "fifolog_reader -t /tmp/fifolog" 200662cb04cSPoul-Henning Kamp.Pp 201662cb04cSPoul-Henning KampOne particular useful use of 202662cb04cSPoul-Henning Kamp.Nm fifolog_writer 203662cb04cSPoul-Henning Kampis with 204662cb04cSPoul-Henning Kamp.Xr syslogd 8 205662cb04cSPoul-Henning Kampusing a line such as this in 206662cb04cSPoul-Henning Kamp.Xr /etc/syslog.conf 5 : 207a1e0a00fSRuslan Ermilov.Pp 208a1e0a00fSRuslan Ermilov.Dl "*.* |fifolog_writer /var/log/syslog_fifolog" 209662cb04cSPoul-Henning Kamp.Sh HISTORY 210a1e0a00fSRuslan ErmilovThe fifolog tools have been liberated from an open source 211a1e0a00fSRuslan Ermilov.Tn SCADA 212a1e0a00fSRuslan Ermilovapplications called 213a1e0a00fSRuslan Ermilov.Dq measured , 214a1e0a00fSRuslan Ermilovwhich monitors and controls remote radio navigation 215662cb04cSPoul-Henning Kamptransmitters for the Danish Air Traffic Control system. 216662cb04cSPoul-Henning Kamp.Sh AUTHORS 217a1e0a00fSRuslan ErmilovThe fifolog tools were written by 218a1e0a00fSRuslan Ermilov.An Poul-Henning Kamp . 219