apache_log_report 0.9.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d75b1094318f7610f0ef9f0cd34ef7fe5d2ba38effb65514d1ca2dddb90962c
4
- data.tar.gz: c0c16a44463d9a808dd6919aaf8aa1c1dfbf16bd589bdef1c8ab6e839dba8c05
3
+ metadata.gz: be24b7fd62ff47195fe5e19cd2717252a37a687a8d92745add21acc952fc50a3
4
+ data.tar.gz: 3f5daff6a7447b6acca3a7ef456b148c3de49ff2dee87b75d419763dc2bbe2c4
5
5
  SHA512:
6
- metadata.gz: af73bf2dd1eec2b9985cc0fa0cf72c7ae1ca0afa91e14eb11e5b6e187d52a81880fe4b3051eba23ad3d5b207d977e0a9132e0644ae51853b8e6d76ff41b7ee1d
7
- data.tar.gz: c968b4971563a5164e790392a34d7cda4787a21385f283d6f39c27ae14a4b10bb99c735d7084f562af169337f77e17e22b4a78d7e9cd9d84eca411be0d59b491
6
+ metadata.gz: d5271fd26059e942a730c649cd6ea00c35b459c3f5b130bd2d0ae707717b3554c90b7adff8364f384e56b5e8782ca147b1fd40f957290aed4a7bc443eb38387c
7
+ data.tar.gz: 475dfe3e49e76434c620bb75558bc2b5e40c6441fe455fca58d9b70b366a549f76a9d1bbbf9aae4bf5c9e0daa013770cefa9047fa11b8206f7eff4425be54b50
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ apache_log_report (0.9.7)
5
+ apache_log-parser
6
+ browser
7
+ sqlite3
8
+ terminal-table
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ apache_log-parser (3.1.2)
14
+ browser (5.0.0)
15
+ rake (12.3.3)
16
+ sqlite3 (1.4.2)
17
+ terminal-table (1.8.0)
18
+ unicode-display_width (~> 1.1, >= 1.1.1)
19
+ unicode-display_width (1.7.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ apache_log_report!
26
+ rake (~> 12.0)
27
+
28
+ BUNDLED WITH
29
+ 2.1.4
File without changes
@@ -5,52 +5,63 @@ module ApacheLogReport
5
5
  #
6
6
  require 'optparse'
7
7
  require 'optparse/date'
8
+ require 'apache_log_report/version'
8
9
 
9
10
  def self.options_parse options
10
11
  limit = 30
11
12
  args = {}
12
13
 
13
14
  opt_parser = OptionParser.new do |opts|
14
- opts.banner = "Usage: log-analyzer.rb [options] logfile"
15
+ opts.banner = "Usage: apache_log_report [options] [logfile]"
15
16
 
16
17
  opts.on("-lN", "--limit=N", Integer, "Number of entries to show (defaults to #{limit})") do |n|
17
18
  args[:limit] = n
18
19
  end
19
20
 
20
- opts.on("-bDATE", "--from-date=DATE", DateTime, "Consider entries after or on DATE") do |n|
21
+ opts.on("-bDATE", "--begin=DATE", DateTime, "Consider entries after or on DATE") do |n|
21
22
  args[:from_date] = n
22
23
  end
23
24
 
24
- opts.on("-eDATE", "--to-date=DATE", DateTime, "Consider entries before or on DATE") do |n|
25
+ opts.on("-eDATE", "--end=DATE", DateTime, "Consider entries before or on DATE") do |n|
25
26
  args[:to_date] = n
26
27
  end
27
28
 
28
- opts.on("-i", "--ignore-crawlers", "Ignore crawlers") do |n|
29
+ opts.on("-i", "--ignore-crawlers", "Ignore crawlers") do
29
30
  args[:ignore_crawlers] = true
30
31
  end
31
32
 
32
- opts.on("-p", "--ignore-selfpoll", "Ignore apaches self poll entries (from ::1)") do |n|
33
+ opts.on("-p", "--ignore-selfpoll", "Ignore apaches self poll entries (from ::1)") do
33
34
  args[:no_selfpoll] = true
34
35
  end
35
36
 
36
- opts.on("-c", "--only-crawlers", "Perform analysis on crawlers only") do |n|
37
+ opts.on("-c", "--only-crawlers", "Perform analysis on crawlers only") do
37
38
  args[:only_crawlers] = true
38
39
  end
39
40
 
40
- opts.on("-u", "--prefix=PREFIX", String, "Prefix to add to all plots (used to run multiple analyses in the same dir)") do |n|
41
+ opts.on("-uPREFIX", "--prefix=PREFIX", String, "Prefix to add to all plots (used to run multiple analyses in the same dir)") do |n|
41
42
  args[:prefix] = n
42
43
  end
43
44
 
44
- opts.on("-w", "--suffix=SUFFIX", String, "Suffix to add to all plots (used to run multiple analyses in the same dir)") do |n|
45
+ opts.on("-wSUFFIX", "--suffix=SUFFIX", String, "Suffix to add to all plots (used to run multiple analyses in the same dir)") do |n|
45
46
  args[:suffix] = n
46
47
  end
47
48
 
48
- opts.on("-c", "--code-export=WHAT", String, "Control :export directive in code blocks (code, results, *both*, none)") do |n|
49
+ opts.on("-cWHAT", "--code-export=WHAT", String, "Control :export directive in code blocks (code, results, *both*, none)") do |n|
49
50
  args[:code_export] = n
50
51
  end
51
52
 
53
+ opts.on("-v", "--version", "Prints version information") do
54
+ puts "apache_log_report version #{ApacheLogReport::VERSION}"
55
+ puts "Copyright (C) 2020 Adolfo Villafiorita"
56
+ puts "Distributed under the terms of the MIT license"
57
+ puts ""
58
+ puts "Written by Adolfo Villafiorita"
59
+ exit
60
+ end
61
+
52
62
  opts.on("-h", "--help", "Prints this help") do
53
63
  puts opts
64
+ puts "This is version #{ApacheLogReport::VERSION}"
54
65
  exit
55
66
  end
56
67
  end
@@ -130,7 +141,7 @@ module ApacheLogReport
130
141
  hash[:datetime].iso8601,
131
142
  hash[:remote_host],
132
143
  hash[:user],
133
- hash[:datetime].iso8601 + " " + hash[:remote_host] + " " + hash[:user_agent],
144
+ hash[:datetime].strftime("%Y-%m-%d") + " " + hash[:remote_host] + " " + hash[:user_agent],
134
145
  hash[:request][:method],
135
146
  hash[:request][:path],
136
147
  (hash[:request][:path] ? File.extname(hash[:request][:path]) : ""),
@@ -175,18 +186,29 @@ module ApacheLogReport
175
186
  "true"
176
187
  ].compact.join " and "
177
188
 
189
+ # in alternative to sum(size)
190
+ human_readable_size = <<-EOS
191
+ CASE
192
+ WHEN sum(size) < 1024 THEN sum(size) || ' B'
193
+ WHEN sum(size) >= 1024 AND sum(size) < (1024 * 1024) THEN ROUND((CAST(sum(size) AS REAL) / 1024),2) || ' KB'
194
+ WHEN sum(size) >= (1024 * 1024) AND sum(size) < (1024 * 1024 * 1024) THEN ROUND((CAST(sum(size) AS REAL) / (1024 * 1024)),2) || ' MB'
195
+ WHEN sum(size) >= (1024 * 1024 * 1024) AND sum(size) < (1024 * 1024 * 1024 *1024) THEN ROUND((CAST(sum(size) AS REAL) / (1024 * 1024 * 1024)),2) || ' GB'
196
+ WHEN sum(size) >= (1024 * 1024 * 1024 * 1024) THEN ROUND((CAST(sum(size) AS REAL) / (1024 * 1024 * 1024 * 1024)),2) || ' TB'
197
+ END AS size
198
+ EOS
199
+
178
200
  @total_hits = db.execute "SELECT count(datetime) from LogLine where #{@filter}"
179
201
  @total_unique_visitors = db.execute "SELECT count(distinct(unique_visitor)) from LogLine where #{@filter}"
180
- @total_size = db.execute "SELECT sum(size) from LogLine where #{@filter}"
202
+ @total_size = db.execute "SELECT #{human_readable_size} from LogLine where #{@filter}"
181
203
  @total_days = (Date.parse(@last_day[0][0]) - Date.parse(@first_day[0][0])).to_i
182
204
 
183
- @daily_distribution = db.execute "SELECT date(datetime), count(datetime), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by date(datetime)"
205
+ @daily_distribution = db.execute "SELECT date(datetime), count(datetime), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by date(datetime)"
184
206
 
185
- @time_distribution = db.execute "SELECT strftime('%H', datetime), count(datetime), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by strftime('%H', datetime)"
207
+ @time_distribution = db.execute "SELECT strftime('%H', datetime), count(datetime), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by strftime('%H', datetime)"
186
208
 
187
- @most_requested_pages = db.execute "SELECT path, count(path), count(distinct(unique_visitor)), sum(size) from LogLine where extension == '.html' and #{@filter} group by path order by count(path) desc limit #{options[:limit]}"
209
+ @most_requested_pages = db.execute "SELECT path, count(path), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where extension == '.html' and #{@filter} group by path order by count(path) desc limit #{options[:limit]}"
188
210
 
189
- @most_requested_resources = db.execute "SELECT path, count(path), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by path order by count(path) desc limit #{options[:limit]}"
211
+ @most_requested_resources = db.execute "SELECT path, count(path), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by path order by count(path) desc limit #{options[:limit]}"
190
212
 
191
213
  @missed_pages = db.execute "SELECT path, count(path), count(distinct(unique_visitor)) from LogLine where status == '404' and extension == '.html' and #{@filter} group by path order by count(path) desc limit #{options[:limit]}"
192
214
 
@@ -208,13 +230,13 @@ module ApacheLogReport
208
230
  [x[0], x[1].map { |y| y[1] }].flatten
209
231
  }
210
232
 
211
- @browsers = db.execute "SELECT browser, count(browser), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by browser order by count(browser) desc"
233
+ @browsers = db.execute "SELECT browser, count(browser), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by browser order by count(browser) desc"
212
234
 
213
- @platforms = db.execute "SELECT platform, count(platform), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by platform order by count(platform) desc"
235
+ @platforms = db.execute "SELECT platform, count(platform), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by platform order by count(platform) desc"
214
236
 
215
- @ips = db.execute "SELECT ip, count(ip), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by ip order by count(ip) desc limit #{options[:limit]}"
237
+ @ips = db.execute "SELECT ip, count(ip), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by ip order by count(ip) desc limit #{options[:limit]}"
216
238
 
217
- @referers = db.execute "SELECT referer, count(referer), count(distinct(unique_visitor)), sum(size) from LogLine where #{@filter} group by referer order by count(referer) desc limit #{options[:limit]}"
239
+ @referers = db.execute "SELECT referer, count(referer), count(distinct(unique_visitor)), #{human_readable_size} from LogLine where #{@filter} group by referer order by count(referer) desc limit #{options[:limit]}"
218
240
  end
219
241
 
220
242
 
@@ -236,7 +258,7 @@ module ApacheLogReport
236
258
  end
237
259
 
238
260
  def self.emit options = {}, command, log_file, started_at, ended_at, duration
239
- @prefx = options[:prefix]
261
+ @prefix = options[:prefix]
240
262
  @suffix = options[:suffix]
241
263
  @export = options[:code_export]
242
264
 
@@ -252,7 +274,7 @@ module ApacheLogReport
252
274
 
253
275
  | Hits | #{"%10d" % @total_hits[0][0]} |
254
276
  | Unique Visitors | #{"%10d" % @total_unique_visitors[0][0] } |
255
- | Tx | #{"%10d" % @total_size[0][0] } |
277
+ | Tx | #{"%10s" % @total_size[0][0]} |
256
278
  | Days | #{"%10d" % @total_days[0][0] } |
257
279
 
258
280
  * Daily Distribution
@@ -282,8 +304,8 @@ plot data using 1:2 with linespoints lw 3 lc rgb "#0000AA" pointtype 5 title "Hi
282
304
  data using 1:2 with filledcurves below x1 linecolor rgb "#0000AA" notitle axes x1y2, \\
283
305
  data using 1:3 with linespoints lw 3 lc rgb "#AA0000" pointtype 7 title "Visitors", \\
284
306
  data using 1:3 with filledcurves below x1 notitle linecolor rgb "#AA0000", \\
285
- data using 1:($3+10):3 with labels notitle textcolor rgb "#AA0000", \\
286
- data using 1:($2+100):2 with labels notitle textcolor rgb "#0000AA" axes x1y2
307
+ data using 1:($3+0.1*$3):3 with labels notitle textcolor rgb "#AA0000", \\
308
+ data using 1:($2+0.1*$2):2 with labels notitle textcolor rgb "#0000AA" axes x1y2
287
309
  #+END_SRC
288
310
 
289
311
 
@@ -312,8 +334,8 @@ set style histogram clustered gap 1
312
334
 
313
335
  plot data using 2:xtic(1) lc rgb "#0000AA" title "Hits", \\
314
336
  data using 3 lc rgb "#AA0000" title "Visitors" axes x1y2, \\
315
- data using ($0 - 0.2):($2 + 10):2 with labels title "" textcolor rgb("#0000AA"), \\
316
- data using ($0 + 0.2):($3 + 10):3 with labels title "" textcolor rgb("#AA0000") axes x1y2
337
+ data using ($0 - 0.2):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#0000AA"), \\
338
+ data using ($0 + 0.2):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#AA0000") axes x1y2
317
339
  #+END_SRC
318
340
 
319
341
  #+BEGIN_SRC gnuplot :var data = time_distribution :results output :exports #{@export} :file #{@prefix}time-traffic#{@suffix}.svg
@@ -333,7 +355,7 @@ set style data histograms
333
355
  set style histogram clustered gap 1
334
356
 
335
357
  plot data using 2:xtic(1) lc rgb "#00AA00" title "Traffic", \\
336
- data using ($0):($2 + 10):2 with labels title "" textcolor rgb("#00AA00")
358
+ data using ($0):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#00AA00")
337
359
  #+END_SRC
338
360
 
339
361
  * Most Requested Pages
@@ -369,7 +391,7 @@ set style fill solid 0.25
369
391
  set boxwidth 0.6
370
392
 
371
393
  plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
372
- data using ($0):($2+100):2 with labels textcolor rgb "#0000AA"
394
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
373
395
  #+END_SRC
374
396
 
375
397
  * Daily Statuses
@@ -396,9 +418,9 @@ set style histogram clustered gap 1
396
418
  plot data using 2:xtic(1) lc rgb "#00AA00" title "2xx", \\
397
419
  data using 3 lc rgb "#0000CC" title "3xx", \\
398
420
  data using 4 lc rgb "#AA0000" title "4xx", \\
399
- data using ($0 - 1. / 4):($2 + 0.5):2 with labels title "" textcolor rgb("#00AA00"), \\
400
- data using ($0):($3 + 0.5):3 with labels title "" textcolor rgb("#0000CC"), \\
401
- data using ($0 + 1. / 4):($4 + 0.5):4 with labels title "" textcolor rgb("#AA0000")
421
+ data using ($0 - 1. / 4):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#00AA00"), \\
422
+ data using ($0):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#0000CC"), \\
423
+ data using ($0 + 1. / 4):($4 + 0.1*$4):4 with labels title "" textcolor rgb("#AA0000")
402
424
  #+END_SRC
403
425
 
404
426
  * Browsers
@@ -414,7 +436,7 @@ set style fill solid 0.25
414
436
  set boxwidth 0.6
415
437
 
416
438
  plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
417
- data using ($0):($2+100):2 with labels textcolor rgb "#0000AA"
439
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
418
440
  #+END_SRC
419
441
 
420
442
  * Platforms
@@ -430,7 +452,7 @@ set style fill solid 0.25
430
452
  set boxwidth 0.6
431
453
 
432
454
  plot data using 2:xtic(1) with boxes lc rgb "#0000AA" title "Hits", \\
433
- data using ($0):($2+100):2 with labels textcolor rgb "#0000AA"
455
+ data using ($0):($2+0.1*$2):2 with labels textcolor rgb "#0000AA"
434
456
  #+END_SRC
435
457
 
436
458
  * IPs
@@ -462,8 +484,8 @@ set style histogram clustered gap 1
462
484
 
463
485
  plot data using 2:xtic(1) lc rgb "#AA00AA" title "Hits", \\
464
486
  data using 3 lc rgb "#0AAAA0" title "Visits", \\
465
- data using ($0 - 1. / 3):($2 + 50):2 with labels title "" textcolor rgb("#AA00AA"), \\
466
- data using ($0 + 1. / 3):($3 + 50):3 with labels title "" textcolor rgb("#0AAAA0")
487
+ data using ($0 - 1. / 3):($2 + 0.1*$2):2 with labels title "" textcolor rgb("#AA00AA"), \\
488
+ data using ($0 + 1. / 3):($3 + 0.1*$3):3 with labels title "" textcolor rgb("#0AAAA0")
467
489
  #+END_SRC
468
490
 
469
491
  * Command Invocation and Performance
@@ -1,3 +1,3 @@
1
1
  module ApacheLogReport
2
- VERSION = "0.9.5"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apache_log_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adolfo Villafiorita
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-29 00:00:00.000000000 Z
11
+ date: 2021-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apache_log-parser
@@ -77,6 +77,7 @@ files:
77
77
  - ".gitignore"
78
78
  - CHANGELOG.org
79
79
  - Gemfile
80
+ - Gemfile.lock
80
81
  - LICENSE.txt
81
82
  - README.org
82
83
  - Rakefile
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  requirements: []
112
- rubygems_version: 3.1.2
113
+ rubygems_version: 3.0.3
113
114
  signing_key:
114
115
  specification_version: 4
115
116
  summary: Generate a request report in OrgMode format from an Apache log file.