fiveruns-dash-activerecord 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -1
- data/VERSION.yml +1 -1
- data/lib/fiveruns-dash-activerecord.rb +1 -1
- data/lib/fiveruns/dash/activerecord.rb +25 -0
- data/lib/fiveruns/dash/recipes/activerecord.rb +35 -13
- data/test/activerecord_test.rb +115 -0
- data/test/test_helper.rb +12 -0
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -9,10 +9,30 @@ You'll need a Dash account before using this library.
|
|
9
9
|
This library is released as a gem from the official repository at http://github.com/fiveruns/dash-activerecord
|
10
10
|
|
11
11
|
sudo gem install fiveruns-dash-activerecord --source http://gems.github.com
|
12
|
+
|
13
|
+
== Configuration
|
14
|
+
|
15
|
+
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:
|
16
|
+
|
17
|
+
* For web applications, this is probably the total time of a request (ie, request_time)
|
18
|
+
* For daemons, this is likely a processing cycle (eg, proc_time)
|
19
|
+
|
20
|
+
Known issue: 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.
|
21
|
+
|
22
|
+
Note: The metric selected must be `marked', ie:
|
23
|
+
|
24
|
+
recipe.time :response_time, :method => 'Request#dispatch_action',
|
25
|
+
:mark => true
|
26
|
+
|
27
|
+
Example:
|
28
|
+
|
29
|
+
other_recipe.add_recipe :activerecord,
|
30
|
+
:url => 'http://dash.fiveruns.com',
|
31
|
+
:total_time => 'response_time'
|
12
32
|
|
13
33
|
== Usage
|
14
34
|
|
15
|
-
See the Dash Ruby support pages http://support.fiveruns.com/faqs/dash/ruby for information on how to use this library.
|
35
|
+
See the Dash Ruby support pages http://support.fiveruns.com/faqs/dash/ruby for more information on how to use this library.
|
16
36
|
|
17
37
|
== Authors
|
18
38
|
|
data/VERSION.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
# Stub for gem dependency schemes
|
2
|
-
require 'fiveruns/dash/
|
2
|
+
require 'fiveruns/dash/activerecord'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
gem 'fiveruns-dash-ruby'
|
2
|
+
require 'fiveruns/dash'
|
3
|
+
|
4
|
+
require 'fiveruns/dash/recipes/activerecord'
|
5
|
+
|
6
|
+
module Fiveruns::Dash::ActiveRecord
|
7
|
+
|
8
|
+
CLASS_METHODS = %w(
|
9
|
+
find find_by_sql
|
10
|
+
create create!
|
11
|
+
update_all
|
12
|
+
destroy destroy_all
|
13
|
+
delete delete_all
|
14
|
+
calculate
|
15
|
+
)
|
16
|
+
INSTANCE_METHODS = %w(
|
17
|
+
update
|
18
|
+
save save!
|
19
|
+
destroy
|
20
|
+
)
|
21
|
+
|
22
|
+
TARGETS = CLASS_METHODS.map { |m| "ActiveRecord::Base.#{m}" } + \
|
23
|
+
INSTANCE_METHODS.map { |m| "ActiveRecord::Base##{m}"}
|
24
|
+
|
25
|
+
end
|
@@ -1,19 +1,41 @@
|
|
1
|
-
require 'fiveruns/dash'
|
2
|
-
|
3
1
|
Fiveruns::Dash.register_recipe :activerecord, :url => 'http://dash.fiveruns.com' do |recipe|
|
4
|
-
# We need a way to get the total time for a request/operation so that we can
|
5
|
-
# calculate the relative percentage used by AR/DB. Default to "response_time" for the Rails
|
6
|
-
# recipe but daemons can set this constant to provide their own total time metric.
|
7
|
-
total_time = recipe.options[:ar_total_time] ? recipe.options[:ar_total_time] : "response_time"
|
8
2
|
|
9
|
-
recipe.time :
|
10
|
-
recipe.time :
|
3
|
+
recipe.time :db_time, 'Database Time', :methods => %w(ActiveRecord::ConnectionAdapters::AbstractAdapter#log)
|
4
|
+
recipe.time :ar_time, 'ActiveRecord Time', :methods => Fiveruns::Dash::ActiveRecord::TARGETS,
|
5
|
+
:reentrant => true
|
6
|
+
recipe.added do |settings|
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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 "Set FiveRuns Dash `activerecord' :total_time setting to #{total_time}"
|
15
|
+
# Limit timing
|
16
|
+
recipe.metrics.each do |metric|
|
17
|
+
if %w(db_time ar_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 :ar_util, 'ActiveRecord Utilization', :sources => ["ar_time", total_time] do |ar_time, all_time|
|
23
|
+
all_time == 0 ? 0 : (ar_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 `activerecord' 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-activerecord README"
|
35
|
+
].join("\n")
|
36
|
+
|
37
|
+
end
|
38
|
+
|
17
39
|
end
|
18
40
|
|
19
41
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.dirname(__FILE__) << "/test_helper"
|
2
|
+
|
3
|
+
Fiveruns::Dash.logger.level = Logger::FATAL
|
4
|
+
|
5
|
+
class ActiverecordTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
class TestModel < ActiveRecord::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestEngine
|
11
|
+
def doit
|
12
|
+
sleep 1
|
13
|
+
2.times do
|
14
|
+
t = TestModel.create!(:name => 'foo')
|
15
|
+
t.destroy
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def conn
|
20
|
+
TestModel.connection.execute("select sleep(1)")
|
21
|
+
end
|
22
|
+
|
23
|
+
def entry(meth)
|
24
|
+
send(meth)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
context "Metric" do
|
30
|
+
|
31
|
+
setup do
|
32
|
+
ActiveRecord::Base.configurations = { 'test' => { 'database' => 'test', 'adapter' => 'mysql', 'user' => 'root', 'hostname' => 'localhost' }}
|
33
|
+
ActiveRecord::Base.establish_connection('test')
|
34
|
+
ActiveRecord::Base.connection.execute("create table if not exists test_models (id integer PRIMARY KEY, name varchar(32) not null)")
|
35
|
+
ActiveRecord::Base.connection.execute("delete from test_models")
|
36
|
+
end
|
37
|
+
|
38
|
+
should "collect basic AR metrics" do
|
39
|
+
ar_scenario do
|
40
|
+
TestEngine.new.entry(:doit)
|
41
|
+
|
42
|
+
data = Fiveruns::Dash.session.data
|
43
|
+
# data.each do |hsh|
|
44
|
+
# puts "#{hsh[:name]}: #{hsh[:values].inspect}"
|
45
|
+
# end
|
46
|
+
|
47
|
+
assert metric('test_time', data) > 1.0
|
48
|
+
assert metric('ar_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
|
+
ar_scenario do
|
55
|
+
TestEngine.new.entry(:conn)
|
56
|
+
|
57
|
+
data = Fiveruns::Dash.session.data
|
58
|
+
# data.each do |hsh|
|
59
|
+
# puts "#{hsh[:name]}: #{hsh[:values].inspect}"
|
60
|
+
# end
|
61
|
+
|
62
|
+
assert metric('test_time', data) > 1.0
|
63
|
+
assert metric('test_time', data) < 1.1
|
64
|
+
assert metric('db_time', data) > 1.0
|
65
|
+
assert metric('db_time', data) < 1.1
|
66
|
+
assert metric('db_util', data) > 90.0
|
67
|
+
assert metric('db_util', data) < 100.0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def ar_scenario(&block)
|
73
|
+
child = fork do
|
74
|
+
mock_activerecord!
|
75
|
+
yield
|
76
|
+
end
|
77
|
+
Process.wait
|
78
|
+
assert_equal 0, $?.exitstatus
|
79
|
+
end
|
80
|
+
|
81
|
+
def metric(metric, data, context=[])
|
82
|
+
hash = data.detect { |hash| hash[:name] == metric }
|
83
|
+
assert hash, "No metric named #{metric} was found in metrics payload"
|
84
|
+
vals = hash[:values]
|
85
|
+
assert vals, "No values found for #{metric} in metrics payload"
|
86
|
+
val = vals.detect { |val| val[:context] == context }
|
87
|
+
assert val, "No value for #{metric} found for context #{context.inspect}"
|
88
|
+
val[:value]
|
89
|
+
end
|
90
|
+
|
91
|
+
def mock_activerecord!
|
92
|
+
|
93
|
+
eval <<-MOCK
|
94
|
+
module Fiveruns::Dash
|
95
|
+
class Reporter
|
96
|
+
private
|
97
|
+
def run
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
MOCK
|
102
|
+
|
103
|
+
Fiveruns::Dash.register_recipe :tester, :url => 'http://dash.fiveruns.com' do |recipe|
|
104
|
+
recipe.time :test_time, 'Test Time', :method => 'ActiverecordTest::TestEngine#entry',
|
105
|
+
:mark => true
|
106
|
+
end
|
107
|
+
|
108
|
+
Fiveruns::Dash.start :app => '666' do |config|
|
109
|
+
config.add_recipe :ruby
|
110
|
+
config.add_recipe :tester
|
111
|
+
config.add_recipe :activerecord, :total_time => 'test_time'
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiveruns-dash-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FiveRuns Development Team
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-19 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.8.
|
23
|
+
version: 0.8.1
|
24
24
|
version:
|
25
25
|
description: Provides an API to send metrics from applications using ActiveRecord to the FiveRuns Dash service
|
26
26
|
email: dev@fiveruns.com
|
@@ -35,9 +35,12 @@ files:
|
|
35
35
|
- VERSION.yml
|
36
36
|
- lib/fiveruns
|
37
37
|
- lib/fiveruns/dash
|
38
|
+
- lib/fiveruns/dash/activerecord.rb
|
38
39
|
- lib/fiveruns/dash/recipes
|
39
40
|
- lib/fiveruns/dash/recipes/activerecord.rb
|
40
41
|
- lib/fiveruns-dash-activerecord.rb
|
42
|
+
- test/activerecord_test.rb
|
43
|
+
- test/test_helper.rb
|
41
44
|
has_rdoc: true
|
42
45
|
homepage: http://github.com/fiveruns/dash-activerecord
|
43
46
|
post_install_message:
|