| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | package App::RecordStream::Manual::Examples; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | App::RecordStream::Manual::Examples - A set of simple recs examples | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | This file provides a couple of useful examples of recs chains and how each of | ||
| 12 | them break down. This is meant as a learning tool for folks new recs that | ||
| 13 | would like to see some cool things you can do with RecordStream. Another good | ||
| 14 | resource is L<App::RecordStream::Manual::Story>, also viewable by running C<recs | ||
| 15 | story>, which is a humorous story meant to get the newest users used to recs. | ||
| 16 | |||
| 17 | =head1 EXAMPLES | ||
| 18 | |||
| 19 | =head2 How many processes is each user on my system running? | ||
| 20 | |||
| 21 | recs fromps | recs collate --key uid -a count | recs sort --key count=n | recs totable | ||
| 22 | |||
| 23 | Broken down this is: | ||
| 24 | |||
| 25 | =over | ||
| 26 | |||
| 27 | =item 1. recs fromps | ||
| 28 | |||
| 29 | First get the records of all the prcesses currently running | ||
| 30 | |||
| 31 | =item 2. recs collate --key uid -a count | ||
| 32 | |||
| 33 | Grouping by the C<uid> field, count how many records fall into the group | ||
| 34 | (stored in the C<count> field by default) | ||
| 35 | |||
| 36 | =item 3. recs sort --key count=n | ||
| 37 | |||
| 38 | Sort the resulting records by the C<count> field numerically (rather than | ||
| 39 | lexically) | ||
| 40 | |||
| 41 | =item 4. recs totable | ||
| 42 | |||
| 43 | Print the output in a nicely formatted plain text table | ||
| 44 | |||
| 45 | =back | ||
| 46 | |||
| 47 | =head2 How many processes for each user at each priority level? | ||
| 48 | |||
| 49 | recs fromps | recs collate --key uid,priority -a count | recs toptable --x priority --y uid --v count | ||
| 50 | |||
| 51 | Broken down: | ||
| 52 | |||
| 53 | =over | ||
| 54 | |||
| 55 | =item 1. recs fromps | ||
| 56 | |||
| 57 | First get the records of all the prcesses currently running | ||
| 58 | |||
| 59 | =item 2. recs collate --key uid,priority -a count | ||
| 60 | |||
| 61 | Grouping by the uid and the priority field, count how many records fall into | ||
| 62 | the group | ||
| 63 | |||
| 64 | =item 3. recs toptable --x priority --y uid -v count | ||
| 65 | |||
| 66 | Create a 2 dimensional table (a I<p>ivot I<table>), across the top put the | ||
| 67 | priority values, down the side put the uid, in each cell put the value of the | ||
| 68 | count field for that priority/uid. | ||
| 69 | |||
| 70 | =back | ||
| 71 | |||
| 72 | =head2 Prep a report on number of modules logging to Xorg.log | ||
| 73 | |||
| 74 | What Xorg modules put information in my Xorg.log at startup, and what log level | ||
| 75 | are they logged at? I need this in CSV format for importing into a spreadsheet | ||
| 76 | program. | ||
| 77 | |||
| 78 | recs frommultire --re 'type,module=\((\S*)\) ([^:]+):' /var/log/Xorg.0.log \ | ||
| 79 | | recs collate --key type,module -a ct \ | ||
| 80 | | recs sort --key ct=n \ | ||
| 81 | | recs tocsv --header | ||
| 82 | |||
| 83 | =over | ||
| 84 | |||
| 85 | =item 1. recs frommultire --re 'type,module=\((\S*)\) ([^:]+):' /var/log/Xorg.0.log | ||
| 86 | |||
| 87 | Parse out the type and module from the Xorg log file. That regex captures | ||
| 88 | non-whitespace inside a literal C<()> pair, then captures text after a space up | ||
| 89 | to the first C<:> (colon). | ||
| 90 | |||
| 91 | =item 2. recs collate --key type,module -a ct | ||
| 92 | |||
| 93 | Collate records into groups of type-modules, and count how many in each group | ||
| 94 | across all records | ||
| 95 | |||
| 96 | =item 3. recs sort --key ct=n | ||
| 97 | |||
| 98 | Sort by the count, numerically | ||
| 99 | |||
| 100 | =item 4. recs tocsv --header | ||
| 101 | |||
| 102 | Output a table in spreadsheet format (no ASCII art), delimited by commas | ||
| 103 | |||
| 104 | =back | ||
| 105 | |||
| 106 | =head1 SEE ALSO | ||
| 107 | |||
| 108 | =over | ||
| 109 | |||
| 110 | =item * See L<App::RecordStream> for an overview of the scripts and the system | ||
| 111 | |||
| 112 | =item * Run C<recs story> or see L<App::RecordStream::Manual::Story> for a humorous introduction to RecordStream | ||
| 113 | |||
| 114 | =back | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | 1; |