dalli-ui 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +35 -0
  4. data/app/assets/javascripts/dalli/ui/application.js +13 -0
  5. data/app/assets/stylesheets/dalli/ui/application.css +15 -0
  6. data/app/controllers/dalli/ui/application_controller.rb +6 -0
  7. data/app/controllers/dalli/ui/cache_controller.rb +34 -0
  8. data/app/views/dalli/ui/cache/index.html.erb +53 -0
  9. data/app/views/layouts/dalli/ui/application.html.erb +40 -0
  10. data/config/routes.rb +4 -0
  11. data/lib/dalli/ui.rb +7 -0
  12. data/lib/dalli/ui/engine.rb +7 -0
  13. data/lib/dalli/ui/stats_presenter.rb +56 -0
  14. data/lib/tasks/dalli_ui_tasks.rake +4 -0
  15. data/readme.md +27 -0
  16. data/test/dummy/README.rdoc +28 -0
  17. data/test/dummy/Rakefile +6 -0
  18. data/test/dummy/app/assets/javascripts/application.js +13 -0
  19. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  20. data/test/dummy/app/controllers/application_controller.rb +5 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  23. data/test/dummy/bin/bundle +3 -0
  24. data/test/dummy/bin/rails +4 -0
  25. data/test/dummy/bin/rake +4 -0
  26. data/test/dummy/config.ru +4 -0
  27. data/test/dummy/config/application.rb +23 -0
  28. data/test/dummy/config/boot.rb +5 -0
  29. data/test/dummy/config/database.yml +25 -0
  30. data/test/dummy/config/environment.rb +5 -0
  31. data/test/dummy/config/environments/development.rb +37 -0
  32. data/test/dummy/config/environments/production.rb +78 -0
  33. data/test/dummy/config/environments/test.rb +39 -0
  34. data/test/dummy/config/initializers/assets.rb +8 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  37. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  38. data/test/dummy/config/initializers/inflections.rb +16 -0
  39. data/test/dummy/config/initializers/mime_types.rb +4 -0
  40. data/test/dummy/config/initializers/session_store.rb +3 -0
  41. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  42. data/test/dummy/config/locales/en.yml +23 -0
  43. data/test/dummy/config/routes.rb +4 -0
  44. data/test/dummy/config/secrets.yml +22 -0
  45. data/test/dummy/db/test.sqlite3 +0 -0
  46. data/test/dummy/log/test.log +320 -0
  47. data/test/dummy/public/404.html +67 -0
  48. data/test/dummy/public/422.html +67 -0
  49. data/test/dummy/public/500.html +66 -0
  50. data/test/dummy/public/favicon.ico +0 -0
  51. data/test/fixtures/dalli_stats.json +52 -0
  52. data/test/presenters/stats_presenter_test.rb +28 -0
  53. data/test/test_helper.rb +9 -0
  54. metadata +234 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 351ef4201908c15cbff4ccd2e105df63749ac11e
4
+ data.tar.gz: eb3dee89f9b42b416a5fe8616e517bfcd40ec801
5
+ SHA512:
6
+ metadata.gz: d1ca82398d1355fa59cf92eed2bc76720535eee2a972417be1dcc7876afa06420e922314b9c5013bbc5959fd2588e5003d47a3cdf3ccda522dad6d489bb65225
7
+ data.tar.gz: 23353777c93aa6687ce2f053a7cd5493a778d07cde02785fe8abfe6fc2ee2939eed6f734c66d410754196ff4410a1ee49e86a37431475e26bed7a37355c2d62b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Pete Hawkins
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ require "bundler/gem_tasks"
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rdoc/task'
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'DalliUi'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.rdoc')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
19
+ load 'rails/tasks/engine.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,6 @@
1
+ module Dalli
2
+ module Ui
3
+ class ApplicationController < ActionController::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ require 'dalli/ui/stats_presenter'
2
+
3
+ module Dalli
4
+ module Ui
5
+ class CacheController < ApplicationController
6
+ layout "dalli/ui/application"
7
+
8
+ def index
9
+ @stats = wrap_presenters Rails.cache.dalli.stats
10
+ end
11
+
12
+ def flush
13
+ Rails.logger.info "Dalli::Ui Flushed Dalli cache store"
14
+ Rails.cache.dalli.flush
15
+
16
+ flash[:dalli_ui_notice] = "Flushed cache store"
17
+ redirect_to dalli_ui_path
18
+ end
19
+
20
+ private
21
+
22
+ def wrap_presenters(stats)
23
+ stats_presnters = {}
24
+
25
+ stats.each do |server, stats|
26
+ stats_presnters[server] = Dalli::Ui::StatsPresenter.new(stats, view_context)
27
+ end
28
+
29
+ stats_presnters
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ <% @stats.each do |host, stats| %>
2
+ <div class="page-header">
3
+ <h1><%= host %> <small>Stats</small></h1>
4
+ </div>
5
+
6
+ <div class="row">
7
+ <div class="col-md-6">
8
+ <canvas id="hit_rate_chart_<%= stats.host_id(host) %>"></canvas>
9
+ </div>
10
+
11
+ <div class="col-md-6">
12
+ <div class="table-responsive">
13
+ <table class="table">
14
+ <tr>
15
+ <th>Memcached instance size</th>
16
+ <td><%= stats.cache_size %></td>
17
+ </tr>
18
+ <tr>
19
+ <th>Hit rate</th>
20
+ <td><%= stats.hit_rate %>%</td>
21
+ </tr>
22
+ <tr>
23
+ <th>Total items</th>
24
+ <td><%= stats.dalli.total_items %></td>
25
+ </tr>
26
+ <tr>
27
+ <th>Current Connections</th>
28
+ <td><%= stats.dalli.curr_connections %></td>
29
+ </tr>
30
+ <tr>
31
+ <th>Total Connections</th>
32
+ <td><%= stats.dalli.total_connections %></td>
33
+ </tr>
34
+ </table>
35
+ </div>
36
+ </div>
37
+
38
+
39
+ </div>
40
+
41
+ <script type="text/javascript">
42
+ $(document).ready(function() {
43
+ var chart_context = document.getElementById("hit_rate_chart_<%= stats.host_id(host) %>").getContext("2d");
44
+
45
+ var data = <%== MultiJson.dump(stats.chart_data) %>;
46
+
47
+ var hit_rate_chart = new Chart(chart_context).Doughnut(data, {
48
+ responsive: true,
49
+ tooltipTemplate: "<%%if (label){%><%%=label%>: <%%}%><%%= value %>%",
50
+ });
51
+ });
52
+ </script>
53
+ <% end %>
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dalli UI</title>
5
+
6
+ <link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
7
+ <%= stylesheet_link_tag "dalli/ui/application", media: "all" %>
8
+
9
+ <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
10
+ <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js"></script>
11
+ <%= javascript_include_tag "dalli/ui/application" %>
12
+
13
+ <%= csrf_meta_tags %>
14
+ </head>
15
+ <body>
16
+
17
+ <nav class="navbar navbar-default navbar-fixed" role="navigation">
18
+ <div class="container">
19
+ <div class="navbar-header">
20
+ <a class="navbar-brand" href="#">Dalli UI</a>
21
+ </div>
22
+
23
+ <form action="<%= dalli_ui_flush_path %>" method="POST" class="navbar-form navbar-right">
24
+ <%= tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) %>
25
+ <input type="submit" value="Flush cache!" class="btn btn-danger">
26
+ </form>
27
+
28
+ </div><!-- /.container -->
29
+ </nav>
30
+
31
+ <% if flash[:dalli_ui_notice] %>
32
+ <div class="ui-notification"><p><%= flash[:dalli_ui_notice] %></p></div>
33
+ <% end %>
34
+
35
+ <div class="container">
36
+ <%= yield %>
37
+ </div>
38
+
39
+ </body>
40
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Dalli::Ui::Engine.routes.draw do
2
+ get "/" => "cache#index", as: :dalli_ui
3
+ post "/flush" => "cache#flush", as: :dalli_ui_flush
4
+ end
data/lib/dalli/ui.rb ADDED
@@ -0,0 +1,7 @@
1
+ require_relative "ui/engine"
2
+ require_relative "ui/stats_presenter"
3
+
4
+ module Dalli
5
+ module Ui
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Dalli
2
+ module Ui
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Dalli::Ui
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ require 'hashie'
2
+ require 'digest/sha1'
3
+
4
+ module Dalli
5
+ module Ui
6
+ class StatsPresenter
7
+ attr_accessor :dalli
8
+
9
+ def initialize(dalli_stats, template)
10
+ @dalli = Hashie::Mash.new(dalli_stats)
11
+ @template = template
12
+ end
13
+
14
+ def hit_rate
15
+ hit_rate = 0
16
+ total = Integer(dalli.get_hits) + Integer(dalli.get_misses)
17
+ hit_rate = Integer(dalli.get_hits).to_f / total.to_f * 100 if total > 0
18
+ hit_rate.round
19
+ end
20
+
21
+ def cache_size
22
+ h.number_to_human_size(dalli.limit_maxbytes)
23
+ end
24
+
25
+ def host_id(host)
26
+ Digest::SHA1.hexdigest host
27
+ end
28
+
29
+ def chart_data
30
+ [
31
+ {
32
+ value: 100 - hit_rate,
33
+ count: dalli.get_misses,
34
+ color: "#F7464A",
35
+ highlight: "#FF5A5E",
36
+ label: "Miss rate"
37
+ },
38
+ {
39
+ value: hit_rate,
40
+ count: dalli.get_hits,
41
+ color: "#46BFBD",
42
+ highlight: "#5AD3D1",
43
+ label: "Hit rate"
44
+ }
45
+ ]
46
+ end
47
+
48
+ private
49
+
50
+ def h
51
+ @template
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :dalli_ui do
3
+ # # Task goes here
4
+ # end
data/readme.md ADDED
@@ -0,0 +1,27 @@
1
+ # Dalli UI
2
+
3
+ Dalli UI is a mountable engine for Rails apps that displays information about your [dalli](https://github.com/mperham/dalli) memcached instance and allows you to flush it from a web interface.
4
+
5
+ ## Rails 4 installation
6
+
7
+ Add **dalli** and **dalli-ui** to your gemfile and `bundle install`.
8
+
9
+ ```rb
10
+ # Gemfile
11
+ gem 'dalli'
12
+ gem 'dalli-ui'
13
+ ```
14
+
15
+ Setup [dalli](https://github.com/mperham/dalli) as your Rails cache store.
16
+
17
+ ```rb
18
+ # config/application.rb
19
+ config.cache_store = :dalli_store
20
+ ```
21
+
22
+ Mount Dalli UI on a route of your choosing
23
+
24
+ ```rb
25
+ # config/routes.rb
26
+ mount Dalli::Ui::Engine, at: "dalli"
27
+ ```
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>