redis_monitor 0.0.4 → 0.0.5

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: 6375769808ae00a232eee7ef5d3041bbf59a87d3
4
- data.tar.gz: 438135f40a526ce33941500707572cac3b96aa97
3
+ metadata.gz: 79092e09550d8bcba8120074790e62443fd811ab
4
+ data.tar.gz: add45fdc52392f1f031555b680509f587ad7224b
5
5
  SHA512:
6
- metadata.gz: 73887e219724b5898ac8d1220a617865d58893df6078aa7af8e2ea2c5d257310cd1f6274132d248ad3475cdc272667373dbc542b9fe47cb5b935895ca92ece09
7
- data.tar.gz: e08e9cebbfe515692dbf3ad48da2c095c235a7caf00f2abc4d723ae30cd0701bc7cb7b1b58a52063947b48bcc87e6f967a2519cd9c05bf09d7c94104d620c083
6
+ metadata.gz: 2e1da2f8ffa882d255f841ee2420c92ca5dd2e0064a4d503be353d95069aa972683767d668fcde2891dce2dac3da570d9b9f280a5896ebe774275b06f049eb74
7
+ data.tar.gz: eaf4029ffd01a860eca9f4006a484e3f2c631a9afceac765ab8392d47fd9e83e9452e102c61378a0c3a077e49488d36246c820f12d183953503b6fcb3435fbd9
@@ -14,9 +14,9 @@ module RedisMonitor
14
14
  @params = opts
15
15
  end
16
16
 
17
- def execute(action)
17
+ def execute(action, params = {})
18
18
  begin
19
- send(action)
19
+ send(action, params)
20
20
  rescue RedisMonitor::Errors::RedisNotAvailable
21
21
  redis_not_available
22
22
  end
@@ -0,0 +1,19 @@
1
+
2
+ module RedisMonitor
3
+ module Controllers
4
+ class ContentController < BaseController
5
+ include RedisMonitor::Helpers::LayoutsHelper
6
+
7
+ SECTION = 'content'
8
+
9
+ def index(params = {})
10
+ haml 'content/index'.to_sym, layout: main_layout, locals: {section: SECTION}
11
+ end
12
+
13
+ def search(params = {})
14
+ results = Backend.search(params[:key])
15
+ haml 'content/search'.to_sym, layout: main_layout, locals: {results: results, section: SECTION}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -4,8 +4,10 @@ module RedisMonitor
4
4
  class InfoController < BaseController
5
5
  include RedisMonitor::Helpers::LayoutsHelper
6
6
 
7
- def index
8
- haml 'info/info'.to_sym, layout: main_layout, locals: {info: Backend.info, section: 'info'}
7
+ SECTION = 'info'
8
+
9
+ def index(params={})
10
+ haml 'info/info'.to_sym, layout: main_layout, locals: {info: Backend.info, section: SECTION}
9
11
  end
10
12
  end
11
13
  end
@@ -4,13 +4,15 @@ module RedisMonitor
4
4
  class PerformanceController < BaseController
5
5
  include RedisMonitor::Helpers::LayoutsHelper
6
6
 
7
- def warning
8
- haml 'performance/warning'.to_sym, layout: main_layout, locals: {section: 'performance'}
7
+ SECTION = 'performance'
8
+
9
+ def warning(params = {})
10
+ haml 'performance/warning'.to_sym, layout: main_layout, locals: {section: SECTION}
9
11
  end
10
12
 
11
- def check
13
+ def check(params = {})
12
14
  stats = Backend.performance_stats
13
- haml 'performance/check'.to_sym, layout: main_layout, locals: {stats: stats, section: 'performance'}
15
+ haml 'performance/check'.to_sym, layout: main_layout, locals: {stats: stats, section: SECTION}
14
16
  end
15
17
 
16
18
  end
@@ -5,19 +5,22 @@ module RedisMonitor
5
5
  'layouts/main'.to_sym
6
6
  end
7
7
 
8
- def selected_section(section, selected)
8
+ def selected_is_selected(section, selected)
9
9
  'active' if section == selected
10
10
  end
11
11
 
12
+ def section(opts = {})
13
+ haml_tag :li, class: selected_is_selected(opts[:name], opts[:selected_section]) do
14
+ haml_tag :a, opts[:title], href: opts[:url]
15
+ end
16
+ end
17
+
12
18
  def content_menu(selected_section)
13
19
  capture_haml do
14
20
  haml_tag :ul, class: 'nav navbar-nav' do
15
- haml_tag :li, class: selected_section('info', selected_section) do
16
- haml_tag :a, 'Info', href: '/info'
17
- end
18
- haml_tag :li, class: selected_section('performance', selected_section) do
19
- haml_tag :a, 'Performance', href: '/performance'
20
- end
21
+ section(name: 'info', title: 'Info', url: '/info', selected_section: selected_section)
22
+ section(name: 'content', title: 'Content', url: '/content', selected_section: selected_section)
23
+ section(name: 'performance', title: 'Performance', url: '/performance', selected_section: selected_section)
21
24
  end
22
25
  end
23
26
  end
@@ -7,7 +7,7 @@ module RedisMonitor
7
7
  class Backend
8
8
  extend SingleForwardable
9
9
 
10
- def_delegators :redis, :get, :set, :del, :info, :keys, :dbsize
10
+ def_delegators :redis, :get, :set, :del, :info, :keys, :dbsize, :monitor
11
11
 
12
12
  def self.config(arguments)
13
13
  @@host = arguments[:redis_host]
@@ -29,5 +29,9 @@ module RedisMonitor
29
29
  def self.performance_stats
30
30
  PerformanceStats.new(self).results
31
31
  end
32
+
33
+ def self.search(key)
34
+ keys(key).map{|found| {key: found, value: get(found)} }
35
+ end
32
36
  end
33
37
  end
@@ -1,3 +1,4 @@
1
1
  require 'controllers/base_controller'
2
2
  require 'controllers/info_controller'
3
+ require 'controllers/content_controller'
3
4
  require 'controllers/performance_controller'
@@ -7,11 +7,14 @@ module RedisMonitor
7
7
 
8
8
  def self.included(server)
9
9
  server.get('/'){ redirect '/info' }
10
- server.get('/info'){ InfoController.new(context: self).execute(:index) }
10
+ server.get('/info'){ InfoController.new(context: self).execute(:index, params) }
11
+
12
+ server.get('/content'){ ContentController.new(context: self).execute(:index, params) }
13
+ server.get('/content/search'){ ContentController.new(context: self).execute(:search, params) }
11
14
 
12
15
  server.get('/performance'){ redirect '/performance/warning' }
13
- server.get('/performance/warning'){ PerformanceController.new(context: self).execute(:warning) }
14
- server.get('/performance/check'){ PerformanceController.new(context: self).execute(:check) }
16
+ server.get('/performance/warning'){ PerformanceController.new(context: self).execute(:warning, params) }
17
+ server.get('/performance/check'){ PerformanceController.new(context: self).execute(:check, params) }
15
18
  end
16
19
  end
17
20
  end
@@ -1,3 +1,3 @@
1
1
  module RedisMonitor
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -0,0 +1,10 @@
1
+ - search_term ||= nil
2
+
3
+ %form{action: '/content/search', method: 'get', style: 'margin-top: 5px'}
4
+ .form-group
5
+ %label{for: 'input_key'}
6
+ Introduce search terms (wildcards allowed)
7
+ %input.form-control{type: 'text', id: 'input_key', name: 'key', placeholder: 'Search terms', value: search_term}
8
+ .form-group
9
+ %button.btn.btn-default{type: 'submit'}
10
+ Search
@@ -0,0 +1 @@
1
+ = haml 'content/_search_form'.to_sym
@@ -0,0 +1,17 @@
1
+ = haml 'content/_search_form'.to_sym, locals: {search_term: params[:key]}
2
+
3
+ %table.table.table-striped
4
+ %thead
5
+ %tr
6
+ %th
7
+ Key
8
+ %th
9
+ Value
10
+
11
+ %tbody
12
+ - results.each do |result|
13
+ %tr
14
+ %td
15
+ = result[:key]
16
+ %td
17
+ = result[:value]
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe ContentController do
4
+ before :each do
5
+ @context = double(:context)
6
+ @controller = ContentController.new(context: @context)
7
+ end
8
+
9
+ describe 'index action' do
10
+ it 'should render index template' do
11
+ @context.should_receive(:haml).with('content/index'.to_sym, anything)
12
+ @controller.index
13
+ end
14
+ end
15
+
16
+ describe 'search action' do
17
+ it 'should render search template' do
18
+ Backend.stub(:search){ {} }
19
+ @context.should_receive(:haml).with('content/search'.to_sym, anything)
20
+ @controller.search
21
+ end
22
+ end
23
+ end
@@ -24,4 +24,23 @@ describe Backend do
24
24
  Backend.performance_stats.should be_kind_of(Hash)
25
25
  end
26
26
  end
27
+
28
+ describe 'search' do
29
+ let(:keys){ ['k1', 'k2', 'k3'] }
30
+
31
+ before :each do
32
+ Backend.stub(:keys){ keys }
33
+ Backend.stub(:get){ 'value' }
34
+ end
35
+
36
+ it 'should return an array of hashes' do
37
+ Backend.search('*').should be_kind_of(Array)
38
+ Backend.search('*')[0].should be_kind_of(Hash)
39
+ end
40
+
41
+ it 'every entry should have key and value data' do
42
+ Backend.search('*')[0][:key].should_not be_nil
43
+ Backend.search('*')[0][:value].should_not be_nil
44
+ end
45
+ end
27
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Jimenez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-26 00:00:00.000000000 Z
11
+ date: 2013-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -124,6 +124,7 @@ files:
124
124
  - Rakefile
125
125
  - bin/redis_monitor
126
126
  - lib/controllers/base_controller.rb
127
+ - lib/controllers/content_controller.rb
127
128
  - lib/controllers/info_controller.rb
128
129
  - lib/controllers/performance_controller.rb
129
130
  - lib/errors/errors.rb
@@ -143,6 +144,9 @@ files:
143
144
  - lib/static/scripts/jquery-2.0.3.min.js
144
145
  - lib/static/styles/bootstrap.min.css
145
146
  - lib/static/styles/custom.css
147
+ - lib/views/content/_search_form.haml
148
+ - lib/views/content/index.haml
149
+ - lib/views/content/search.haml
146
150
  - lib/views/errors/redis_not_available.haml
147
151
  - lib/views/info/info.haml
148
152
  - lib/views/layouts/main.haml
@@ -150,6 +154,7 @@ files:
150
154
  - lib/views/performance/warning.haml
151
155
  - redis_monitor.gemspec
152
156
  - spec/controllers/base_controller_spec.rb
157
+ - spec/controllers/content_controller_spec.rb
153
158
  - spec/controllers/info_controller_spec.rb
154
159
  - spec/controllers/performance_controller_spec.rb
155
160
  - spec/modules/backend_spec.rb
@@ -182,6 +187,7 @@ specification_version: 4
182
187
  summary: Get general information of a running redis instance
183
188
  test_files:
184
189
  - spec/controllers/base_controller_spec.rb
190
+ - spec/controllers/content_controller_spec.rb
185
191
  - spec/controllers/info_controller_spec.rb
186
192
  - spec/controllers/performance_controller_spec.rb
187
193
  - spec/modules/backend_spec.rb