log_analyzer 0.1.0
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 +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +49 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/log_analyzer +40 -0
- data/lib/log_analyzer.rb +9 -0
- data/lib/log_analyzer/analyzer.rb +71 -0
- data/lib/log_analyzer/stat.rb +28 -0
- data/lib/log_analyzer/version.rb +3 -0
- data/log_analyzer.gemspec +33 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b65515f5afad3cc16020fa642e54712b33ce891
|
4
|
+
data.tar.gz: 7855b62a20e5f59dea8461b869ab2ba5583d4285
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c9be991d98c8e06a3927ad4a549de362bd082e9ad84b7a5f40117dc89bd5d3863eecce0289bfc772d9d8ba301b58e6d509b846a0c4ffb2774cf6bfa680dc556
|
7
|
+
data.tar.gz: 2a3955df278f8530d3b7bec768b709dc44e05acc4199622d0fd20221c51b24d2ecdf844906a28956964f25c41fa8dda9568409470a4cedfa09e55f34f5053d92
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
log_analyzer (0.1.0)
|
5
|
+
colorize
|
6
|
+
terminal-table
|
7
|
+
thor
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.2)
|
13
|
+
colorize (0.8.1)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
method_source (0.9.0)
|
16
|
+
pry (0.11.3)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.9.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.1)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.1)
|
33
|
+
terminal-table (1.8.0)
|
34
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
35
|
+
thor (0.19.4)
|
36
|
+
unicode-display_width (1.3.0)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (> 1.14)
|
43
|
+
log_analyzer!
|
44
|
+
pry
|
45
|
+
rake (~> 10.0)
|
46
|
+
rspec (~> 3.0)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.14.6
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# LogAnalyzer
|
2
|
+
|
3
|
+
See how fast is rendering in your app. Based on information from logs
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'log_analyzer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install log_analyzer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/varyform/log_analyzer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
data/bin/log_analyzer
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "log_analyzer"
|
5
|
+
require "pry"
|
6
|
+
require "terminal-table"
|
7
|
+
require "colorize"
|
8
|
+
require "optparse"
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: log_analyzer [options]\nSample: log_analyzer -f production.log -s name"
|
14
|
+
|
15
|
+
opts.on("-f filename", "--file=filename", "Select log file") do |v|
|
16
|
+
options[:file] = v
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-s order", "--sort=order", "Select sorting: time/name/count. Default: time") do |v|
|
20
|
+
options[:sort] = v
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-h', '--help', 'Displays Help') do
|
24
|
+
puts opts
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
parser.parse!
|
30
|
+
|
31
|
+
options[:sort] ||= :time # default order
|
32
|
+
|
33
|
+
if options[:file] && options[:sort]
|
34
|
+
analyzer = LogAnalyzer.analyze(filename: options[:file])
|
35
|
+
analyzer.run
|
36
|
+
analyzer.order(by: options[:sort])
|
37
|
+
analyzer.visualize
|
38
|
+
else
|
39
|
+
parser.parse! %w[--help]
|
40
|
+
end
|
data/lib/log_analyzer.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module LogAnalyzer
|
2
|
+
|
3
|
+
class Analyzer
|
4
|
+
DEFAULT_TABLE_WIDTH = 120 # width
|
5
|
+
MATCHER = /Rendered (.*) \((.*)ms\)/.freeze
|
6
|
+
DANGER_DEFAULT = 800 # ms
|
7
|
+
WARNING_DEFAULT = 400 # ms
|
8
|
+
INFO_DEFAULT = 100 # ms
|
9
|
+
|
10
|
+
attr_reader :filename
|
11
|
+
attr_reader :stats
|
12
|
+
|
13
|
+
def initialize(filename:)
|
14
|
+
@filename = filename
|
15
|
+
@stats = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
IO.foreach(filename).each do |line|
|
20
|
+
if line =~ MATCHER
|
21
|
+
if $1 && $2
|
22
|
+
@stats[$1] ||= Stat.new
|
23
|
+
@stats[$1].push($2)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def order(by: :time)
|
30
|
+
case by.to_sym
|
31
|
+
when :name
|
32
|
+
@stats = @stats.sort{|a, b| a[0] <=> b[0] }
|
33
|
+
when :time
|
34
|
+
@stats = @stats.sort{|a, b| a[1].avg <=> b[1].avg }
|
35
|
+
when :count
|
36
|
+
@stats = @stats.sort{|a, b| a[1].count <=> b[1].count }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def visualize(limit: 100)
|
41
|
+
length = (0..DEFAULT_TABLE_WIDTH - 20).freeze
|
42
|
+
table = Terminal::Table.new \
|
43
|
+
headings: ['Path', 'Count', 'AVG (ms)', 'Max', 'Min'],
|
44
|
+
width: DEFAULT_TABLE_WIDTH do |t|
|
45
|
+
stats.each do |path, stat|
|
46
|
+
t.add_row [
|
47
|
+
path[length],
|
48
|
+
stat.count,
|
49
|
+
avg_label(stat.avg),
|
50
|
+
stat.max,
|
51
|
+
stat.min,
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
puts table
|
56
|
+
end
|
57
|
+
|
58
|
+
def avg_label(avg)
|
59
|
+
str = avg.to_s
|
60
|
+
if avg > DANGER_DEFAULT
|
61
|
+
str.white.on_red
|
62
|
+
elsif avg > WARNING_DEFAULT
|
63
|
+
str.red
|
64
|
+
elsif avg > INFO_DEFAULT
|
65
|
+
str.yellow
|
66
|
+
else
|
67
|
+
str.green
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LogAnalyzer
|
2
|
+
class Stat
|
3
|
+
attr_reader :count
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@data = []
|
8
|
+
@count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def push(time)
|
12
|
+
@count += 1
|
13
|
+
@data << time.to_f
|
14
|
+
end
|
15
|
+
|
16
|
+
def avg
|
17
|
+
@avg ||= (sum.to_f / count.to_f).round(2)
|
18
|
+
end
|
19
|
+
|
20
|
+
def max; @max ||= @data.max; end
|
21
|
+
def min; @min ||= @data.min; end
|
22
|
+
|
23
|
+
private
|
24
|
+
def sum
|
25
|
+
@sum ||= @data.inject(nil) { |total, x| total ? total + x : x }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'log_analyzer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "log_analyzer"
|
8
|
+
spec.version = LogAnalyzer::VERSION
|
9
|
+
spec.authors = ["Igor Kasyanchuk"]
|
10
|
+
spec.email = ["igorkasyanchuk@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{log_analyzer gem is created to get statistics about your views rendering performance.}
|
13
|
+
spec.description = %q{log_analyzer gem is created to get statistics about your views rendering performance.}
|
14
|
+
spec.homepage = "https://github.com/igorkasyanchuk"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = Dir["{lib,test}/**/*", "log_analyzer.gemspec", "Gemfile", "Gemfile.lock", "MIT-LICENSE", "Rakefile", "README.md", "bin/log_analyzer"]
|
18
|
+
spec.test_files = Dir["rspec/**/*"]
|
19
|
+
|
20
|
+
spec.executables = ['log_analyzer']
|
21
|
+
|
22
|
+
spec.bindir = "bin"
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "thor"
|
26
|
+
spec.add_dependency "terminal-table"
|
27
|
+
spec.add_dependency "colorize"
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "> 1.14"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "pry"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log_analyzer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Kasyanchuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: terminal-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
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: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: log_analyzer gem is created to get statistics about your views rendering
|
112
|
+
performance.
|
113
|
+
email:
|
114
|
+
- igorkasyanchuk@gmail.com
|
115
|
+
executables:
|
116
|
+
- log_analyzer
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/log_analyzer
|
125
|
+
- lib/log_analyzer.rb
|
126
|
+
- lib/log_analyzer/analyzer.rb
|
127
|
+
- lib/log_analyzer/stat.rb
|
128
|
+
- lib/log_analyzer/version.rb
|
129
|
+
- log_analyzer.gemspec
|
130
|
+
homepage: https://github.com/igorkasyanchuk
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.8
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: log_analyzer gem is created to get statistics about your views rendering
|
154
|
+
performance.
|
155
|
+
test_files: []
|