line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
46250
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
19
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package App::RecordStream; |
5
|
1
|
|
|
1
|
|
332
|
use Module::Pluggable::Object; |
|
1
|
|
|
|
|
6478
|
|
|
1
|
|
|
|
|
89
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "4.0.25"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub operation_packages { |
10
|
1
|
|
|
1
|
0
|
377
|
sort { $a cmp $b } |
|
43
|
|
|
|
|
30847
|
|
11
|
|
|
|
|
|
|
Module::Pluggable::Object->new( |
12
|
|
|
|
|
|
|
search_path => "App::RecordStream::Operation", |
13
|
|
|
|
|
|
|
max_depth => 4, |
14
|
|
|
|
|
|
|
)->plugins |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=encoding utf-8 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=for markdown |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=for markdown |
23
|
|
|
|
|
|
|
[![CPAN version](https://badge.fury.io/pl/App-RecordStream.png)](https://metacpan.org/release/App-RecordStream) |
24
|
|
|
|
|
|
|
[![Build Status](https://travis-ci.org/benbernard/RecordStream.svg?branch=master)](https://travis-ci.org/benbernard/RecordStream) |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
App::RecordStream - recs - A system for command-line analysis of data |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
A set of programs for creating, manipulating, and outputting a stream of |
33
|
|
|
|
|
|
|
Records, or JSON hashes. Inspired by Monad. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 INSTALLATION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 Quick, standalone bundle |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
The quickest way to start using recs is via the minimal, standalone bundle: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
curl -fsSL https://recs.pl > recs |
42
|
|
|
|
|
|
|
chmod +x recs |
43
|
|
|
|
|
|
|
./recs --help |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This is also known as the "fatpacked" recs. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 From CPAN |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
You can also install recs from L as App::RecordStream: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
cpanm --interactive App::RecordStream |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Using L in interactive mode will prompt you for optional feature |
54
|
|
|
|
|
|
|
support. Other CPAN clients such as L and L also work fine, but |
55
|
|
|
|
|
|
|
you can't opt to use any optional features (just like cpanm in non-interactive |
56
|
|
|
|
|
|
|
mode). A kitchen-sink install of App::RecordStream looks like: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
cpanm --with-recommends --with-all-features App::RecordStream |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
If you don't have L itself, you can install it easily with: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
curl -fsSL https://cpanmin.us | perl - App::cpanminus |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The recs system consists of three basic sets of commands: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=over 4 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * I commands responsible for generating streams of record objects |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item * I commands responsible for analyzing, selecting, and manipulating records |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * I |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
These commands can interface with other systems to retrieve data, parse existing |
79
|
|
|
|
|
|
|
files, or just regex out some values from a text stream. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Commands are run using C. If you're using |
82
|
|
|
|
|
|
|
a CPAN-based install, you may also run commands directly as C, |
83
|
|
|
|
|
|
|
though this is no longer recommended for forwards compatibility. Both |
84
|
|
|
|
|
|
|
L provide a top-level C executable |
85
|
|
|
|
|
|
|
which dispatches to commands, so this is the preferred invocation style. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The core recs commands are briefly summarized below, and you can list all |
88
|
|
|
|
|
|
|
available commands by running C. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
To read more about each command, run C. Longer |
91
|
|
|
|
|
|
|
documentation is available as C or C. |
92
|
|
|
|
|
|
|
For example, to read more about L, you might run any of the |
93
|
|
|
|
|
|
|
following: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
recs fromcsv --help |
96
|
|
|
|
|
|
|
recs fromcsv --help-all |
97
|
|
|
|
|
|
|
perldoc recs-fromcsv |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COMMANDS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 Input Generation |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item fromcsv |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Produces records from a csv file/stream |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item fromdb |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Produces records for a db table, or from a SELECT statement into a db. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item fromre |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Matches input streams against a regex, puts capture groups into hashes |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item frommongo |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Generate a record stream from a MongoDB query. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item frommultire |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Matches input streams against several regexes, puts capture groups into the record |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item fromsplit |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Splits input stream on a delimiter |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item fromps |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Generate records from the process tree |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item fromatomfeed |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Produces records for an optionally paginated atom feed. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item fromxml |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Produces records for an XML document. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item fromkv |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Produces records from input streams containing loosely formed key/value pairs |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item fromtcpdump |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Produces records from packet capture files (.pcap) as made by tcpdump |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 Stream Manipulation |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over 4 |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item annotate |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Annotate records with common fields, will memoize additions to speed up common |
158
|
|
|
|
|
|
|
annotations |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item collate |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Perforce aggregation operations on records. Group by a field, get an average, |
163
|
|
|
|
|
|
|
sum, correlation, etc. Very powerful |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item delta |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Transform values into deltas between adjacent records |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item eval |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Eval a string of Perl against each record |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item flatten |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Flatten records of input to one level |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item grep |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Select records for which a string of Perl evaluates to true. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item multiplex |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Take records, grouped by keys, and run a separate recs command for each group. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item normalizetime |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Based on a time field, tag records with a normalized time, i.e. every 5 minute buckets |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item join |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Perform an inner join of two record streams. Associate records in one stream |
192
|
|
|
|
|
|
|
with another stream. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item substream |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Filter to a range of matching records with paired Perl snippets C<--start> and C<--end>. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item sort |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Sort records based on keys, may specify multiple levels of sorting, as well as |
201
|
|
|
|
|
|
|
numerical or lexical sort ordering |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item topn |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Outputs the top I records. You may segment the input based on a list of keys |
206
|
|
|
|
|
|
|
such that unique values of keys are treated as distinct input streams. This |
207
|
|
|
|
|
|
|
enables top I listings per value groupings. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item xform |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Perform a block of Perl on each record, which may modify the record, Record is |
212
|
|
|
|
|
|
|
then output |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item generate |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Perform a block of Perl on each record to generate a record stream, which is |
217
|
|
|
|
|
|
|
then output with a chain link back to the original record. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=back |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 Output Generation |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over 4 |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item todb |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Inserts records into a DBI supported SQL database. Will create a local SQLite |
228
|
|
|
|
|
|
|
database by default |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item tocsv |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Generates correctly quoted CSV files from record streams. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item tognuplot |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Create a graph of field values in a record using GNU Plot. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item totable |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Pretty prints a table of results. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item tohtml |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Prints out an HTML table of the record stream |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item toprettyprint |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Prettily prints records, one key to a line, great for making sense of very large records |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item toptable |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Prints a multi-dimensional (pivot) table of values. Very powerful. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=back |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 KEY SPECS |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Many of the commands above take key arguments to specify or assign to a key in a |
259
|
|
|
|
|
|
|
record. Almost all of the places where you can specify a key (which normally |
260
|
|
|
|
|
|
|
means a first level key in the record), you can instead specify a key spec. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
A key spec may be nested, and may index into arrays. Use a C> to nest into a |
263
|
|
|
|
|
|
|
hash and a C<#NUM> to index into an array (i.e. C<#2>) |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
An example is in order, take a record like this: |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
{"biz":["a","b","c"],"foo":{"bar 1":1},"zap":"blah1"} |
268
|
|
|
|
|
|
|
{"biz":["a","b","c"],"foo":{"bar 1":2},"zap":"blah2"} |
269
|
|
|
|
|
|
|
{"biz":["a","b","c"],"foo":{"bar 1":3},"zap":"blah3"} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
In this case a key spec of C would have the values 1, 2, and 3 |
272
|
|
|
|
|
|
|
respectively. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Similarly, C would have the value of C for all 3 records |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head2 Fuzzy matching |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
You can also prefix key specs with C<@> to engage the fuzzy matching logic. |
279
|
|
|
|
|
|
|
Matching is tried like this, in order, with the first key to match winning: |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=over 4 |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item 1. Exact match (C) |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item 2. Prefix match (C) |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item 3. Match anywhere in the key (C) |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=back |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Given the above example data and the fuzzy key spec C<@b/#2>, the C portion |
292
|
|
|
|
|
|
|
would expand to C and C<2> would be the index into the array, so all |
293
|
|
|
|
|
|
|
records would have the value of C. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Simiarly, C<@f/b> would have values 1, 2, and 3. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head1 WRITING YOUR OWN COMMANDS |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
The data stream format of the recs commands is JSON hashes separated by new |
300
|
|
|
|
|
|
|
lines. If you wish to write your own recs command in your own language, just |
301
|
|
|
|
|
|
|
get a JSON parser and you should be good to go. The recs commands use |
302
|
|
|
|
|
|
|
L. |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
If you name your command as C and put it somewhere in your |
305
|
|
|
|
|
|
|
C environment variable, the C command will dispatch to it when |
306
|
|
|
|
|
|
|
called as C. It will also be included in C |
307
|
|
|
|
|
|
|
output. |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
If you want to write your new command in Perl, you can use the same Perl API |
310
|
|
|
|
|
|
|
that the standard recs toolkit uses. See the various |
311
|
|
|
|
|
|
|
L subclasses. Once your new operation class is |
312
|
|
|
|
|
|
|
installed in perl's library paths, C will find it automatically without |
313
|
|
|
|
|
|
|
the need for any executable command shim. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 EXAMPLES |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# look in the custom access log for all accesses with greater than 5 seconds, |
318
|
|
|
|
|
|
|
# display in a table |
319
|
|
|
|
|
|
|
cat access.log \ |
320
|
|
|
|
|
|
|
| recs fromre --fields ip,time '^(\d+).*TIME: (\d+)' \ |
321
|
|
|
|
|
|
|
| recs grep '$r->{time} > 5' \ |
322
|
|
|
|
|
|
|
| recs totable |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=head1 SEE ALSO |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
Each of the commands discussed have a C<--help> mode available to print out |
327
|
|
|
|
|
|
|
usage and examples for the particular command. See that documentation for |
328
|
|
|
|
|
|
|
detailed information on the operation of each of the commands. Also see some |
329
|
|
|
|
|
|
|
other man pages: |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=over |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=item * Run C or see L for a set of simple recs examples |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=item * Run C or see L for a humorous introduction to RecordStream |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=back |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head1 AUTHORS |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
Benjamin Bernard |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Keith Amling |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
Thomas Sibley |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Copyright 2007–2017 by the AUTHORS |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
This software is released under the MIT and Artistic 1.0 licenses. |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=cut |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
1; |