fiveruns-dash-datamapper 0.6.0
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.
- data/README.rdoc +90 -0
- data/VERSION.yml +4 -0
- data/lib/fiveruns-dash-datamapper.rb +2 -0
- data/lib/fiveruns/dash/datamapper.rb +11 -0
- data/lib/fiveruns/dash/recipes/datamapper.rb +41 -0
- data/test/datamapper_test.rb +111 -0
- data/test/test_helper.rb +15 -0
- metadata +63 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
= FiveRuns Dash recipe for DataMapper
|
|
2
|
+
|
|
3
|
+
Provides a Ruby API to push metrics from applications using DataMapper to the FiveRuns Dash service, http://dash.fiveruns.com, currently in beta.
|
|
4
|
+
|
|
5
|
+
You'll need a Dash account before using this library.
|
|
6
|
+
|
|
7
|
+
== Installation
|
|
8
|
+
|
|
9
|
+
This library is released as a gem from the official repository at http://github.com/fiveruns/dash-datamapper
|
|
10
|
+
|
|
11
|
+
sudo gem install fiveruns-dash-datamapper --source http://gems.github.com
|
|
12
|
+
|
|
13
|
+
== Compatibility
|
|
14
|
+
|
|
15
|
+
Currently only DataObject adapters are supported.
|
|
16
|
+
|
|
17
|
+
== Configuration
|
|
18
|
+
|
|
19
|
+
Metrics in this recipe require a 'total_time' option be provided when the recipe is added; this option should indicate the metric to use when calculating % of utilization:
|
|
20
|
+
|
|
21
|
+
* For web applications, this is probably the total time of a request (ie, request_time)
|
|
22
|
+
* For daemons, this is likely a processing cycle (eg, proc_time)
|
|
23
|
+
|
|
24
|
+
Known issues: The metric name is not currently namespaced by recipe URL; although collision is unlikely, if your 'total_time' setting is for a metric that's present in more than one recipe, you may encounter problems.
|
|
25
|
+
|
|
26
|
+
Note: The metric selected must be `marked', ie:
|
|
27
|
+
|
|
28
|
+
recipe.time :response_time, :method => 'Request#dispatch_action',
|
|
29
|
+
:mark => true
|
|
30
|
+
Example:
|
|
31
|
+
|
|
32
|
+
other_recipe.add_recipe :datamapper,
|
|
33
|
+
:url => 'http://dash.fiveruns.com',
|
|
34
|
+
:total_time => 'response_time'
|
|
35
|
+
|
|
36
|
+
== Usage
|
|
37
|
+
|
|
38
|
+
See the Dash Ruby support pages http://support.fiveruns.com/faqs/dash/ruby for more information on how to use this library.
|
|
39
|
+
|
|
40
|
+
== Authors
|
|
41
|
+
|
|
42
|
+
The FiveRuns Development Team & Dash community
|
|
43
|
+
|
|
44
|
+
== Dependencies
|
|
45
|
+
|
|
46
|
+
* The fiveruns-dash-ruby gem (see http://github.com/fiveruns/dash-ruby)
|
|
47
|
+
* The json gem (as a dependency for fiveruns-dash-ruby)
|
|
48
|
+
|
|
49
|
+
== Platforms
|
|
50
|
+
|
|
51
|
+
This library has only been tested on OSX and Linux. See the notes for fiveruns-dash-ruby for more information: http://github.com/fiveruns/dash-ruby
|
|
52
|
+
|
|
53
|
+
== Contributing
|
|
54
|
+
|
|
55
|
+
As an open source project, we welcome community contributions!
|
|
56
|
+
|
|
57
|
+
The best way to contribute is by sending pull requests via GitHub. The official repository for this project is:
|
|
58
|
+
|
|
59
|
+
http://github.com/fiveruns/dash-datamapper
|
|
60
|
+
|
|
61
|
+
== Support
|
|
62
|
+
|
|
63
|
+
Please join the dash-users Google group, http://groups.google.com/group/dash-users
|
|
64
|
+
|
|
65
|
+
You can also contact us via Twitter, Campfire, or email; see the main help page, http://support.fiveruns.com, for details.
|
|
66
|
+
|
|
67
|
+
== License
|
|
68
|
+
|
|
69
|
+
# (The FiveRuns License)
|
|
70
|
+
#
|
|
71
|
+
# Copyright (c) 2006-2008 FiveRuns Corporation
|
|
72
|
+
#
|
|
73
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
74
|
+
# a copy of this software and associated documentation files (the
|
|
75
|
+
# 'Software'), to deal in the Software without restriction, including
|
|
76
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
77
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
78
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
79
|
+
# the following conditions:
|
|
80
|
+
#
|
|
81
|
+
# The above copyright notice and this permission notice shall be
|
|
82
|
+
# included in all copies or substantial portions of the Software.
|
|
83
|
+
#
|
|
84
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
86
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
87
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
88
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
89
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
90
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION.yml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
gem 'fiveruns-dash-ruby'
|
|
2
|
+
require 'fiveruns/dash'
|
|
3
|
+
|
|
4
|
+
require 'fiveruns/dash/recipes/datamapper'
|
|
5
|
+
|
|
6
|
+
module Fiveruns::Dash::DataMapper
|
|
7
|
+
DB_TARGETS = %w(DataMapper::Adapters::DataObjectsAdapter#execute)
|
|
8
|
+
ORM_TARGETS = %w(read_many read_one update delete).map do |meth|
|
|
9
|
+
"DataMapper::Repository##{meth}"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Fiveruns::Dash.register_recipe :datamapper, :url => 'http://dash.fiveruns.com' do |recipe|
|
|
2
|
+
|
|
3
|
+
recipe.time :db_time, 'Database Time', :methods => Fiveruns::Dash::DataMapper::DB_TARGETS
|
|
4
|
+
recipe.time :orm_time, 'DataMapper Time', :methods => Fiveruns::Dash::DataMapper::ORM_TARGETS,
|
|
5
|
+
:reentrant => true
|
|
6
|
+
recipe.added do |settings|
|
|
7
|
+
|
|
8
|
+
# We need a way to get the total time for a request/operation so that we can
|
|
9
|
+
# calculate the relative percentage used by AR/DB.
|
|
10
|
+
if settings[:total_time]
|
|
11
|
+
|
|
12
|
+
total_time = settings[:total_time].to_s
|
|
13
|
+
|
|
14
|
+
Fiveruns::Dash.logger.debug "Limiting FiveRuns Dash DataMapper metrics to within #{total_time}"
|
|
15
|
+
# Limit timing
|
|
16
|
+
recipe.metrics.each do |metric|
|
|
17
|
+
if %w(db_time orm_time).include?(metric.name) && metric.recipe.url == 'http://dash.fiveruns.com'
|
|
18
|
+
metric.options[:only_within] = total_time
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
recipe.percentage :orm_util, 'DataMapper Utilization', :sources => ["orm_time", total_time] do |orm_time, all_time|
|
|
23
|
+
all_time == 0 ? 0 : (orm_time / all_time) * 100.0
|
|
24
|
+
end
|
|
25
|
+
recipe.percentage :db_util, 'Database Utilization', :sources => ["db_time", total_time] do |db_time, all_time|
|
|
26
|
+
all_time == 0 ? 0 : (db_time / all_time) * 100.0
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
else
|
|
30
|
+
|
|
31
|
+
Fiveruns::Dash.logger.error [
|
|
32
|
+
"Could not add some metrics from the FiveRuns Dash `datamapper' recipe to the configuration;",
|
|
33
|
+
"Please provide a :total_time metric name setting when adding the recipe.",
|
|
34
|
+
"For more information, see the fiveruns-dash-datamapper README"
|
|
35
|
+
].join("\n")
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require File.dirname(__FILE__) << "/test_helper"
|
|
2
|
+
|
|
3
|
+
Fiveruns::Dash.logger.level = Logger::FATAL
|
|
4
|
+
|
|
5
|
+
class DataMapperTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
class TestModel
|
|
8
|
+
include DataMapper::Resource
|
|
9
|
+
property :id, Serial
|
|
10
|
+
property :name, String
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class TestEngine
|
|
14
|
+
def doit
|
|
15
|
+
sleep 1
|
|
16
|
+
2.times do
|
|
17
|
+
t = TestModel.create(:name => 'foo')
|
|
18
|
+
t.destroy
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def conn
|
|
23
|
+
# FIXME: We need a way to suspend execution temporarily
|
|
24
|
+
# for a specific w/in the DB; sqlite doesn't support sleep()
|
|
25
|
+
# ... otherwise we need to mock `execute'
|
|
26
|
+
TestModel.repository.adapter.execute("select sleep(1)")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def entry(meth)
|
|
30
|
+
send(meth)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
context "Metric" do
|
|
36
|
+
|
|
37
|
+
setup do
|
|
38
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
|
39
|
+
DataMapper.auto_migrate!
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should "collect basic ORM metrics" do
|
|
43
|
+
scenario do
|
|
44
|
+
TestEngine.new.entry(:doit)
|
|
45
|
+
|
|
46
|
+
data = Fiveruns::Dash.session.data
|
|
47
|
+
assert metric('test_time', data) > 1.0
|
|
48
|
+
assert metric('orm_util', data) > metric('db_util', data)
|
|
49
|
+
assert metric('db_util', data) < 5
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should "collect DB metrics" do
|
|
54
|
+
scenario do
|
|
55
|
+
TestEngine.new.entry(:conn)
|
|
56
|
+
|
|
57
|
+
data = Fiveruns::Dash.session.data
|
|
58
|
+
assert metric('test_time', data) > 1.0
|
|
59
|
+
assert metric('test_time', data) < 1.1
|
|
60
|
+
assert metric('db_time', data) > 1.0
|
|
61
|
+
assert metric('db_time', data) < 1.1
|
|
62
|
+
assert metric('db_util', data) > 90.0
|
|
63
|
+
assert metric('db_util', data) < 100.0
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def scenario(&block)
|
|
69
|
+
child = fork do
|
|
70
|
+
mock_datamapper!
|
|
71
|
+
yield
|
|
72
|
+
end
|
|
73
|
+
Process.wait
|
|
74
|
+
assert_equal 0, $?.exitstatus
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def metric(metric, data, context=[])
|
|
78
|
+
hash = data.detect { |hash| hash[:name] == metric }
|
|
79
|
+
assert hash, "No metric named #{metric} was found in metrics payload"
|
|
80
|
+
vals = hash[:values]
|
|
81
|
+
assert vals, "No values found for #{metric} in metrics payload"
|
|
82
|
+
val = vals.detect { |val| val[:context] == context }
|
|
83
|
+
assert val, "No value for #{metric} found for context #{context.inspect}"
|
|
84
|
+
val[:value]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def mock_datamapper!
|
|
88
|
+
|
|
89
|
+
eval <<-MOCK
|
|
90
|
+
module Fiveruns::Dash
|
|
91
|
+
class Reporter
|
|
92
|
+
private
|
|
93
|
+
def run
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
MOCK
|
|
98
|
+
|
|
99
|
+
Fiveruns::Dash.register_recipe :tester, :url => 'http://dash.fiveruns.com' do |recipe|
|
|
100
|
+
recipe.time :test_time, 'Test Time', :method => 'DataMapperTest::TestEngine#entry',
|
|
101
|
+
:mark => true
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
Fiveruns::Dash.start :app => '666' do |config|
|
|
105
|
+
config.add_recipe :ruby
|
|
106
|
+
config.add_recipe :tester
|
|
107
|
+
config.add_recipe :datamapper, :total_time => 'test_time'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'datamapper'
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) << "/../lib")
|
|
5
|
+
require 'fiveruns/dash/datamapper'
|
|
6
|
+
|
|
7
|
+
require 'test/unit'
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
require 'redgreen'
|
|
11
|
+
rescue LoadError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
require 'activerecord'
|
|
15
|
+
require 'shoulda'
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fiveruns-dash-datamapper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.6.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- FiveRuns Development Team
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-02-22 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Provides an API to send metrics from applications using DataMapper to the FiveRuns Dash service
|
|
17
|
+
email: dev@fiveruns.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- README.rdoc
|
|
26
|
+
- VERSION.yml
|
|
27
|
+
- lib/fiveruns
|
|
28
|
+
- lib/fiveruns/dash
|
|
29
|
+
- lib/fiveruns/dash/datamapper.rb
|
|
30
|
+
- lib/fiveruns/dash/recipes
|
|
31
|
+
- lib/fiveruns/dash/recipes/datamapper.rb
|
|
32
|
+
- lib/fiveruns-dash-datamapper.rb
|
|
33
|
+
- test/datamapper_test.rb
|
|
34
|
+
- test/test_helper.rb
|
|
35
|
+
has_rdoc: true
|
|
36
|
+
homepage: http://github.com/fiveruns/dash-datamapper
|
|
37
|
+
post_install_message:
|
|
38
|
+
rdoc_options:
|
|
39
|
+
- --inline-source
|
|
40
|
+
- --charset=UTF-8
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: "0"
|
|
48
|
+
version:
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "0"
|
|
54
|
+
version:
|
|
55
|
+
requirements: []
|
|
56
|
+
|
|
57
|
+
rubyforge_project:
|
|
58
|
+
rubygems_version: 1.2.0
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 2
|
|
61
|
+
summary: FiveRuns Dash recipe for DataMapper
|
|
62
|
+
test_files: []
|
|
63
|
+
|