peek-memcached 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a99b91316f6239884a7c0d26a8600370026e8af9
4
+ data.tar.gz: 5668ba994c679b151630fe51d2ddc59bb54dfa81
5
+ SHA512:
6
+ metadata.gz: ebf53c3f92040b9e5dd4c05d8cdcdd3830c776b91d09460919b4cf41e8272381e06e7e8043ab9f11f7c2807283bba635cda90243b67a755f3ae59d280e408f51
7
+ data.tar.gz: 0514918af003d762bf38386ad59f9358edf18d51c195393586848ca18d5af5f4fb035078f2ab1a51f7e55e1166e8d600bc9d8dcc85aa6304b88eec589da89715
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ mkmf.log
16
+ vendor/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peek-memcached.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Masaki YOSHIDA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Peek::Memcached
2
+
3
+ Take a peek into the Memcache commands made through Memcached during your application's requests.
4
+
5
+ Thins this peek view provides:
6
+
7
+ * Total number of memcache commands called during the request
8
+ * The number of memcache `get` and hit commands called during the request
9
+ * The number of memcache `get` and miss commands called during the request
10
+ * The number of memcache `set` commands called during the request
11
+ * The duration of the commands made during the request
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'peek-memcached'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install peek-memcached
28
+
29
+ ## Usage
30
+
31
+ Add the following to your `config/initializers/peekrb`:
32
+
33
+ ```ruby
34
+ Peek.into Peek ::Views::Memcached
35
+ ```
36
+
37
+ There is an additional JavaScript file peek-memcached provides that gives additional infomation about the requests Memcached makes during the request:
38
+
39
+ * Get[HIT]
40
+ * Get[MISS]
41
+ * Set
42
+
43
+ Include the `peek/views/memcachced` JavaScript file in your application:
44
+
45
+ ```coffee
46
+ #= require peek
47
+ #= require peek/views/memcached
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/ReSTARTR/peek-memcached/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ $(document).on 'peek:render', (event, requestId, data) ->
2
+ title = []
3
+ title.push("Gets[HIT]: #{data.context.memcached.get_hits}")
4
+ title.push("Gets[MISS]: #{data.context.memcached.get_misses}")
5
+ title.push("Sets: #{data.context.memcached.sets}")
6
+
7
+ $('#peek-memcached-tooltip')
8
+ .attr('title', title.join('<br>'))
9
+ .tipsy
10
+ html: true
11
+ gravity: $.fn.tipsy.autoNS
@@ -0,0 +1 @@
1
+ <strong><span id="peek-memcached-tooltip"><span data-defer-to="<%= view.defer_key %>-duration">...</span> / <span data-defer-to="<%= view.defer_key %>-calls">...</span></span></strong> memcached
@@ -0,0 +1,92 @@
1
+ require 'memcached'
2
+ require 'atomic'
3
+
4
+ Memcached.class_eval do
5
+ class << self
6
+ attr_accessor :duration, :calls, :get_hits, :get_misses, :sets
7
+
8
+ def init_peek_stats
9
+ self.duration = Atomic.new(0)
10
+ self.calls = Atomic.new(0)
11
+ self.get_hits = Atomic.new(0)
12
+ self.get_misses = Atomic.new(0)
13
+ self.sets = Atomic.new(0)
14
+ end
15
+ end
16
+ self.init_peek_stats
17
+
18
+ alias :get_orig :get
19
+
20
+ def get(keys, decode=true)
21
+ start = Time.now
22
+ get_orig(keys, decode)
23
+ rescue Memcached::NotFound => e
24
+ hits = false
25
+ raise e
26
+ ensure
27
+ _duration = Time.now - start
28
+ self.class.duration.update { |v| v + _duration }
29
+ self.class.calls.update { |v| v + 1 }
30
+ if hits
31
+ self.class.get_hits.update { |v| v + 1 }
32
+ else
33
+ self.class.get_misses.update { |v| v + 1 }
34
+ end
35
+ end
36
+
37
+ alias :set_orig :set
38
+
39
+ def set(key, value, ttl=@default_ttl, encode=true, flags=::Memcached::FLAGS)
40
+ start = Time.now
41
+ set_orig(key, value, ttl, encode, flags)
42
+ ensure
43
+ _duration = Time.now - start
44
+ self.class.duration.update { |v| v + _duration }
45
+ self.class.calls.update { |v| v + 1 }
46
+ self.class.sets.update { |v| v + 1 }
47
+ end
48
+ end
49
+
50
+ require 'peek/views/view'
51
+
52
+ module Peek
53
+ module Views
54
+ class Memcached < View
55
+ def duration
56
+ ::Memcached.duration.value
57
+ end
58
+
59
+ def formatted_duration
60
+ ms = duration * 1000
61
+ if ms >= 1000
62
+ '%.2fms' % ms
63
+ else
64
+ '%.0fms' % ms
65
+ end
66
+ end
67
+
68
+ def context
69
+ {
70
+ :get_hits => ::Memcached.get_hits.value,
71
+ :get_misses => ::Memcached.get_misses.value,
72
+ :sets => ::Memcached.sets.value,
73
+ }
74
+ end
75
+
76
+ def results
77
+ {
78
+ :duration => formatted_duration,
79
+ :calls => ::Memcached.calls.value,
80
+ }
81
+ end
82
+
83
+ private
84
+
85
+ def setup_subscribers
86
+ before_request do
87
+ ::Memcached.init_peek_stats
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+
3
+ module Peek
4
+ module Memcached
5
+ class Railtie < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Peek
2
+ module Memcached
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'peek/views/memcached'
2
+ require 'peek-memcached/version'
3
+ require 'peek-memcached/railtie'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'peek-memcached/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "peek-memcached"
8
+ spec.version = Peek::Memcached::VERSION
9
+ spec.authors = ["Masaki YOSHIDA"]
10
+ spec.email = ["yoshida@vasily.jp"]
11
+ spec.summary = %q{Take a peek into the Memcached calls made within your Rails application.}
12
+ spec.description = %q{Take a peek into the Memcached calls made within your Rails application.}
13
+ spec.homepage = "http://github.com/ReSTARTR/peek-memcached"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "peek"
24
+ spec.add_dependency "memcached"
25
+ spec.add_dependency "atomic", '>= 1.0.0'
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'peek-memcached'
2
+ require 'minitest/autorun'
3
+
4
+ class MemcachedTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ Memcached.init_peek_stats
7
+ @memcached = Memcached.new
8
+ @memcached.flush
9
+ end
10
+
11
+ def test_get_and_miss
12
+ assert_raises(::Memcached::NotFound) do
13
+ @memcached.get('foo')
14
+ end
15
+ ensure
16
+ assert_equal 1, Memcached.calls.value
17
+ assert_equal 0, Memcached.get_hits.value
18
+ assert_equal 1, Memcached.get_misses.value
19
+ assert_equal 0, Memcached.sets.value
20
+ end
21
+
22
+ def test_get_and_hit
23
+ @memcached.set('foo', 99)
24
+ result = @memcached.get('foo')
25
+ assert_equal 99, result
26
+ rescue ::Memcached::NotFound
27
+ assert_equal 1, Memcached.calls.value
28
+ assert_equal 1, Memcached.get_hits.value
29
+ assert_equal 0, Memcached.get_misses.value
30
+ assert_equal 1, Memcached.sets.value
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'minitest/unit'
4
+
5
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peek-memcached
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masaki YOSHIDA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: peek
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: memcached
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: atomic
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
83
+ description: Take a peek into the Memcached calls made within your Rails application.
84
+ email:
85
+ - yoshida@vasily.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - app/assets/javascripts/peek/views/memcached.coffee
96
+ - app/views/peek/views/memcached.html.erb
97
+ - lib/peek-memcached.rb
98
+ - lib/peek-memcached/railtie.rb
99
+ - lib/peek-memcached/version.rb
100
+ - lib/peek/views/memcached.rb
101
+ - peek-memcached.gemspec
102
+ - test/peek/views/memcached_test.rb
103
+ - test/test_helper.rb
104
+ homepage: http://github.com/ReSTARTR/peek-memcached
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.14
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Take a peek into the Memcached calls made within your Rails application.
128
+ test_files:
129
+ - test/peek/views/memcached_test.rb
130
+ - test/test_helper.rb