apache_log_report 0.9.4 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e24660fd5b97e6d07312173f1333c60be9191802d27ca114f7fd5ca8e615559
4
- data.tar.gz: f141ec4f8e12eaaee87bdba74ec287d21b0e1266e7ac10364a7dda5f402a0b0b
3
+ metadata.gz: 0cfcc34ca8741250adff411009618f4a359c4c59606a911a924416650fa352e7
4
+ data.tar.gz: 4f366f09084266e0112f597aac8be998ff47df8ef50d8fd01b1c26361dc889b9
5
5
  SHA512:
6
- metadata.gz: 793fbf6d497b55d77947034dcc80b4b62f9c83f181db23a7d34554d87becca1e726aed70957646b7da8ff6c22d6055e32df9b1fe18d4b3f74c4e9b56993de99e
7
- data.tar.gz: 4fc2177c75b0a6ea25c6c0c6e7d1166fb28914c1de978d64afd2196e92cb47df65c4901e181f78a432c2786b85d7a6164b4771f40b0a000429d1ba29b938fa65
6
+ metadata.gz: ddee7b7b3fd56327c3409f0a6de2778b83a0e67d743d300f00259ba314159d1cb62315f388fc0136052895903c7e6df47e08ba59b036db23f0722fc99e5f7b6d
7
+ data.tar.gz: 0e857dbb34cd66057a401016afcd457c19c995c7aff66a87d4db230569b67a091c19d5f3446377f1a7ee8f8cda3b70ea0b8b4753bd7aea3beadc07810cf2d54b
@@ -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
data/README.org CHANGED
@@ -12,6 +12,13 @@
12
12
 
13
13
  See the [[file:CHANGELOG.org][CHANGELOG]] file.
14
14
 
15
+ * Todo
16
+
17
+ ** TODO Version information from command line and in reports
18
+ ** TODO Refactor code from one giant class to more manageable chunkes
19
+ ** TODO Move performance stats var to class (to isolate vars)
20
+ ** TODO Check total number of days (which is not working, now)
21
+
15
22
  * Compatibility
16
23
 
17
24
 
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
@@ -393,12 +415,12 @@ set boxwidth 0.6
393
415
  set style data histograms
394
416
  set style histogram clustered gap 1
395
417
 
396
- plot data using 2:xtic(1) lc rgb "#CC0000" title "4xx", \\
418
+ plot data using 2:xtic(1) lc rgb "#00AA00" title "2xx", \\
397
419
  data using 3 lc rgb "#0000CC" title "3xx", \\
398
- data using 4 lc rgb "#00AA00" title "2xx", \\
399
- data using ($0 - 1. / 4):($2 + 0.5):2 with labels title "" textcolor rgb("#CC0000"), \\
420
+ data using 4 lc rgb "#AA0000" title "4xx", \\
421
+ data using ($0 - 1. / 4):($2 + 0.5):2 with labels title "" textcolor rgb("#00AA00"), \\
400
422
  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("#00AA00")
423
+ data using ($0 + 1. / 4):($4 + 0.5):4 with labels title "" textcolor rgb("#AA0000")
402
424
  #+END_SRC
403
425
 
404
426
  * Browsers
@@ -1,3 +1,3 @@
1
1
  module ApacheLogReport
2
- VERSION = "0.9.4"
2
+ VERSION = "0.9.9"
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.4
4
+ version: 0.9.9
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: 2020-10-12 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.