sidekiq_log_analyser 0.1 → 0.1.1

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
  SHA1:
3
- metadata.gz: e3a036b6772fc546a4a801308218311359568ebe
4
- data.tar.gz: 45a43301a978ce126ab49a0f1cf8bfba8ab2efa5
3
+ metadata.gz: ef60b02fa7759404e20513cc3c8237e52607b9e0
4
+ data.tar.gz: 3cb0b0eb267a3caa5b15df0b17e577ca0dc62b4b
5
5
  SHA512:
6
- metadata.gz: b42b0cb77d124462e3401e52c5f466056904cb25a1c46c6c0f2d4493948436d7bf677e131f9fc9a7be4793a1a78826c024c7279c32f090f64328e61b10f3b4ee
7
- data.tar.gz: 0b981740d105bd1ea54afe6687e47263612d940c0f635e3f80ce7f73c3a8c3e6653f8bed7d496803eb93172d00598ddb1c21fa4da4cf956bfba6eafa0dbfcbb8
6
+ metadata.gz: f17d5acebf327ddf225e4427ba4784ca7d3a8cb103864dae5fdff59b27e612e76c6b5cfc3da04ebd02d075db48237f4c04536f3325d8d0c0ec3484b6707da3a0
7
+ data.tar.gz: fe070fee1bd1659766dbb2f7bb79293e12ca381c94f38a5592b64789b59291d3e39ba67586034de9cf2309329986a71a9285b1fedf7ab32bc91255894b6aba3b
@@ -2,13 +2,15 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  sidekiq_log_analyser (0.1)
5
+ activesupport
5
6
  colorize
6
7
  groupdate
8
+ terminal-table
7
9
 
8
10
  GEM
9
11
  remote: https://rubygems.org/
10
12
  specs:
11
- activesupport (5.2.1)
13
+ activesupport (5.2.0)
12
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
15
  i18n (>= 0.7, < 2)
14
16
  minitest (~> 5.1)
@@ -19,27 +21,27 @@ GEM
19
21
  diff-lcs (1.3)
20
22
  groupdate (4.0.1)
21
23
  activesupport (>= 4.2)
22
- i18n (1.1.0)
24
+ i18n (1.0.1)
23
25
  concurrent-ruby (~> 1.0)
24
26
  method_source (0.9.0)
25
27
  minitest (5.11.3)
26
28
  pry (0.11.3)
27
29
  coderay (~> 1.1.0)
28
30
  method_source (~> 0.9.0)
29
- rake (10.5.0)
30
- rspec (3.8.0)
31
- rspec-core (~> 3.8.0)
32
- rspec-expectations (~> 3.8.0)
33
- rspec-mocks (~> 3.8.0)
34
- rspec-core (3.8.0)
35
- rspec-support (~> 3.8.0)
36
- rspec-expectations (3.8.1)
31
+ rake (10.4.2)
32
+ rspec (3.7.0)
33
+ rspec-core (~> 3.7.0)
34
+ rspec-expectations (~> 3.7.0)
35
+ rspec-mocks (~> 3.7.0)
36
+ rspec-core (3.7.1)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-expectations (3.7.0)
37
39
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.8.0)
39
- rspec-mocks (3.8.0)
40
+ rspec-support (~> 3.7.0)
41
+ rspec-mocks (3.7.0)
40
42
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.8.0)
42
- rspec-support (3.8.0)
43
+ rspec-support (~> 3.7.0)
44
+ rspec-support (3.7.1)
43
45
  terminal-table (1.8.0)
44
46
  unicode-display_width (~> 1.1, >= 1.1.1)
45
47
  thread_safe (0.3.6)
@@ -59,4 +61,4 @@ DEPENDENCIES
59
61
  terminal-table
60
62
 
61
63
  BUNDLED WITH
62
- 1.16.1
64
+ 1.13.6
@@ -2,14 +2,17 @@ require 'time'
2
2
  require 'groupdate'
3
3
  require 'colorize'
4
4
  require 'terminal-table'
5
- require "sidekiq_log_analyser/version"
6
- require "sidekiq_log_analyser/row"
7
- require "sidekiq_log_analyser/pretty_print"
8
- require "sidekiq_log_analyser/collection"
9
- require "sidekiq_log_analyser/log_file"
10
- require "sidekiq_log_analyser/simple_stat"
11
- require "sidekiq_log_analyser/timeline"
12
- require "sidekiq_log_analyser/app"
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
7
+
8
+ require_relative "sidekiq_log_analyser/version"
9
+ require_relative "sidekiq_log_analyser/row"
10
+ require_relative "sidekiq_log_analyser/pretty_print"
11
+ require_relative "sidekiq_log_analyser/collection"
12
+ require_relative "sidekiq_log_analyser/log_file"
13
+ require_relative "sidekiq_log_analyser/statistics"
14
+ require_relative "sidekiq_log_analyser/timeline"
15
+ require_relative "sidekiq_log_analyser/app"
13
16
 
14
17
  module SidekiqLogAnalyser
15
18
  end
@@ -3,10 +3,20 @@ module SidekiqLogAnalyser
3
3
  def App.run(filename)
4
4
  log_file = LogFile.new(filename)
5
5
  collection = Collection.new(log_file.lines)
6
- statistics = SimpleStat.new(collection)
6
+ statistics = Statistics.new(collection)
7
+
8
+ print "\nSidekiq log analyser report (30 days) ".colorize(:cyan)
9
+ 3.times do
10
+ print '.'.colorize(:yellow)
11
+ sleep(0.5)
12
+ end
13
+ puts
14
+ puts
7
15
 
8
16
  PrettyPrint.print_summary_report(statistics.total)
17
+
9
18
  PrettyPrint.print_avg_report(statistics.avg)
19
+
10
20
  PrettyPrint.print_timeline_report(statistics.timeline)
11
21
 
12
22
  nil
@@ -4,6 +4,7 @@ module SidekiqLogAnalyser
4
4
  attr_reader :start_collection, :end_collection
5
5
 
6
6
  def initialize(lines)
7
+ @from_date = 1.month.ago
7
8
  populate(lines)
8
9
  end
9
10
 
@@ -12,15 +13,23 @@ module SidekiqLogAnalyser
12
13
  lines.each do |line|
13
14
  row = Row.new(line)
14
15
  if row.valid?
15
- @collection << row.metadata
16
+ metadata = row.metadata
17
+ @collection << metadata if in_range?(metadata[:datetime])
16
18
  end
17
19
  end
18
20
  @start_collection ||= collection(:start).group_by{|metadata| metadata[:worker]}
19
21
  @end_collection ||= collection(:end).group_by{|metadata| metadata[:worker]}
22
+ @collection = []
20
23
  end
21
24
 
22
25
  private
23
26
 
27
+ def in_range?(datetime)
28
+ return false if datetime.blank?
29
+
30
+ @from_date < datetime
31
+ end
32
+
24
33
  def collection(type)
25
34
  @collection.select{|metadata| metadata[:type] == type}
26
35
  end
@@ -11,6 +11,7 @@ module SidekiqLogAnalyser
11
11
  end
12
12
  puts(table)
13
13
  puts
14
+ puts
14
15
  end
15
16
 
16
17
  def PrettyPrint.print_avg_report(report)
@@ -21,6 +22,7 @@ module SidekiqLogAnalyser
21
22
  end
22
23
  puts(table)
23
24
  puts
25
+ puts
24
26
  end
25
27
 
26
28
  def PrettyPrint.print_timeline_report(report)
@@ -32,6 +34,7 @@ module SidekiqLogAnalyser
32
34
  end
33
35
  puts(table)
34
36
  puts
37
+ puts
35
38
  end
36
39
  end
37
40
 
@@ -21,23 +21,25 @@ module SidekiqLogAnalyser
21
21
  end
22
22
 
23
23
  def metadata
24
- if start?
25
- {
26
- datetime: Time.parse(start_match[1]),
27
- worker: start_match[3].split(' ').last,
28
- job_id: start_match[4],
29
- type: :start
30
- }
31
- elsif end?
32
- {
33
- datetime: Time.parse(end_match[1]),
34
- worker: end_match[3].split(' ').last,
35
- job_id: end_match[4],
36
- duration: end_match[5].to_f,
37
- type: :end
38
- }
39
- else
40
- {}
24
+ @metadata ||= begin
25
+ if start?
26
+ {
27
+ datetime: Time.parse(start_match[1]),
28
+ worker: start_match[3].split(' ').last,
29
+ job_id: start_match[4],
30
+ type: :start
31
+ }
32
+ elsif end?
33
+ {
34
+ datetime: Time.parse(end_match[1]),
35
+ worker: end_match[3].split(' ').last,
36
+ job_id: end_match[4],
37
+ duration: end_match[5].to_f,
38
+ type: :end
39
+ }
40
+ else
41
+ {}
42
+ end
41
43
  end
42
44
  end
43
45
 
@@ -0,0 +1,38 @@
1
+ module SidekiqLogAnalyser
2
+ class Statistics
3
+ attr_reader :collection
4
+
5
+ def initialize(collection)
6
+ @collection = collection
7
+ end
8
+
9
+ def total
10
+ with_collection { |worker, data| data.count }
11
+ end
12
+
13
+ def avg
14
+ with_collection do |worker, data|
15
+ data.sum{|metadata| metadata[:duration]}.to_f / data.length
16
+ end
17
+ end
18
+
19
+ def timeline
20
+ with_collection { |worker, data| Timeline.timeline(data) }
21
+ end
22
+
23
+ private
24
+
25
+ def with_collection
26
+ result = {}
27
+ raw = end_collection
28
+ raw.each do |worker, data|
29
+ result[worker] = yield(worker, data)
30
+ end
31
+ result
32
+ end
33
+
34
+ def start_collection; collection.start_collection; end
35
+ def end_collection; collection.end_collection; end
36
+
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module SidekiqLogAnalyser
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_log_analyser
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-08 00:00:00.000000000 Z
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groupdate
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +157,7 @@ files:
129
157
  - lib/sidekiq_log_analyser/log_file.rb
130
158
  - lib/sidekiq_log_analyser/pretty_print.rb
131
159
  - lib/sidekiq_log_analyser/row.rb
132
- - lib/sidekiq_log_analyser/simple_stat.rb
160
+ - lib/sidekiq_log_analyser/statistics.rb
133
161
  - lib/sidekiq_log_analyser/timeline.rb
134
162
  - lib/sidekiq_log_analyser/version.rb
135
163
  - spec/row_spec.rb
@@ -156,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
184
  version: '0'
157
185
  requirements: []
158
186
  rubyforge_project:
159
- rubygems_version: 2.6.14
187
+ rubygems_version: 2.6.8
160
188
  signing_key:
161
189
  specification_version: 4
162
190
  summary: Simple sidekiq log analyzer.
@@ -1,41 +0,0 @@
1
- module SidekiqLogAnalyser
2
- class SimpleStat
3
- extend Forwardable
4
-
5
- attr_reader :collection
6
-
7
- def_delegator :collection, :start_collection
8
- def_delegator :collection, :end_collection
9
-
10
- def initialize(collection)
11
- @collection = collection
12
- end
13
-
14
- def total
15
- result = {}
16
- raw = end_collection
17
- raw.each do |worker, data|
18
- result[worker] = data.count
19
- end
20
- result
21
- end
22
-
23
- def avg
24
- result = {}
25
- raw = end_collection
26
- raw.each do |worker, data|
27
- result[worker] = data.sum{|metadata| metadata[:duration]}.to_f / data.length
28
- end
29
- result
30
- end
31
-
32
- def timeline
33
- result = {}
34
- raw = end_collection
35
- raw.each do |worker, data|
36
- result[worker] = Timeline.timeline(data)
37
- end
38
- result
39
- end
40
- end
41
- end