peek-moped 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/app/views/peek/views/_moped.html.erb +73 -0
- data/lib/peek-moped.rb +3 -0
- data/lib/peek-moped/railtie.rb +6 -0
- data/lib/peek-moped/version.rb +5 -0
- data/lib/peek/views/moped.rb +90 -0
- data/peek-moped.gemspec +23 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7693b846d58f7952cd6b0ed8d8350e8a98844560
|
4
|
+
data.tar.gz: dbadd3408d0c5198785ff119bb7ef3bece208048
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02039cbfffc18799a8535ea0873b7ec870e30d39cd70d7480408cd47de653bf45340e14c659662ee34c03d2c540ee786ac43b6d02eab1583107598532e1618cf
|
7
|
+
data.tar.gz: a03cecc8c06663f083459d96c92da5874b5d89fb2dd4a35f489f0271a6f62c711ef31b2152bdf4500ca3fd37f04e3f1b6373a8502d6cb1ec4fd273e3c6480d12
|
data/.gitignore
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
*.rbc
|
2
|
+
*.sassc
|
3
|
+
.sass-cache
|
4
|
+
capybara-*.html
|
5
|
+
.rspec
|
6
|
+
.rvmrc
|
7
|
+
/.bundle
|
8
|
+
/vendor/bundle
|
9
|
+
/log/*
|
10
|
+
/tmp/*
|
11
|
+
/db/*.sqlite3
|
12
|
+
/public/system/*
|
13
|
+
/coverage/
|
14
|
+
/spec/tmp/*
|
15
|
+
**.orig
|
16
|
+
rerun.txt
|
17
|
+
pickle-email-*.html
|
18
|
+
.project
|
19
|
+
config/initializers/secret_token.rb
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pavel Chertorogov
|
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,39 @@
|
|
1
|
+
# Peek::Moped
|
2
|
+
|
3
|
+
Take a peek into the Mongoid and Moped commands made within your Rails application.
|
4
|
+
|
5
|
+
Things this peek view provides:
|
6
|
+
|
7
|
+
- Total number of Mongo commands called during the request
|
8
|
+
- The duration of the calls made during the request
|
9
|
+
- Profiling each command with app stacktrace
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'peek-moped'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install peek-moped
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Add the following to your `config/initializers/peek.rb`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Peek.into Peek::Views::Moped
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
<strong>
|
2
|
+
<span data-defer-to="<%= view.defer_key %>-duration">...</span>
|
3
|
+
/
|
4
|
+
<span data-defer-to="<%= view.defer_key %>-calls">...</span>
|
5
|
+
<a href="#" onclick="$('#moped_queries_log').slideToggle(); return false;">moped</a>
|
6
|
+
</strong>
|
7
|
+
|
8
|
+
<style>
|
9
|
+
#peek-moped-table {
|
10
|
+
color: #333;
|
11
|
+
font-weight: normal;
|
12
|
+
text-shadow: none;
|
13
|
+
}
|
14
|
+
#peek-moped-table td {
|
15
|
+
line-height: normal;
|
16
|
+
}
|
17
|
+
.peek-moped-num {
|
18
|
+
color: gray;
|
19
|
+
}
|
20
|
+
.peek-moped-code {
|
21
|
+
font-weight: bold;
|
22
|
+
}
|
23
|
+
.peek-moped-query-details, .peek-moped-query-stack {
|
24
|
+
display: none;
|
25
|
+
}
|
26
|
+
.peek-moped-query-opened {
|
27
|
+
background-color: #FFFFE0;
|
28
|
+
border: 2px solid #ffd495;
|
29
|
+
padding: 4px;
|
30
|
+
}
|
31
|
+
.peek-moped-query-opened .peek-moped-query-details, .peek-moped-query-opened .peek-moped-query-stack {
|
32
|
+
display: block;
|
33
|
+
white-space: pre;
|
34
|
+
}
|
35
|
+
.peek-moped-query-opened a {
|
36
|
+
font-weight: bold;
|
37
|
+
}
|
38
|
+
#moped_queries_log {
|
39
|
+
display:none;
|
40
|
+
position:absolute;
|
41
|
+
}
|
42
|
+
</style>
|
43
|
+
<div id="moped_queries_log">
|
44
|
+
<table cellpadding="3" id="peek-moped-table">
|
45
|
+
<% duration = view.duration %>
|
46
|
+
<% cmd_num = 0 %>
|
47
|
+
<% view.operations.each do |row| %>
|
48
|
+
<tr>
|
49
|
+
<td class="peek-moped-num"><%= row[0] %></td>
|
50
|
+
<td <%= row[1]/duration > 0.1 ? 'style=color:red':'' %>><%= "%.2fms" % (row[1] * 1000) %></td>
|
51
|
+
<td>
|
52
|
+
<% row[2].each do |cmd| %>
|
53
|
+
<div>
|
54
|
+
<% code_desc = view.op_code_info cmd.op_code %>
|
55
|
+
<span class="peek-moped-code" title="<%= code_desc[1] %>"><%= code_desc[0] %></span>
|
56
|
+
<a href="#" onclick="$(this).closest('div').toggleClass('peek-moped-query-opened'); return false;">
|
57
|
+
<%= cmd.full_collection_name %>
|
58
|
+
</a>
|
59
|
+
<div class="peek-moped-query-details"><%= cmd.to_yaml %></div>
|
60
|
+
<div class="peek-moped-query-stack"><b>APP STACK:</b><%= "\n#{row[3].join("\n")}" %></div>
|
61
|
+
</div>
|
62
|
+
<% end %>
|
63
|
+
</td>
|
64
|
+
</tr>
|
65
|
+
<% end %>
|
66
|
+
</table>
|
67
|
+
</div>
|
68
|
+
<% if false %>
|
69
|
+
<span data-defer-to="<%= view.defer_key %>-operations">...</span>
|
70
|
+
<% end %>
|
71
|
+
|
72
|
+
|
73
|
+
|
data/lib/peek-moped.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'moped'
|
2
|
+
require 'atomic'
|
3
|
+
|
4
|
+
class Moped::Node
|
5
|
+
class << self
|
6
|
+
attr_accessor :command_time, :command_count, :command_operations
|
7
|
+
end
|
8
|
+
self.command_count = Atomic.new(0)
|
9
|
+
self.command_time = Atomic.new(0)
|
10
|
+
self.command_operations = Atomic.new([])
|
11
|
+
|
12
|
+
def logging_with_peek(*args, &block)
|
13
|
+
start = Time.now
|
14
|
+
logging_without_peek(*args, &block)
|
15
|
+
ensure
|
16
|
+
duration = (Time.now - start)
|
17
|
+
Moped::Node.command_time.update { |value| value + duration }
|
18
|
+
Moped::Node.command_count.update { |value| value + 1 }
|
19
|
+
Moped::Node.command_operations.update { |value| value << [Moped::Node.command_count.get, duration, args[0], peek_app_backtrace] }
|
20
|
+
end
|
21
|
+
alias_method_chain :logging, :peek
|
22
|
+
|
23
|
+
def peek_app_backtrace
|
24
|
+
root_path = Rails.root.to_s
|
25
|
+
caller.grep(%r{^#{root_path}/(app|lib)}) { |v| v.sub(root_path, '') }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Peek
|
30
|
+
module Views
|
31
|
+
class Moped < View
|
32
|
+
OP_CODES = {
|
33
|
+
'1' => ['*', 'Reply to a client request. responseTo is set'],
|
34
|
+
'1000' => ['*', 'Generic msg command followed by a string'],
|
35
|
+
'2001' => ['U', 'Update document'],
|
36
|
+
'2002' => ['I', 'Insert new document'],
|
37
|
+
'2003' => ['*', 'Formerly used for OP_GET_BY_OID'],
|
38
|
+
'2004' => ['R', 'Query a collection'],
|
39
|
+
'2005' => ['RR','Get more data from a query'],
|
40
|
+
'2006' => ['D', 'Delete documents'],
|
41
|
+
'2007' => ['*', 'Tell database client is done with a cursor']
|
42
|
+
}
|
43
|
+
|
44
|
+
def duration
|
45
|
+
::Moped::Node.command_time.value
|
46
|
+
end
|
47
|
+
|
48
|
+
def op_code_info op_code
|
49
|
+
key = op_code.to_s
|
50
|
+
if OP_CODES.has_key? key
|
51
|
+
OP_CODES[key]
|
52
|
+
else
|
53
|
+
[key, 'Undescribed op_code of mongodb wired protocol']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def formatted_duration
|
58
|
+
ms = duration * 1000
|
59
|
+
if ms >= 1000
|
60
|
+
"%.2fms" % ms
|
61
|
+
else
|
62
|
+
"%.0fms" % ms
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def calls
|
67
|
+
::Moped::Node.command_count.value
|
68
|
+
end
|
69
|
+
|
70
|
+
def operations
|
71
|
+
::Moped::Node.command_operations.value
|
72
|
+
end
|
73
|
+
|
74
|
+
def results
|
75
|
+
{ :duration => formatted_duration, :calls => calls, :operations => operations.inspect }
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def setup_subscribers
|
81
|
+
# Reset each counter when a new request starts
|
82
|
+
before_request do
|
83
|
+
::Moped::Node.command_time.value = 0
|
84
|
+
::Moped::Node.command_count.value = 0
|
85
|
+
::Moped::Node.command_operations.value = []
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/peek-moped.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'peek-moped/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'peek-moped'
|
8
|
+
gem.version = Peek::Moped::VERSION
|
9
|
+
gem.authors = ['Pavel Chertorogov']
|
10
|
+
gem.email = ['pavel.chertorogov@gmail.com']
|
11
|
+
gem.description = %q{Take a peek into the Moped and Mongoid commands made within your Rails application.}
|
12
|
+
gem.summary = %q{Take a peek into the Moped and Mongoid commands made within your Rails application.}
|
13
|
+
gem.homepage = 'https://github.com/nodkz/peek-moped'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'peek'
|
21
|
+
gem.add_dependency 'moped', '>= 1.5.1'
|
22
|
+
gem.add_dependency 'atomic', '>= 1.0.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: peek-moped
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Chertorogov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: peek
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: moped
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.5.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: atomic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
description: Take a peek into the Moped and Mongoid commands made within your Rails
|
56
|
+
application.
|
57
|
+
email:
|
58
|
+
- pavel.chertorogov@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- CHANGELOG.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- app/views/peek/views/_moped.html.erb
|
70
|
+
- lib/peek-moped.rb
|
71
|
+
- lib/peek-moped/railtie.rb
|
72
|
+
- lib/peek-moped/version.rb
|
73
|
+
- lib/peek/views/moped.rb
|
74
|
+
- peek-moped.gemspec
|
75
|
+
homepage: https://github.com/nodkz/peek-moped
|
76
|
+
licenses: []
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.1.11
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Take a peek into the Moped and Mongoid commands made within your Rails application.
|
98
|
+
test_files: []
|