1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
.\" Copyright (c) 2008 Poul-Henning Kamp
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd February 9, 2008
.Os
.Dt FIFOLOG 1
.Sh NAME
.Nm fifolog_create , fifolog_writer , fifolog_reader
.Nd "initialize, write, seek and extract data from a fifolog"
.Sh SYNOPSIS
.Nm fifolog_create
.Op Fl l Ar record-size
.Op Fl r Ar record-count
.Op Fl s Ar size
.Ar file
.Nm fifolog_reader
.Op Fl t
.Op Fl b Ar tstart
.Op Fl B Ar Tstart
.Op Fl e Ar tend
.Op Fl E Ar Tend
.Op Fl o Ar ofile
.Op Fl R Ar regexp
.Op Fl T Ar timefmt
.Ar file
.Nm fifolog_writer
.Op Fl w Ar write-rate
.Op Fl s Ar sync-rate
.Op Fl z Ar compression
.Ar file
.Sh DESCRIPTION
Fifologs provide a compact round-robin circular storage for
recording text and binary information to permanent storage in a bounded
and predictable fashion, time and space wise.
.Pp
A fifolog can be stored either directly on a disk partition or in a
regular file.
.Pp
The input data stream is encoded, compressed and marked up with
timestamps before it is written to storage, such that it is possible
to seek out a particular time interval in the stored data, without
having to decompress the entire logfile.
.Pp
The
.Nm fifolog_create
utility
is used to initialize the first sector of a disk device
or file system file to make it a fifolog and should be called only
once.
.Pp
Running
.Nm fifolog_create
on an existing fifolog will reset it so that
.Nm fifolog_reader
and
.Nm fifolog_writer
will not see the previous contents.
(The previous contents are not physically erased, and with a bit
of hand-work all but the first record can be easily recovered.)
.Pp
If the
.Ar file
does not already exist,
.Nm fifolog_create
will attempt to create and
.Xr ftruncate 2
it to the specified size, defaulting to 86400 records of 512 bytes
if the
.Fl r , l
or
.Fl s
options do not specify otherwise.
.Pp
The
.Nm fifolog_writer
utility
will read standard input and write it to the end of the fifolog
according to the parameters given.
.Pp
Writes happen whenever the output buffer is filled with compressed
data or when either of two timers expire, forcing a partially filled
buffer to be written.
.Pp
The first and faster timer,
.Fl w Ar write-rate ,
forces available data to be written
but does not flush and reset the compression dictionary.
This timer is intended to minimize the amount of logdata lost in RAM
in case of a crash and by default it fires 10 seconds after
the previous write.
.Pp
The second and slower timer,
.Fl s Ar sync-rate ,
forces a full flush and reset of the compression
engine and causes the next record written to be a synchronization
point with an uncompressed timestamp, making it possible to start
reading the logfile from that record.
By default this timer fires a minute after the previous sync.
.Pp
The
.Fl z Ar compression
option controls the
.Xr zlib 3
compression level; legal values are zero to nine which is the default.
.Pp
The
.Nm fifolog_reader
utility
will retrieve records from the fifolog according to the specified
parameters and write them either to standard output or the file specified
with
.Fl o .
.Pp
It is possible to specify a start and end time to limit the amount
of data
.Nm fifolog_reader
will report.
The lower-case variants
.Fl b
and
.Fl e
take a
.Vt time_t
value, whereas the upper-case variants
.Fl B
and
.Fl E
take human-readable specifications such as
.Dq Li "1 hour ago" .
.Pp
The
.Fl t
option forces timestamps to be formatted as
.Dq Li "YYYYMMDDhhmmss"
instead of as
.Vt time_t ,
and
.Fl T
allows the specification of an
.Xr strftime 3
formatting string.
.Pp
Finally, records can be filtered such that only records matching the
.Pq Dv REG_BASIC
regular expression specified with
.Fl R
are output.
.Sh IMPLEMENTATION NOTES
The data stored in the fifolog consists of three layers, an outer
layer that allows searches to synchronization points based on timestamps
without having to decompress and decode the actual contents, a
compression layer implemented with
.Xr zlib 3 ,
and an inner serialization and timestamping layer.
.Pp
The exact encoding is described in the
.Pa fifolog.h
file.
.Pp
Fifolog is particularly well suited for use on Flash based media, where
it results in much lower write-wear, than a file system with regular
log files rotated with
.Xr newsyslog 8
etc.
.Sh EXAMPLES
Create a fifolog with 1024*1024 records of 512 bytes:
.Pp
.Dl "fifolog_create -r 10m /tmp/fifolog"
.Pp
Write a single record to this file:
.Pp
.Dl "date | fifolog_writer /tmp/fifolog"
.Pp
Read it back with human readable timestamps:
.Pp
.Dl "fifolog_reader -t /tmp/fifolog"
.Pp
One particular useful use of
.Nm fifolog_writer
is with
.Xr syslogd 8
using a line such as this in
.Xr /etc/syslog.conf 5 :
.Pp
.Dl "*.* |fifolog_writer /var/log/syslog_fifolog"
.Sh HISTORY
The fifolog tools have been liberated from an open source
.Tn SCADA
applications called
.Dq measured ,
which monitors and controls remote radio navigation
transmitters for the Danish Air Traffic Control system.
.Sh AUTHORS
The fifolog tools were written by
.An Poul-Henning Kamp .
|