slow-events 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +40 -0
- data/.ruby-version +1 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/generators/slow/events/config_generator.rb +17 -0
- data/lib/generators/slow/templates/config.rb +10 -0
- data/lib/slow/events/config.rb +27 -0
- data/lib/slow/events/format.rb +31 -0
- data/lib/slow/events/log_subscriber.rb +15 -0
- data/lib/slow/events/version.rb +7 -0
- data/lib/slow/events.rb +14 -0
- data/slow-events.gemspec +35 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b161e8f080cb2423edea1700f15e125532423f3162d763253b80809995793a4
|
4
|
+
data.tar.gz: 9ddff22176cc33e015527e05f62f9e706d47ed9c5d59a49556c2e1f4e600e32d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d6063b5da94d7818fd3201bbafeacb336f732c226ef8a348c1c6fb576f97af5b97f37e5802aa5d3b5a24af5b83b934e8ebcec9fd5df027f6cf8c3f205c28dfd6
|
7
|
+
data.tar.gz: c64356e7d768f0139ee42097103f0aadd7301762056dbaaaab3340ad6cfa2fc1a49045da06528f0c6c7f4a03df7aba0196e59186b357f6fdbab506167d07dd7f
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Style/StringLiterals:
|
4
|
+
Enabled: true
|
5
|
+
EnforcedStyle: single_quotes
|
6
|
+
|
7
|
+
Style/StringLiteralsInInterpolation:
|
8
|
+
Enabled: true
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Layout/LineLength:
|
12
|
+
Max: 130
|
13
|
+
|
14
|
+
Layout/FirstArrayElementIndentation:
|
15
|
+
EnforcedStyle: consistent
|
16
|
+
|
17
|
+
Layout/FirstHashElementIndentation:
|
18
|
+
EnforcedStyle: consistent
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-06-13 09:20:07 UTC using RuboCop version 0.89.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
12
|
+
# URISchemes: http, https
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 122
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
# Cop supports --auto-correct.
|
18
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
19
|
+
# SupportedStyles: nested, compact
|
20
|
+
Style/ClassAndModuleChildren:
|
21
|
+
Exclude:
|
22
|
+
- 'lib/slow/events.rb'
|
23
|
+
|
24
|
+
# Offense count: 5
|
25
|
+
Style/Documentation:
|
26
|
+
Exclude:
|
27
|
+
- 'spec/**/*'
|
28
|
+
- 'test/**/*'
|
29
|
+
- 'lib/generators/slow/events/config_generator.rb'
|
30
|
+
- 'lib/slow/events.rb'
|
31
|
+
- 'lib/slow/events/config.rb'
|
32
|
+
- 'lib/slow/events/format.rb'
|
33
|
+
- 'lib/slow/events/log_subscriber.rb'
|
34
|
+
|
35
|
+
# Offense count: 1
|
36
|
+
# Cop supports --auto-correct.
|
37
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
38
|
+
# URISchemes: http, https
|
39
|
+
Layout/LineLength:
|
40
|
+
Max: 122
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Khoa Nguyen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Slow::Events
|
2
|
+
This GEM will support U to optimizing your Rails app, easy to see the slow events in Rails log.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'slow-events'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
```
|
14
|
+
$ bundle install
|
15
|
+
```
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
```
|
19
|
+
$ gem install slow-events
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
- You can custom the setting.
|
25
|
+
```
|
26
|
+
$ rails generate slow:events:config
|
27
|
+
```
|
28
|
+
|
29
|
+
And change the your setting in `config/initializers/slow_events.rb` file.
|
30
|
+
|
31
|
+
#### Change the Prefix
|
32
|
+
- Default is `Slow Event:` and you can change to anything
|
33
|
+
```ruby
|
34
|
+
config.prefix = 'Bad events:'
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Change the Duration value
|
38
|
+
- Default is `500ms`, and minimum is `50ms`
|
39
|
+
```ruby
|
40
|
+
config.alert_duration = 300
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Change the Alert color
|
44
|
+
- Default is `YELLOW`
|
45
|
+
- Supported colors: `YELLOW`, `RED`, `GREEN`, `BLUE`, `MAGENTA`, `CYAN`, `WHITE`
|
46
|
+
```ruby
|
47
|
+
config.alert_color = ::Slow::Events::Format::BLUE
|
48
|
+
```
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
53
|
+
|
54
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ThanhKhoaIT/slow-events.
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'slow/events'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/base'
|
4
|
+
|
5
|
+
module Slow
|
6
|
+
module Events
|
7
|
+
module Generators
|
8
|
+
class ConfigGenerator < Rails::Generators::Base
|
9
|
+
source_root File.expand_path('../templates', __dir__)
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
template 'config.rb', 'config/initializers/slow_events.rb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Slow::Events.config do |config|
|
4
|
+
# config.prefix = 'Slow Event:'
|
5
|
+
|
6
|
+
# config.alert_duration = 300 # Default: 500ms
|
7
|
+
|
8
|
+
# config.alert_color = ::Slow::Events::Format::YELLOW
|
9
|
+
# Color options: YELLOW,RED,GREEN,BLUE,MAGENTA,CYAN,WHITE
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slow
|
4
|
+
module Events
|
5
|
+
class Config
|
6
|
+
attr_reader :prefix
|
7
|
+
attr_reader :alert_duration
|
8
|
+
attr_reader :alert_color
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@prefix = 'Slow Event:'
|
12
|
+
@alert_color = Slow::Events::Format::YELLOW # Default: Red
|
13
|
+
@alert_duration = 500 # Default: 500ms
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_writer :prefix
|
17
|
+
|
18
|
+
def alert_color=(value)
|
19
|
+
@alert_color = value || Slow::Events::Format::YELLOW
|
20
|
+
end
|
21
|
+
|
22
|
+
def alert_duration=(value)
|
23
|
+
@alert_duration = [value, 50].max # Minimum: 50ms
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slow
|
4
|
+
module Events
|
5
|
+
class Format
|
6
|
+
CLEAR = "\e[0m"
|
7
|
+
BOLD = "\e[1m"
|
8
|
+
|
9
|
+
RED = "\e[31m"
|
10
|
+
GREEN = "\e[32m"
|
11
|
+
YELLOW = "\e[33m"
|
12
|
+
BLUE = "\e[34m"
|
13
|
+
MAGENTA = "\e[35m"
|
14
|
+
CYAN = "\e[36m"
|
15
|
+
WHITE = "\e[37m"
|
16
|
+
|
17
|
+
def self.build_message(duration, text)
|
18
|
+
[
|
19
|
+
CLEAR,
|
20
|
+
BOLD,
|
21
|
+
RED,
|
22
|
+
Slow::Events.config.prefix,
|
23
|
+
"(#{duration.round(2)}ms)",
|
24
|
+
Slow::Events.config.alert_color,
|
25
|
+
text,
|
26
|
+
CLEAR
|
27
|
+
].join(' ')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slow
|
4
|
+
module Events
|
5
|
+
class LogSubscriber < ::ActiveRecord::LogSubscriber
|
6
|
+
def sql(event)
|
7
|
+
return if event.duration < Slow::Events.config.alert_duration
|
8
|
+
|
9
|
+
debug Slow::Events::Format.build_message(event.duration, event.payload[:name] || event.payload[:sql] || 'Unknown')
|
10
|
+
end
|
11
|
+
|
12
|
+
attach_to :active_record
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/slow/events.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'events/version'
|
4
|
+
require_relative 'events/config'
|
5
|
+
require_relative 'events/format'
|
6
|
+
require_relative 'events/log_subscriber'
|
7
|
+
|
8
|
+
module Slow::Events
|
9
|
+
def self.config
|
10
|
+
@config ||= Slow::Events::Config.new
|
11
|
+
yield(@config) if block_given?
|
12
|
+
@config
|
13
|
+
end
|
14
|
+
end
|
data/slow-events.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/slow/events/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'slow-events'
|
7
|
+
spec.version = Slow::Events::VERSION
|
8
|
+
spec.authors = ['Khoa Nguyen']
|
9
|
+
spec.email = ['thanhkhoait@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Easy to see the Slow events in Rails logs'
|
12
|
+
spec.description = 'This GEM will support U in optimizing your Rails app, easy to see the slow events in the Rails log.'
|
13
|
+
spec.homepage = 'https://github.com/ThanhKhoaIT/slow-events'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ThanhKhoaIT/slow-events'
|
19
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, checkout our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slow-events
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Khoa Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This GEM will support U in optimizing your Rails app, easy to see the
|
14
|
+
slow events in the Rails log.
|
15
|
+
email:
|
16
|
+
- thanhkhoait@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- ".rubocop_todo.yml"
|
24
|
+
- ".ruby-version"
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- lib/generators/slow/events/config_generator.rb
|
32
|
+
- lib/generators/slow/templates/config.rb
|
33
|
+
- lib/slow/events.rb
|
34
|
+
- lib/slow/events/config.rb
|
35
|
+
- lib/slow/events/format.rb
|
36
|
+
- lib/slow/events/log_subscriber.rb
|
37
|
+
- lib/slow/events/version.rb
|
38
|
+
- slow-events.gemspec
|
39
|
+
homepage: https://github.com/ThanhKhoaIT/slow-events
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
homepage_uri: https://github.com/ThanhKhoaIT/slow-events
|
44
|
+
source_code_uri: https://github.com/ThanhKhoaIT/slow-events
|
45
|
+
changelog_uri: https://github.com/ThanhKhoaIT/slow-events
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.1.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Easy to see the Slow events in Rails logs
|
65
|
+
test_files: []
|