redis_web_manager 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +17 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +17 -0
  7. data/Gemfile.lock +162 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +29 -0
  10. data/Rakefile +28 -0
  11. data/app/assets/config/redis_web_manager_manifest.js +2 -0
  12. data/app/assets/javascripts/redis_web_manager/application.js +19 -0
  13. data/app/assets/javascripts/redis_web_manager/bootstrap.js +6 -0
  14. data/app/assets/javascripts/redis_web_manager/chartjs.js +7 -0
  15. data/app/assets/javascripts/redis_web_manager/dashboard.js +246 -0
  16. data/app/assets/javascripts/redis_web_manager/jquery.js +2 -0
  17. data/app/assets/javascripts/redis_web_manager/keys.js +14 -0
  18. data/app/assets/javascripts/redis_web_manager/popper.js +4 -0
  19. data/app/assets/stylesheets/redis_web_manager/application.css +15 -0
  20. data/app/assets/stylesheets/redis_web_manager/bootstrap.css +6 -0
  21. data/app/assets/stylesheets/redis_web_manager/dashboard.css +28 -0
  22. data/app/controllers/redis_web_manager/actions_controller.rb +11 -0
  23. data/app/controllers/redis_web_manager/application_controller.rb +31 -0
  24. data/app/controllers/redis_web_manager/clients_controller.rb +12 -0
  25. data/app/controllers/redis_web_manager/configuration_controller.rb +12 -0
  26. data/app/controllers/redis_web_manager/dashboard_controller.rb +14 -0
  27. data/app/controllers/redis_web_manager/information_controller.rb +18 -0
  28. data/app/helpers/redis_web_manager/application_helper.rb +13 -0
  29. data/app/helpers/redis_web_manager/clients_helper.rb +35 -0
  30. data/app/helpers/redis_web_manager/dashboard_helper.rb +20 -0
  31. data/app/views/layouts/redis_web_manager/application.html.erb +17 -0
  32. data/app/views/redis_web_manager/clients/index.html.erb +58 -0
  33. data/app/views/redis_web_manager/configuration/index.html.erb +24 -0
  34. data/app/views/redis_web_manager/dashboard/index.html.erb +49 -0
  35. data/app/views/redis_web_manager/information/index.html.erb +24 -0
  36. data/app/views/redis_web_manager/shared/_header.html.erb +49 -0
  37. data/app/views/redis_web_manager/shared/_status.html.erb +6 -0
  38. data/bin/rails +20 -0
  39. data/config/routes.rb +19 -0
  40. data/gemfiles/Gemfile-5-2 +5 -0
  41. data/gemfiles/Gemfile-6-0 +5 -0
  42. data/lib/redis_web_manager.rb +35 -0
  43. data/lib/redis_web_manager/action.rb +21 -0
  44. data/lib/redis_web_manager/base.rb +11 -0
  45. data/lib/redis_web_manager/connection.rb +31 -0
  46. data/lib/redis_web_manager/data.rb +55 -0
  47. data/lib/redis_web_manager/engine.rb +21 -0
  48. data/lib/redis_web_manager/info.rb +69 -0
  49. data/lib/redis_web_manager/version.rb +5 -0
  50. data/redis_web_manager.gemspec +42 -0
  51. data/spec/controllers/redis_web_manager/actions_controller_spec.rb +13 -0
  52. data/spec/controllers/redis_web_manager/application_controller_spec.rb +29 -0
  53. data/spec/controllers/redis_web_manager/clients_controller_spec.rb +14 -0
  54. data/spec/controllers/redis_web_manager/configuration_controller_spec.rb +14 -0
  55. data/spec/controllers/redis_web_manager/dashboard_controller_spec.rb +14 -0
  56. data/spec/controllers/redis_web_manager/information_controller_spec.rb +14 -0
  57. data/spec/dummy/Rakefile +8 -0
  58. data/spec/dummy/app/assets/config/manifest.js +4 -0
  59. data/spec/dummy/app/assets/javascripts/application.js +14 -0
  60. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  62. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  63. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  64. data/spec/dummy/bin/bundle +5 -0
  65. data/spec/dummy/bin/rails +6 -0
  66. data/spec/dummy/bin/rake +6 -0
  67. data/spec/dummy/bin/setup +27 -0
  68. data/spec/dummy/bin/update +27 -0
  69. data/spec/dummy/config.ru +7 -0
  70. data/spec/dummy/config/application.rb +23 -0
  71. data/spec/dummy/config/boot.rb +7 -0
  72. data/spec/dummy/config/environment.rb +7 -0
  73. data/spec/dummy/config/environments/development.rb +49 -0
  74. data/spec/dummy/config/environments/production.rb +79 -0
  75. data/spec/dummy/config/environments/test.rb +38 -0
  76. data/spec/dummy/config/initializers/application_controller_renderer.rb +9 -0
  77. data/spec/dummy/config/initializers/assets.rb +14 -0
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  79. data/spec/dummy/config/initializers/content_security_policy.rb +26 -0
  80. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  81. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  82. data/spec/dummy/config/initializers/inflections.rb +17 -0
  83. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  84. data/spec/dummy/config/initializers/wrap_parameters.rb +11 -0
  85. data/spec/dummy/config/locales/en.yml +33 -0
  86. data/spec/dummy/config/puma.rb +39 -0
  87. data/spec/dummy/config/routes.rb +5 -0
  88. data/spec/dummy/config/spring.rb +8 -0
  89. data/spec/dummy/public/404.html +67 -0
  90. data/spec/dummy/public/422.html +67 -0
  91. data/spec/dummy/public/500.html +66 -0
  92. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  93. data/spec/dummy/public/apple-touch-icon.png +0 -0
  94. data/spec/dummy/public/favicon.ico +0 -0
  95. data/spec/helpers/application_helper_spec.rb +15 -0
  96. data/spec/helpers/clients_helper_spec.rb +19 -0
  97. data/spec/helpers/dashboard_helper_spec.rb +15 -0
  98. data/spec/rails_helper.rb +50 -0
  99. data/spec/redis_web_manager_action_spec.rb +33 -0
  100. data/spec/redis_web_manager_connection_spec.rb +33 -0
  101. data/spec/redis_web_manager_info_spec.rb +90 -0
  102. data/spec/redis_web_manager_spec.rb +57 -0
  103. data/spec/routing/actions_controller_spec.rb +21 -0
  104. data/spec/routing/clients_controller_spec.rb +15 -0
  105. data/spec/routing/configuration_controller_spec.rb +15 -0
  106. data/spec/routing/dashboard_controller_spec.rb +15 -0
  107. data/spec/spec_helper.rb +96 -0
  108. metadata +619 -0
@@ -0,0 +1,6 @@
1
+ <div class="row my-4">
2
+ <div class="col-12">
3
+ <%= @url %>
4
+ <%= @status %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This command will automatically be run when you run "rails" with Rails gems
5
+ # installed from the root of your application.
6
+
7
+ ENGINE_ROOT = File.expand_path('..', __dir__)
8
+ ENGINE_PATH = File.expand_path('../lib/redis_web_manager/engine', __dir__)
9
+ APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
10
+
11
+ # Set up gems listed in the Gemfile.
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
13
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
14
+
15
+ require 'rails'
16
+ # Pick the frameworks you want:
17
+ require 'action_controller/railtie'
18
+ require 'action_view/railtie'
19
+ require 'sprockets/railtie'
20
+ require 'rails/engine/commands'
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ RedisWebManager::Engine.routes.draw do
4
+ # Configuration
5
+ get :configuration, to: 'configuration#index'
6
+
7
+ # Information
8
+ get :information, to: 'information#index'
9
+
10
+ # Clients
11
+ get :clients, to: 'clients#index'
12
+
13
+ # Actions
14
+ delete :flushdb, to: 'actions#flushdb'
15
+ delete :flushall, to: 'actions#flushall'
16
+
17
+ # Root
18
+ root 'dashboard#index'
19
+ end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 5.2'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 6.0'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis_web_manager/engine'
4
+ require 'redis_web_manager/base'
5
+ require 'redis_web_manager/action'
6
+ require 'redis_web_manager/connection'
7
+ require 'redis_web_manager/info'
8
+ require 'redis_web_manager/data'
9
+ require 'redis'
10
+
11
+ module RedisWebManager
12
+ mattr_accessor :redis, default: ::Redis.new
13
+ mattr_accessor :authenticate, default: nil
14
+ mattr_accessor :lifespan, default: 15.days
15
+
16
+ class << self
17
+ def configure
18
+ yield self if block_given?
19
+ check_attrs
20
+ end
21
+
22
+ private
23
+
24
+ def check_attrs
25
+ unless redis.is_a?(::Redis)
26
+ raise ArgumentError, 'Invalid Redis instance, use like that Redis.new'
27
+ end
28
+ unless lifespan.is_a?(::ActiveSupport::Duration)
29
+ raise ArgumentError, 'Invalid lifespan, use like that 15.days, 15.minutes etc'
30
+ end
31
+ valid = lifespan.to_i.positive?
32
+ raise ArgumentError, 'Invalid lifespan, value must be greater than 0' unless valid
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ class Action < Base
5
+ def flushall
6
+ redis.flushall
7
+ end
8
+
9
+ def flushdb
10
+ redis.flushdb
11
+ end
12
+
13
+ def del(key)
14
+ redis.del(key)
15
+ end
16
+
17
+ def rename(old_name, new_name)
18
+ redis.rename(old_name, new_name)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ class Base
5
+ private
6
+
7
+ def redis
8
+ @redis ||= RedisWebManager.redis
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ class Connection < Base
5
+ def host
6
+ @host ||= connection[:host]
7
+ end
8
+
9
+ def port
10
+ @port ||= connection[:port]
11
+ end
12
+
13
+ def db
14
+ @db ||= connection[:db]
15
+ end
16
+
17
+ def id
18
+ @id ||= connection[:id]
19
+ end
20
+
21
+ def location
22
+ @location ||= connection[:location]
23
+ end
24
+
25
+ private
26
+
27
+ def connection
28
+ @connection ||= redis.connection
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ class Data < Base
5
+ BASE = 'RedisWebManager'
6
+
7
+ def perform
8
+ now = Time.now.to_i
9
+ seconds = (now + lifespan.to_i) - now
10
+ redis.setex("#{BASE}_#{now}", seconds, serialize.to_json)
11
+ end
12
+
13
+ private
14
+
15
+ def serialize
16
+ {
17
+ date: Time.now,
18
+ memory: memory,
19
+ client: client,
20
+ cpu: cpu
21
+ }
22
+ end
23
+
24
+ def memory
25
+ {
26
+ used_memory: stats[:used_memory],
27
+ used_memory_rss: stats[:used_memory_rss],
28
+ used_memory_peak: stats[:used_memory_peak],
29
+ used_memory_overhead: stats[:used_memory_overhead],
30
+ used_memory_startup: stats[:used_memory_startup],
31
+ used_memory_dataset: stats[:used_memory_dataset]
32
+ }
33
+ end
34
+
35
+ def client
36
+ {
37
+ connected_clients: stats[:connected_clients],
38
+ blocked_clients: stats[:blocked_clients]
39
+ }
40
+ end
41
+
42
+ def cpu
43
+ {
44
+ used_cpu_sys: stats[:used_cpu_sys],
45
+ used_cpu_user: stats[:used_cpu_user],
46
+ used_cpu_sys_children: stats[:used_cpu_sys_children],
47
+ used_cpu_user_children: stats[:used_cpu_user_children]
48
+ }
49
+ end
50
+
51
+ def stats
52
+ @stats ||= redis.info.symbolize_keys
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace RedisWebManager
6
+
7
+ path = Engine.root.join('app', 'assets', 'config')
8
+ config.assets.precompile << "#{path}/redis_web_manager_manifest.js"
9
+
10
+ config.generators do |generate|
11
+ # Don't generate assets
12
+ generate.assets false
13
+
14
+ # Don't generate helper
15
+ generate.helper false
16
+
17
+ # Rspec
18
+ generate.test_framework :rspec
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ class Info < Base
5
+ def status
6
+ @status ||= redis.ping == 'PONG'
7
+ end
8
+
9
+ def stats
10
+ @stats ||= redis.info
11
+ end
12
+
13
+ def keys
14
+ @keys ||= redis.keys
15
+ end
16
+
17
+ def search(query)
18
+ redis.scan_each(match: "*#{query.downcase}*").to_a
19
+ end
20
+
21
+ def type(key)
22
+ redis.type(key)
23
+ end
24
+
25
+ def expire(key)
26
+ redis.ttl(key)
27
+ end
28
+
29
+ def memory_usage(key)
30
+ redis.memory(:usage, key)
31
+ end
32
+
33
+ def get(key)
34
+ redis.get(key)
35
+ end
36
+
37
+ def llen(key)
38
+ redis.llen(key)
39
+ end
40
+
41
+ def lrange(key, start, stop)
42
+ redis.lrange(key, start, stop)
43
+ end
44
+
45
+ def smembers(key)
46
+ redis.smembers(key)
47
+ end
48
+
49
+ def zrange(key, start, stop, options = {})
50
+ redis.zrange(key, start, stop, options)
51
+ end
52
+
53
+ def hgetall(key)
54
+ redis.hgetall(key)
55
+ end
56
+
57
+ def dbsize
58
+ @dbsize ||= redis.dbsize
59
+ end
60
+
61
+ def configuration
62
+ @configuration ||= redis.config(:get, '*')
63
+ end
64
+
65
+ def clients
66
+ @clients ||= redis.client(:list)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisWebManager
4
+ VERSION = '0.1.6'
5
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ # Maintain your gem's version:
6
+ require 'redis_web_manager/version'
7
+
8
+ # Describe your gem and declare its dependencies:
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'redis_web_manager'
11
+ spec.version = RedisWebManager::VERSION
12
+
13
+ spec.authors = ['Boris BRESCIANI', 'Benjamin DARCET', 'Olivier DUMAS', 'Sylvain KRAISIN']
14
+ spec.email = %w[boris2bresciani@gmail.com
15
+ b.darcet@gmail.com
16
+ dumas.olivier@outlook.fr
17
+ sylvain.kraisin@gmail.com]
18
+
19
+ spec.summary = 'Manage your Redis instance (See keys, memory used, connected client, etc...)'
20
+ spec.description = 'Manage your Redis instance (See keys, memory used, connected client, configuration, information)'
21
+ spec.homepage = 'https://github.com/OpenGems/redis_web_manager'
22
+ spec.license = 'MIT'
23
+
24
+ spec.metadata['homepage_uri'] = spec.homepage
25
+ spec.metadata['source_code_uri'] = spec.homepage
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0")
31
+ .reject { |f| f.match(%r{^(test|spec|features|images)/}) }
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+ spec.test_files = Dir['spec/**/*']
37
+
38
+ spec.add_development_dependency 'rspec-rails', '= 4.0.0.beta3'
39
+
40
+ spec.add_dependency 'rails', '>= 5.2', '< 7'
41
+ spec.add_dependency 'redis', '~> 4.1.0'
42
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RedisWebManager::ActionsController, type: :controller do
6
+ routes { RedisWebManager::Engine.routes }
7
+
8
+ describe 'DELETE #flushdb' do
9
+ end
10
+
11
+ describe 'DELETE #flushall' do
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RedisWebManager::ApplicationController, type: :controller do
6
+ describe 'Methods' do
7
+ it 'returns a raise value (authenticated?)' do
8
+ expect do
9
+ controller.send(:authenticated?)
10
+ end.to raise_error(LocalJumpError)
11
+ end
12
+
13
+ it 'returns a nil value (authenticate)' do
14
+ expect(controller.send(:authenticate)).to eql(nil)
15
+ end
16
+
17
+ it 'returns a Info class (info)' do
18
+ expect(controller.send(:info)).to be_a_kind_of(RedisWebManager::Info)
19
+ end
20
+
21
+ it 'returns a Connection class (connection)' do
22
+ expect(controller.send(:connection)).to be_a_kind_of(RedisWebManager::Connection)
23
+ end
24
+
25
+ it 'returns a Action class (action)' do
26
+ expect(controller.send(:action)).to be_a_kind_of(RedisWebManager::Action)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RedisWebManager::ClientsController, type: :controller do
6
+ routes { RedisWebManager::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ it 'returns a success response' do
10
+ get :index
11
+ expect(response).to be_successful
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RedisWebManager::ConfigurationController, type: :controller do
6
+ routes { RedisWebManager::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ it 'returns a success response' do
10
+ get :index
11
+ expect(response).to be_successful
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe RedisWebManager::DashboardController, type: :controller do
6
+ routes { RedisWebManager::Engine.routes }
7
+
8
+ describe 'GET #index' do
9
+ it 'returns a success response' do
10
+ get :index
11
+ expect(response).to be_successful
12
+ end
13
+ end
14
+ end