xref: /freebsd/usr.sbin/fifolog/fifolog_create/fifolog.1 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.\"
25a1e0a00fSRuslan Ermilov.Dd February 9, 2008
26662cb04cSPoul-Henning Kamp.Dt FIFOLOG 1
27aa12cea2SUlrich Spörlein.Os
28662cb04cSPoul-Henning Kamp.Sh NAME
29c022d15eSRuslan Ermilov.Nm fifolog_create , fifolog_writer , fifolog_reader
30a1e0a00fSRuslan Ermilov.Nd "initialize, write, seek and extract data from a fifolog"
31662cb04cSPoul-Henning Kamp.Sh SYNOPSIS
32662cb04cSPoul-Henning Kamp.Nm fifolog_create
33662cb04cSPoul-Henning Kamp.Op Fl l Ar record-size
34662cb04cSPoul-Henning Kamp.Op Fl r Ar record-count
35662cb04cSPoul-Henning Kamp.Op Fl s Ar size
36662cb04cSPoul-Henning Kamp.Ar file
37662cb04cSPoul-Henning Kamp.Nm fifolog_reader
38662cb04cSPoul-Henning Kamp.Op Fl t
39662cb04cSPoul-Henning Kamp.Op Fl b Ar tstart
40662cb04cSPoul-Henning Kamp.Op Fl B Ar Tstart
41662cb04cSPoul-Henning Kamp.Op Fl e Ar tend
42662cb04cSPoul-Henning Kamp.Op Fl E Ar Tend
43662cb04cSPoul-Henning Kamp.Op Fl o Ar ofile
44662cb04cSPoul-Henning Kamp.Op Fl R Ar regexp
45662cb04cSPoul-Henning Kamp.Op Fl T Ar timefmt
46662cb04cSPoul-Henning Kamp.Ar file
47662cb04cSPoul-Henning Kamp.Nm fifolog_writer
48662cb04cSPoul-Henning Kamp.Op Fl w Ar write-rate
49662cb04cSPoul-Henning Kamp.Op Fl s Ar sync-rate
50662cb04cSPoul-Henning Kamp.Op Fl z Ar compression
51662cb04cSPoul-Henning Kamp.Ar file
52662cb04cSPoul-Henning Kamp.Sh DESCRIPTION
53662cb04cSPoul-Henning KampFifologs provide a compact round-robin circular storage for
54662cb04cSPoul-Henning Kamprecording text and binary information to permanent storage in a bounded
55662cb04cSPoul-Henning Kampand predictable fashion, time and space wise.
56662cb04cSPoul-Henning Kamp.Pp
57662cb04cSPoul-Henning KampA fifolog can be stored either directly on a disk partition or in a
58662cb04cSPoul-Henning Kampregular file.
59662cb04cSPoul-Henning Kamp.Pp
60662cb04cSPoul-Henning KampThe input data stream is encoded, compressed and marked up with
61662cb04cSPoul-Henning Kamptimestamps before it is written to storage, such that it is possible
62662cb04cSPoul-Henning Kampto seek out a particular time interval in the stored data, without
63662cb04cSPoul-Henning Kamphaving to decompress the entire logfile.
64662cb04cSPoul-Henning Kamp.Pp
65a1e0a00fSRuslan ErmilovThe
66a1e0a00fSRuslan Ermilov.Nm fifolog_create
67a1e0a00fSRuslan Ermilovutility
68662cb04cSPoul-Henning Kampis used to initialize the first sector of a disk device
69662cb04cSPoul-Henning Kampor file system file to make it a fifolog and should be called only
70662cb04cSPoul-Henning Kamponce.
71662cb04cSPoul-Henning Kamp.Pp
72662cb04cSPoul-Henning KampRunning
73a1e0a00fSRuslan Ermilov.Nm fifolog_create
74662cb04cSPoul-Henning Kampon an existing fifolog will reset it so that
75662cb04cSPoul-Henning Kamp.Nm fifolog_reader
76662cb04cSPoul-Henning Kampand
77662cb04cSPoul-Henning Kamp.Nm fifolog_writer
78662cb04cSPoul-Henning Kampwill not see the previous contents.
79a1e0a00fSRuslan Ermilov(The previous contents are not physically erased, and with a bit
80a1e0a00fSRuslan Ermilovof hand-work all but the first record can be easily recovered.)
81662cb04cSPoul-Henning Kamp.Pp
82a1e0a00fSRuslan ErmilovIf the
83a1e0a00fSRuslan Ermilov.Ar file
84a1e0a00fSRuslan Ermilovdoes not already exist,
85c022d15eSRuslan Ermilov.Nm fifolog_create
86662cb04cSPoul-Henning Kampwill attempt to create and
87a1e0a00fSRuslan Ermilov.Xr ftruncate 2
88662cb04cSPoul-Henning Kampit to the specified size, defaulting to 86400 records of 512 bytes
89662cb04cSPoul-Henning Kampif the
90a1e0a00fSRuslan Ermilov.Fl r , l
91662cb04cSPoul-Henning Kampor
92662cb04cSPoul-Henning Kamp.Fl s
93a1e0a00fSRuslan Ermilovoptions do not specify otherwise.
94662cb04cSPoul-Henning Kamp.Pp
95a1e0a00fSRuslan ErmilovThe
96a1e0a00fSRuslan Ermilov.Nm fifolog_writer
97a1e0a00fSRuslan Ermilovutility
98662cb04cSPoul-Henning Kampwill read standard input and write it to the end of the fifolog
99662cb04cSPoul-Henning Kampaccording to the parameters given.
100662cb04cSPoul-Henning Kamp.Pp
101662cb04cSPoul-Henning KampWrites happen whenever the output buffer is filled with compressed
102662cb04cSPoul-Henning Kampdata or when either of two timers expire, forcing a partially filled
103662cb04cSPoul-Henning Kampbuffer to be written.
104662cb04cSPoul-Henning Kamp.Pp
105662cb04cSPoul-Henning KampThe first and faster timer,
106a1e0a00fSRuslan Ermilov.Fl w Ar write-rate ,
107662cb04cSPoul-Henning Kampforces available data to be written
108662cb04cSPoul-Henning Kampbut does not flush and reset the compression dictionary.
109662cb04cSPoul-Henning KampThis timer is intended to minimize the amount of logdata lost in RAM
110662cb04cSPoul-Henning Kampin case of a crash and by default it fires 10 seconds after
111662cb04cSPoul-Henning Kampthe previous write.
112662cb04cSPoul-Henning Kamp.Pp
113662cb04cSPoul-Henning KampThe second and slower timer,
114a1e0a00fSRuslan Ermilov.Fl s Ar sync-rate ,
115662cb04cSPoul-Henning Kampforces a full flush and reset of the compression
116662cb04cSPoul-Henning Kampengine and causes the next record written to be a synchronization
117662cb04cSPoul-Henning Kamppoint with an uncompressed timestamp, making it possible to start
118662cb04cSPoul-Henning Kampreading the logfile from that record.
119662cb04cSPoul-Henning KampBy default this timer fires a minute after the previous sync.
120662cb04cSPoul-Henning Kamp.Pp
121662cb04cSPoul-Henning KampThe
122a1e0a00fSRuslan Ermilov.Fl z Ar compression
123a1e0a00fSRuslan Ermilovoption controls the
124662cb04cSPoul-Henning Kamp.Xr zlib 3
125a1e0a00fSRuslan Ermilovcompression level; legal values are zero to nine which is the default.
126662cb04cSPoul-Henning Kamp.Pp
127a1e0a00fSRuslan ErmilovThe
128a1e0a00fSRuslan Ermilov.Nm fifolog_reader
129a1e0a00fSRuslan Ermilovutility
130662cb04cSPoul-Henning Kampwill retrieve records from the fifolog according to the specified
131a1e0a00fSRuslan Ermilovparameters and write them either to standard output or the file specified
132662cb04cSPoul-Henning Kampwith
133662cb04cSPoul-Henning Kamp.Fl o .
134662cb04cSPoul-Henning Kamp.Pp
135662cb04cSPoul-Henning KampIt is possible to specify a start and end time to limit the amount
136662cb04cSPoul-Henning Kampof data
137662cb04cSPoul-Henning Kamp.Nm fifolog_reader
138662cb04cSPoul-Henning Kampwill report.
139662cb04cSPoul-Henning KampThe lower-case variants
140662cb04cSPoul-Henning Kamp.Fl b
141662cb04cSPoul-Henning Kampand
142662cb04cSPoul-Henning Kamp.Fl e
143662cb04cSPoul-Henning Kamptake a
144a1e0a00fSRuslan Ermilov.Vt time_t
145662cb04cSPoul-Henning Kampvalue, whereas the upper-case variants
146662cb04cSPoul-Henning Kamp.Fl B
147662cb04cSPoul-Henning Kampand
148662cb04cSPoul-Henning Kamp.Fl E
149a1e0a00fSRuslan Ermilovtake human-readable specifications such as
150a1e0a00fSRuslan Ermilov.Dq Li "1 hour ago" .
151662cb04cSPoul-Henning Kamp.Pp
152662cb04cSPoul-Henning KampThe
153662cb04cSPoul-Henning Kamp.Fl t
154a1e0a00fSRuslan Ermilovoption forces timestamps to be formatted as
155a1e0a00fSRuslan Ermilov.Dq Li "YYYYMMDDhhmmss"
156a1e0a00fSRuslan Ermilovinstead of as
157a1e0a00fSRuslan Ermilov.Vt time_t ,
158a1e0a00fSRuslan Ermilovand
159662cb04cSPoul-Henning Kamp.Fl T
160a1e0a00fSRuslan Ermilovallows the specification of an
161662cb04cSPoul-Henning Kamp.Xr strftime 3
162662cb04cSPoul-Henning Kampformatting string.
163662cb04cSPoul-Henning Kamp.Pp
164662cb04cSPoul-Henning KampFinally, records can be filtered such that only records matching the
165a1e0a00fSRuslan Ermilov.Pq Dv REG_BASIC
166a1e0a00fSRuslan Ermilovregular expression specified with
167662cb04cSPoul-Henning Kamp.Fl R
168a1e0a00fSRuslan Ermilovare output.
169662cb04cSPoul-Henning Kamp.Sh IMPLEMENTATION NOTES
170a1e0a00fSRuslan ErmilovThe data stored in the fifolog consists of three layers, an outer
171662cb04cSPoul-Henning Kamplayer that allows searches to synchronization points based on timestamps
172662cb04cSPoul-Henning Kampwithout having to decompress and decode the actual contents, a
173662cb04cSPoul-Henning Kampcompression layer implemented with
174a1e0a00fSRuslan Ermilov.Xr zlib 3 ,
175662cb04cSPoul-Henning Kampand an inner serialization and timestamping layer.
176662cb04cSPoul-Henning Kamp.Pp
177a1e0a00fSRuslan ErmilovThe exact encoding is described in the
178a1e0a00fSRuslan Ermilov.Pa fifolog.h
179a1e0a00fSRuslan Ermilovfile.
180662cb04cSPoul-Henning Kamp.Pp
181662cb04cSPoul-Henning KampFifolog is particularly well suited for use on Flash based media, where
182662cb04cSPoul-Henning Kampit results in much lower write-wear, than a file system with regular
183662cb04cSPoul-Henning Kamplog files rotated with
184662cb04cSPoul-Henning Kamp.Xr newsyslog 8
185662cb04cSPoul-Henning Kampetc.
186662cb04cSPoul-Henning Kamp.Sh EXAMPLES
187662cb04cSPoul-Henning KampCreate a fifolog with 1024*1024 records of 512 bytes:
188a1e0a00fSRuslan Ermilov.Pp
189a1e0a00fSRuslan Ermilov.Dl "fifolog_create -r 10m /tmp/fifolog"
190662cb04cSPoul-Henning Kamp.Pp
191662cb04cSPoul-Henning KampWrite a single record to this file:
192a1e0a00fSRuslan Ermilov.Pp
193a1e0a00fSRuslan Ermilov.Dl "date | fifolog_writer /tmp/fifolog"
194662cb04cSPoul-Henning Kamp.Pp
195662cb04cSPoul-Henning KampRead it back with human readable timestamps:
196a1e0a00fSRuslan Ermilov.Pp
197a1e0a00fSRuslan Ermilov.Dl "fifolog_reader -t /tmp/fifolog"
198662cb04cSPoul-Henning Kamp.Pp
199662cb04cSPoul-Henning KampOne particular useful use of
200662cb04cSPoul-Henning Kamp.Nm fifolog_writer
201662cb04cSPoul-Henning Kampis with
202662cb04cSPoul-Henning Kamp.Xr syslogd 8
203662cb04cSPoul-Henning Kampusing a line such as this in
204*b94db03dSSergey Kandaurov.Xr syslog.conf 5 :
205a1e0a00fSRuslan Ermilov.Pp
206a1e0a00fSRuslan Ermilov.Dl "*.* |fifolog_writer /var/log/syslog_fifolog"
207662cb04cSPoul-Henning Kamp.Sh HISTORY
208a1e0a00fSRuslan ErmilovThe fifolog tools have been liberated from an open source
209a1e0a00fSRuslan Ermilov.Tn SCADA
210a1e0a00fSRuslan Ermilovapplications called
211a1e0a00fSRuslan Ermilov.Dq measured ,
212a1e0a00fSRuslan Ermilovwhich monitors and controls remote radio navigation
213662cb04cSPoul-Henning Kamptransmitters for the Danish Air Traffic Control system.
214662cb04cSPoul-Henning Kamp.Sh AUTHORS
215a1e0a00fSRuslan ErmilovThe fifolog tools were written by
216a1e0a00fSRuslan Ermilov.An Poul-Henning Kamp .
217