apache_log_report 0.9.9 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ <%
2
+ def slugify string
3
+ string.downcase.gsub(/ +/, '-')
4
+ end
5
+ %>
6
+
7
+ <table id="<%= slugify(title || "") %>" class="<%= slugify(title || "") %>">
8
+ <thead>
9
+ <tr>
10
+ <% header.each do |heading| %>
11
+ <th class="<%= slugify(heading) %>"><%= heading %></th>
12
+ <% end %>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% rows.each do |row| %>
17
+ <tr>
18
+ <% row.each_with_index do |cell, i| %>
19
+ <td class="<%= slugify (header[i] || "") %>"><%= cell %></td>
20
+ <% end %>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+
@@ -0,0 +1,200 @@
1
+ <html>
2
+ <head>
3
+ <title>Apache Log Analysis: <%= data[:log_file] || "stdin" %></title>
4
+ <meta name="author" content="apache_log_report">
5
+
6
+ <link rel="stylesheet" href="alr-styles.css"></style>
7
+ </head>
8
+
9
+ <body>
10
+ <section>
11
+ <h1>Apache Log Analysis: <%= data[:log_file] || "stdin" %></h1>
12
+
13
+ <article>
14
+ <h2>Summary</h2>
15
+
16
+ <table class="pure-table summary">
17
+ <tr>
18
+ <th class="hits">Hits</th>
19
+ <td class="hits"><%= data[:total_hits][0][0] %></td>
20
+ </tr>
21
+ <tr>
22
+ <th class="unique-visitors">Unique Visitors</th>
23
+ <td class="unique-visitors"><%= data[:total_unique_visitors][0][0] %></td>
24
+ </tr>
25
+ <tr>
26
+ <th class="tx">Tx</th>
27
+ <td class="tx"><%= data[:total_size][0][0] %></td>
28
+ </tr>
29
+ <tr>
30
+ <th class="period">Period</th>
31
+ <td class="period">
32
+ <%= data[:first_day][0][0] %>
33
+ --
34
+ <%= data[:last_day][0][0] %>
35
+ </td>
36
+ </tr>
37
+ <tr>
38
+ <th class="days">Days </th>
39
+ <td class="days"><%= data[:total_days] %></td>
40
+ </tr>
41
+ </table>
42
+ </article>
43
+
44
+ <% @reports = [
45
+ { title: "Daily Distribution", header: ["Day", "Hits", "Visits", "Size"], rows: data[:daily_distribution] },
46
+ { title: "Time Distribution", header: ["Hour", "Hits", "Visits", "Size"], rows: data[:time_distribution] },
47
+ { title: "Most Requested Pages", header: ["Path", "Hits", "Visits", "Size"], rows: data[:most_requested_pages] },
48
+ { title: "Most Requested Resources", header: ["Path", "Hits", "Visits", "Size"], rows: data[:most_requested_resources] },
49
+ { title: "404 on HTML Files", header: ["Path", "Hits", "Visitors"], rows: data[:missed_pages] },
50
+ { title: "404 on other Resources", header: ["Path", "Hits", "Visitors"], rows: data[:missed_resources] },
51
+ { title: "Attacks", header: ["Path", "Hits", "Visitors"], rows: data[:attacks] },
52
+ { title: "Statuses", header: ["Status", "Count"], rows: data[:statuses] },
53
+ { title: "Daily Statuses", header: ["Status", "2xx", "3xx", "4xx"], rows: data[:statuses_by_day] },
54
+ { title: "Browsers", header: ["Browser", "Hits", "Visitors", "Size"], rows: data[:browsers] },
55
+ { title: "Platforms", header: ["Platform", "Hits", "Visitors", "Size"], rows: data[:platforms] },
56
+ { title: "IPs", header: ["IPs", "Hits", "Visitors", "Size"], rows: data[:ips] },
57
+ { title: "Referers", header: ["Referers", "Hits", "Visitors", "Size"], rows: data[:referers] },
58
+ ]
59
+ %>
60
+ <% @reports.each do |report| %>
61
+ <article>
62
+ <h2><%= report[:title] %></h2>
63
+ <%= render "output_table", report %>
64
+ </article>
65
+ <% end %>
66
+
67
+ <article>
68
+ <h2>Streaks</h2>
69
+
70
+ <table class="streaks">
71
+ <thead>
72
+ <tr>
73
+ <th>IP</th>
74
+ <th>Day</th>
75
+ <th>URL</th>
76
+ </tr>
77
+ </thead>
78
+ <tbody>
79
+ <% data[:streaks].group_by(&:first).each do |ip, date_urls| %>
80
+ <tr>
81
+ <td class="ip"><%= ip %></td>
82
+ <td class="streaks">
83
+ <% date_urls.group_by(&:first).each do |date, urls| %>
84
+ <% urls.each do |url| %>
85
+ <b><%= url[1] %>:</b> <%= url[2] %> <br />
86
+ <% end %>
87
+ <% end %>
88
+ </td>
89
+ </tr>
90
+ <% end %>
91
+ </tbody>
92
+ </table>
93
+ </article>
94
+
95
+ <article>
96
+ <h2>Command Invocation and Performance</h2>
97
+
98
+ <h3>Command Invocation</h3>
99
+
100
+ <code>
101
+ </code>
102
+
103
+ <table class="pure-table command-invocation">
104
+ <tbody>
105
+ <tr>
106
+ <th>CLI Command</th>
107
+ <td><pre><%= data[:command] %></pre></td>
108
+ </tr>
109
+ <tr>
110
+ <th>Input file</th>
111
+ <td><code><%= (data[:log_file] || "stdin") %></code></td>
112
+ </tr>
113
+ <tr>
114
+ <th>Ignore crawlers</th>
115
+ <td><code><%= options[:ignore_crawlers] %></code></td></tr>
116
+ <tr>
117
+ <th>Only crawlers</th>
118
+ <td><code><%= options[:only_crawlers] %></code></td>
119
+ </tr>
120
+ <tr>
121
+ <th>No selfpoll</th>
122
+ <td><code><%= options[:no_selfpoll] %></code></td>
123
+ </tr>
124
+ <tr>
125
+ <th>Filter by date</th>
126
+ <td>
127
+ <code><%= (options[:from_date] != nil or options[:to_date] != nil) %></code>
128
+ </td>
129
+ </tr>
130
+ <tr>
131
+ <th>Prefix</th>
132
+ <td><code><%= @prefix %></code></td>
133
+ </tr>
134
+ <tr>
135
+ <th>Suffix</th>
136
+ <td><code><%= @suffix %></code></td>
137
+ </tr>
138
+ </tbody>
139
+ </table>
140
+
141
+ <h3> Log Structure</h3>
142
+
143
+ <table class="pure-table log-structure">
144
+ <tbody>
145
+ <tr>
146
+ <th>Log size</th>
147
+ <td><%= data[:log_size][0][0] %></td>
148
+ </tr>
149
+ <tr>
150
+ <th>Self poll entries</th>
151
+ <td><%= data[:selfpolls_size][0][0] %></td>
152
+ </tr>
153
+ <tr>
154
+ <th>Crawlers</th>
155
+ <td><%= data[:crawlers_size][0][0] %></td>
156
+ </tr>
157
+ <tr>
158
+ <th>Entries considered</th>
159
+ <td><%= data[:total_hits][0][0] %></td>
160
+ </tr>
161
+ </tbody>
162
+ </table>
163
+
164
+ <h3> Performance</h3>
165
+
166
+ <table class="pure-table performance">
167
+ <tbody>
168
+ <tr>
169
+ <th>Analysis started at</th>
170
+ <td><%= data[:started_at].to_s %></td>
171
+ </tr>
172
+ <tr>
173
+ <th>Analysis ended at</th>
174
+ <td><%= data[:ended_at].to_s %></td>
175
+ </tr>
176
+ <tr>
177
+ <th>Duration (sec)</th>
178
+ <td><%= "%.1f" % data[:duration] %></td>
179
+ </tr>
180
+ <tr>
181
+ <th>Duration (min)</th>
182
+ <td><%= "%d" % (data[:duration] / 60 ) %></td>
183
+ </tr>
184
+ <tr>
185
+ <th>Log size</th>
186
+ <td><%= data[:log_size][0][0] %></td>
187
+ </tr>
188
+ <tr>
189
+ <th>Lines/sec</th>
190
+ <td><%= "%.2f" % (data[:log_size][0][0] / data[:duration]) %></td></tr>
191
+ </tbody>
192
+ </table>
193
+ </article>
194
+ </section>
195
+ </body>
196
+ </html>
197
+
198
+
199
+
200
+
@@ -0,0 +1,262 @@
1
+ #+TITLE: Apache Log Analysis: <%= data[:log_file] %>
2
+ #+DATE: <<%= Date.today %>>
3
+ #+STARTUP: showall
4
+ #+OPTIONS: ^:{}
5
+ #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="ala-style.css" />
6
+ #+OPTIONS: html-style:nil
7
+
8
+ * Summary
9
+
10
+ | Hits | <%= "%10d" % data[:total_hits][0][0] %> |
11
+ | Unique Visitors | <%= "%10d" % data[:total_unique_visitors][0][0] %> |
12
+ | Tx | <%= "%10s" % data[:total_size][0][0] %> |
13
+ | Days | <%= "%10d" % data[:total_days][0][0] %> |
14
+
15
+ * Daily Distribution
16
+
17
+ <%= self.output_table "daily_distribution", ["Day", "Hits", "Visits", "Size"], data[:daily_distribution] %>
18
+
19
+ #+BEGIN_SRC gnuplot :var data = daily_distribution :results output :exports <%= @export %> :file <%= @prefix %>daily<%= @suffix %>.svg
20
+ reset
21
+ set grid ytics linestyle 0
22
+ set grid xtics linestyle 0
23
+ set terminal svg size 1200,800 fname 'Arial'
24
+
25
+ set xdata time
26
+ set timefmt "%Y-%m-%d"
27
+ set format x "%a, %b %d"
28
+ set xtics rotate by 60 right
29
+
30
+ set title "Hits and Visitors"
31
+ set xlabel "Date"
32
+ set ylabel "Hits"
33
+ set y2label "Visits"
34
+ set y2tics
35
+
36
+ set style fill transparent solid 0.2 noborder
37
+
38
+ plot data using 1:2 with linespoints lw 3 lc rgb "#0000AA" pointtype 5 title "Hits" axes x1y2, \\
39
+ data using 1:2 with filledcurves below x1 linecolor rgb "#0000AA" notitle axes x1y2, \\
40
+ data using 1:3 with linespoints lw 3 lc rgb "#AA0000" pointtype 7 title "Visitors", \\
41
+ data using 1:3 with filledcurves below x1 notitle linecolor rgb "#AA0000", \\
42
+ data using 1:($3+0.1*$3):3 with labels notitle textcolor rgb "#AA0000", \\
43
+ data using 1:($2+0.1*$2):2 with labels notitle textcolor rgb "#0000AA" axes x1y2
44
+ #+END_SRC
45
+
46
+
47
+ * Time Distribution
48
+
49
+ <%= self.output_table "time_distribution", ["Hour", "Hits", "Visits", "Size"], data[:time_distribution] %>
50
+
51
+
52
+ #+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports <%= @export %> :file <%= @prefix %>time<%= @suffix %>.svg
53
+ reset
54
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
55
+
56
+ set grid ytics linestyle 0
57
+
58
+ set title "Hits and Visitors"
59
+ set xlabel "Date"
60
+ set ylabel "Hits"
61
+ set y2label "Visitors"
62
+ set y2tics
63
+
64
+ set style fill solid 0.25
65
+ set boxwidth 0.6
66
+
67
+ set style data histograms
68
+ set style histogram clustered gap 1
69
+
70
+ plot data using 2:xtic(1) lc rgb "#0000AA" title "Hits", \\
71
+ data using 3 lc rgb "#AA0000" title "Visitors" axes x1y2, \\
72
+ data using ($0 - 0.2):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#0000AA"), \\
73
+ data using ($0 + 0.2):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#AA0000") axes x1y2
74
+ #+END_SRC
75
+
76
+ #+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports <%= @export %> :file <%= @prefix %>time-traffic<%= @suffix %>.svg
77
+ reset
78
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
79
+
80
+ set grid ytics linestyle 0
81
+
82
+ set title "Traffic"
83
+ set xlabel "Date"
84
+ set ylabel "Traffic"
85
+
86
+ set style fill solid 0.50
87
+ set boxwidth 0.6
88
+
89
+ set style data histograms
90
+ set style histogram clustered gap 1
91
+
92
+ plot data using 2:xtic(1) lc rgb "#00AA00" title "Traffic", \\
93
+ data using ($0):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#00AA00")
94
+ #+END_SRC
95
+
96
+ * Most Requested Pages
97
+
98
+ <%= self.output_table "most_requested_pages", ["Path", "Hits", "Visits", "Size"], data[:most_requested_pages] %>
99
+
100
+ * Most Requested URIs
101
+
102
+ <%= self.output_table "most_requested_resources", ["Path", "Hits", "Visits", "Size"], data[:most_requested_resources] %>
103
+
104
+ * 404s on HTML files
105
+
106
+ <%= self.output_table "pages_404", ["Path", "Hits", "Visitors"], data[:missed_pages] %>
107
+
108
+ * 404s on other resources
109
+
110
+ <%= self.output_table "resources_404", ["Path", "Hits", "Visitors"], data[:missed_resources] %>
111
+
112
+ * Possible Attacks
113
+
114
+ <%= self.output_table "attacks", ["Path", "Hits", "Visitors"], data[:attacks] %>
115
+
116
+ * Statuses
117
+
118
+ <%= self.output_table "statuses", ["Status", "Count"], data[:statuses] %>
119
+
120
+ #+BEGIN_SRC gnuplot :var data = statuses :results output :exports <%= @export %> :file <%= @prefix %>statuses<%= @suffix %>.svg
121
+ reset
122
+ set grid ytics linestyle 0
123
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
124
+
125
+ set style fill solid 0.25
126
+ set boxwidth 0.6
127
+
128
+ plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
129
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
130
+ #+END_SRC
131
+
132
+ * Daily Statuses
133
+
134
+ <%= self.output_table "daily_statuses", ["Status", "2xx", "3xx", "4xx"], data[:statuses_by_day] %>
135
+
136
+ #+BEGIN_SRC gnuplot :var data = daily_statuses :results output :exports <%= @export %> :file <%= @prefix %>daily-statuses<%= @suffix %>.svg
137
+ reset
138
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
139
+
140
+ set grid ytics linestyle 0
141
+
142
+ set title "Daily Statuses"
143
+ set xlabel "Date"
144
+ set ylabel "Number of Hits"
145
+ set xtics rotate by 60 right
146
+
147
+ set style fill solid 0.25
148
+ set boxwidth 0.6
149
+
150
+ set style data histograms
151
+ set style histogram clustered gap 1
152
+
153
+ plot data using 2:xtic(1) lc rgb "#00AA00" title "2xx", \\
154
+ data using 3 lc rgb "#0000CC" title "3xx", \\
155
+ data using 4 lc rgb "#AA0000" title "4xx", \\
156
+ data using ($0 - 1. / 4):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#00AA00"), \\
157
+ data using ($0):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#0000CC"), \\
158
+ data using ($0 + 1. / 4):($4 + 0.1*$4):4 with labels title "" textcolor rgb("#AA0000")
159
+ #+END_SRC
160
+
161
+ * Browsers
162
+
163
+ <%= self.output_table "browsers", ["Browser", "Hits", "Visitors", "Size"], data[:browsers] %>
164
+
165
+ #+BEGIN_SRC gnuplot :var data = browsers :results output :exports <%= @export %> :file <%= @prefix %>browser<%= @suffix %>.svg
166
+ reset
167
+ set grid ytics linestyle 0
168
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
169
+
170
+ set style fill solid 0.25
171
+ set boxwidth 0.6
172
+
173
+ plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
174
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
175
+ #+END_SRC
176
+
177
+ * Platforms
178
+
179
+ <%= self.output_table "platforms", ["Platform", "Hits", "Visitors", "Size"], data[:platforms] %>
180
+
181
+ #+BEGIN_SRC gnuplot :var data = platforms :results output :exports <%= @export %> :file <%= @prefix %>platforms<%= @suffix %>.svg
182
+ reset
183
+ set grid ytics linestyle 0
184
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
185
+
186
+ set style fill solid 0.25
187
+ set boxwidth 0.6
188
+
189
+ plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
190
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
191
+ #+END_SRC
192
+
193
+ * IPs
194
+
195
+ <%= self.output_table "ips", ["IPs", "Hits", "Visitors", "Size"], data[:ips] %>
196
+
197
+
198
+ * Referers
199
+
200
+ <%= self.output_table "referers", ["Referers", "Hits", "Visitors", "Size"], data[:referers] %>
201
+
202
+ #+BEGIN_SRC gnuplot :var data = referers :results output :exports <%= @export %> :file <%= @prefix %>referers<%= @suffix %>.svg
203
+ reset
204
+ set terminal svg size 1200,800 fname 'Arial' fsize 10
205
+
206
+ set grid ytics linestyle 0
207
+ set grid xtics linestyle 0
208
+
209
+ set title "Referers"
210
+ set xlabel "Date"
211
+ set xtics rotate by 60 right
212
+ set ylabel "Hits and Visits"
213
+
214
+ set style fill solid 0.45
215
+ set boxwidth 0.7
216
+
217
+ set style data histograms
218
+ set style histogram clustered gap 1
219
+
220
+ plot data using 2:xtic(1) lc rgb "#AA00AA" title "Hits", \\
221
+ data using 3 lc rgb "#0AAAA0" title "Visits", \\
222
+ data using ($0 - 1. / 3):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#AA00AA"), \\
223
+ data using ($0 + 1. / 3):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#0AAAA0")
224
+ #+END_SRC
225
+
226
+ * Command Invocation and Performance
227
+
228
+ ** Command Invocation
229
+
230
+ #+BEGIN_EXAMPLE shell
231
+ <%= data[:command] %>
232
+ #+END_EXAMPLE
233
+
234
+ | Input file | <%= "%-50s" % (data[:log_file] || "stdin") %> |
235
+ | Ignore crawlers | <%= "%-50s" % options[:ignore_crawlers] %> |
236
+ | Only crawlers | <%= "%-50s" % options[:only_crawlers] %> |
237
+ | No selfpoll | <%= "%-50s" % options[:no_selfpoll] %> |
238
+ | Filter by date | <%= "%-50s" % (options[:from_date] != nil or options[:to_date] != nil) %> |
239
+ | Prefix | <%= "%-50s" % @prefix %> |
240
+ | Suffix | <%= "%-50s" % @suffix %> |
241
+
242
+ ** Log Structure
243
+
244
+ | Log size | <%= "%10d" % data[:log_size][0][0] %> |
245
+ | Self poll entries | <%= "%10d" % data[:selfpolls_size][0][0] %> |
246
+ | Crawlers | <%= "%10d" % data[:crawlers_size][0][0] %> |
247
+ | Entries considered | <%= "%10d" % data[:total_hits][0][0] %> |
248
+
249
+ ** Performance
250
+
251
+ | Analysis started at | <%= data[:started_at].to_s %> |
252
+ | Analysis ended at | <%= data[:ended_at].to_s %> |
253
+ | Duration (sec) | <%= "%5.3d" % data[:duration] %> |
254
+ | Duration (min) | <%= "%5.3d" % (data[:duration] / 60 ) %> |
255
+ | Log size | <%= "%9d" % data[:log_size][0][0] %> |
256
+ | Lines/sec | <%= "%6.2f" % (data[:log_size][0][0] / data[:duration]) %> |
257
+
258
+ * Local Variables :noexport:
259
+ # Local Variables:
260
+ # org-confirm-babel-evaluate: nil
261
+ # org-display-inline-images: t
262
+ # end:
@@ -1,3 +1,3 @@
1
1
  module ApacheLogReport
2
- VERSION = "0.9.9"
2
+ VERSION = "1.1.2"
3
3
  end