system-metrics 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/views/layouts/system_metrics/metrics.html.erb +12 -8
- data/lib/system_metrics.rb +1 -0
- data/lib/system_metrics/async_store.rb +57 -0
- data/lib/system_metrics/config.rb +1 -1
- data/lib/system_metrics/version.rb +1 -1
- data/public/stylesheets/app.css +18 -2
- data/spec/system_metrics/async_store_spec.rb +50 -0
- data/spec/system_metrics/store_spec.rb +1 -1
- metadata +5 -2
@@ -15,17 +15,21 @@
|
|
15
15
|
</head>
|
16
16
|
<body>
|
17
17
|
<div class="container">
|
18
|
-
<div id="
|
19
|
-
<
|
20
|
-
|
18
|
+
<div id="top">
|
19
|
+
<div id="hd">
|
20
|
+
<h1>System Metrics</h1>
|
21
|
+
<%= render "menu" %>
|
22
|
+
</div>
|
21
23
|
</div>
|
22
|
-
<%= render "title_bar" %>
|
23
24
|
<div id="bd">
|
24
|
-
<%=
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
<%= render "title_bar" %>
|
26
|
+
<div id="content">
|
27
|
+
<%= yield %>
|
28
|
+
</div>
|
28
29
|
</div>
|
29
30
|
</div>
|
31
|
+
<div id="ft">
|
32
|
+
<span>Developed by <a href="http://www.nearinfinity.com">Near Infinity</a></span>
|
33
|
+
</div>
|
30
34
|
</body>
|
31
35
|
</html>
|
data/lib/system_metrics.rb
CHANGED
@@ -4,6 +4,7 @@ module SystemMetrics
|
|
4
4
|
autoload :Middleware, 'system_metrics/middleware'
|
5
5
|
autoload :NestedEvent, 'system_metrics/nested_event'
|
6
6
|
autoload :Store, 'system_metrics/store'
|
7
|
+
autoload :AsyncStore, 'system_metrics/async_store'
|
7
8
|
autoload :Version, 'system_metrics/version'
|
8
9
|
|
9
10
|
def self.collection_on
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module SystemMetrics
|
4
|
+
class AsyncStore
|
5
|
+
|
6
|
+
# An instrumenter that does not send notifications. This is used in the
|
7
|
+
# AsyncStore so saving events does not send any notifications, not even
|
8
|
+
# for logging.
|
9
|
+
class VoidInstrumenter < ::ActiveSupport::Notifications::Instrumenter
|
10
|
+
def instrument(name, payload={})
|
11
|
+
yield(payload) if block_given?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@queue = Queue.new
|
17
|
+
@thread = Thread.new do
|
18
|
+
set_void_instrumenter
|
19
|
+
consume
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def save(events)
|
24
|
+
@queue << events
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
def set_void_instrumenter
|
29
|
+
Thread.current[:"instrumentation_#{notifier.object_id}"] = VoidInstrumenter.new(notifier)
|
30
|
+
end
|
31
|
+
|
32
|
+
def notifier
|
33
|
+
ActiveSupport::Notifications.notifier
|
34
|
+
end
|
35
|
+
|
36
|
+
def consume
|
37
|
+
while events = @queue.pop
|
38
|
+
root_event = SystemMetrics::NestedEvent.arrange(events, :presort => false)
|
39
|
+
root_model = create_metric(root_event)
|
40
|
+
root_model.update_attributes(:request_id => root_model.id)
|
41
|
+
save_tree(root_event.children, root_model.id, root_model.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def save_tree(events, request_id, parent_id)
|
46
|
+
events.each do |event|
|
47
|
+
model = create_metric(event, :request_id => request_id, :parent_id => parent_id)
|
48
|
+
save_tree(event.children, request_id, model.id)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_metric(event, merge_params={})
|
53
|
+
SystemMetrics::Metric.create(event.to_hash.merge(merge_params))
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -3,7 +3,7 @@ module SystemMetrics
|
|
3
3
|
attr_accessor :store, :instruments, :notification_exclude_patterns, :path_exclude_patterns
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
self.store = SystemMetrics::
|
6
|
+
self.store = SystemMetrics::AsyncStore.new
|
7
7
|
self.notification_exclude_patterns = []
|
8
8
|
self.path_exclude_patterns = [/system\/metrics/, /system_metrics/]
|
9
9
|
self.instruments = [
|
data/public/stylesheets/app.css
CHANGED
@@ -3,7 +3,6 @@ body {
|
|
3
3
|
font-family: "Helvetica Neue",Arial,Helvetica,sans-serif;
|
4
4
|
font-size: 75%;
|
5
5
|
line-height: 150%;
|
6
|
-
background-color: #FAD08A;
|
7
6
|
margin: 0 auto;
|
8
7
|
max-width: 100%;
|
9
8
|
width: 100%;
|
@@ -29,14 +28,28 @@ h1, h2, h3, h4, h5, h6 {
|
|
29
28
|
|
30
29
|
#container {
|
31
30
|
height: 100%;
|
31
|
+
margin-bottom: -46px;
|
32
32
|
min-height: 100%;
|
33
33
|
}
|
34
34
|
|
35
|
+
#top {
|
36
|
+
position: fixed;
|
37
|
+
top: 0;
|
38
|
+
width: 100%;
|
39
|
+
z-index: 2;
|
40
|
+
}
|
41
|
+
|
35
42
|
#bd {
|
36
|
-
padding:
|
43
|
+
padding-bottom: 46px;
|
44
|
+
position: relative;
|
45
|
+
top: 40px;
|
37
46
|
background-color: #FAFCFF;
|
38
47
|
}
|
39
48
|
|
49
|
+
#content {
|
50
|
+
padding: 20px;
|
51
|
+
}
|
52
|
+
|
40
53
|
tr {
|
41
54
|
height: 45px;
|
42
55
|
}
|
@@ -50,6 +63,7 @@ div.clear {
|
|
50
63
|
}
|
51
64
|
|
52
65
|
#hd {
|
66
|
+
clear: both;
|
53
67
|
top: 0;
|
54
68
|
width: 100%;
|
55
69
|
height: 40px;
|
@@ -147,6 +161,8 @@ div.clear {
|
|
147
161
|
text-align: center;
|
148
162
|
text-shadow: 0 -1px 0 #FBDAA2;
|
149
163
|
width: 100%;
|
164
|
+
position: fixed;
|
165
|
+
bottom: 0;
|
150
166
|
z-index: 2;
|
151
167
|
-moz-box-shadow: 0 1px 0 #FCE3BB inset;
|
152
168
|
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'system_metrics/metric'
|
3
|
+
|
4
|
+
describe SystemMetrics::AsyncStore do
|
5
|
+
include NotificationsSupport
|
6
|
+
|
7
|
+
describe '#save' do
|
8
|
+
it 'should save an array of events hierarchically' do
|
9
|
+
parent = event(:start => Time.now - 10.seconds, :end => Time.now)
|
10
|
+
child = event(:start => Time.now - 9.seconds, :end => Time.now - 1.seconds)
|
11
|
+
grandchild = event(:start => Time.now - 8.seconds, :end => Time.now - 2.seconds)
|
12
|
+
|
13
|
+
store = SystemMetrics::AsyncStore.new
|
14
|
+
|
15
|
+
lambda {
|
16
|
+
store.save([grandchild, child, parent])
|
17
|
+
sleep(0.1)
|
18
|
+
}.should change(SystemMetrics::Metric, :count).by(3)
|
19
|
+
|
20
|
+
metrics = SystemMetrics::Metric.all
|
21
|
+
verify_equal(parent, metrics[0])
|
22
|
+
verify_equal(child, metrics[0].children[0])
|
23
|
+
verify_equal(grandchild, metrics[0].children[0].children[0])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should not attempt to save anything if passed an empty array of events' do
|
27
|
+
store = SystemMetrics::AsyncStore.new
|
28
|
+
lambda { store.save([]); sleep(0.1) }.should_not change(SystemMetrics::Metric, :count)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should not attempt to save anything if passed a nil' do
|
32
|
+
store = SystemMetrics::AsyncStore.new
|
33
|
+
lambda { store.save(nil); sleep(0.1) }.should_not change(SystemMetrics::Metric, :count)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def verify_equal(event, metric)
|
40
|
+
event.name.should == metric.name
|
41
|
+
event.action.should == metric.action
|
42
|
+
event.category.should == metric.category
|
43
|
+
event.transaction_id.should == metric.transaction_id
|
44
|
+
event.payload.should == metric.payload
|
45
|
+
event.started_at.should be_within(1).of(metric.started_at)
|
46
|
+
event.duration.should be_within(1).of(metric.duration)
|
47
|
+
event.exclusive_duration.should be_within(1).of(metric.exclusive_duration)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -11,7 +11,7 @@ describe SystemMetrics::Store do
|
|
11
11
|
grandchild = event(:start => Time.now - 8.seconds, :end => Time.now - 2.seconds)
|
12
12
|
|
13
13
|
store = SystemMetrics::Store.new
|
14
|
-
|
14
|
+
|
15
15
|
lambda {
|
16
16
|
store.save([grandchild, child, parent])
|
17
17
|
}.should change(SystemMetrics::Metric, :count).by(3)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: system-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Kunkle
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-18 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/generators/system_metrics/migration/templates/migration.rb
|
90
90
|
- lib/system-metrics.rb
|
91
91
|
- lib/system_metrics.rb
|
92
|
+
- lib/system_metrics/async_store.rb
|
92
93
|
- lib/system_metrics/collector.rb
|
93
94
|
- lib/system_metrics/config.rb
|
94
95
|
- lib/system_metrics/engine.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- spec/support/test_logger.rb
|
118
119
|
- spec/support/test_store.rb
|
119
120
|
- spec/support/transactional_specs.rb
|
121
|
+
- spec/system_metrics/async_store_spec.rb
|
120
122
|
- spec/system_metrics/collector_spec.rb
|
121
123
|
- spec/system_metrics/config_spec.rb
|
122
124
|
- spec/system_metrics/engine_spec.rb
|
@@ -167,6 +169,7 @@ test_files:
|
|
167
169
|
- spec/support/test_logger.rb
|
168
170
|
- spec/support/test_store.rb
|
169
171
|
- spec/support/transactional_specs.rb
|
172
|
+
- spec/system_metrics/async_store_spec.rb
|
170
173
|
- spec/system_metrics/collector_spec.rb
|
171
174
|
- spec/system_metrics/config_spec.rb
|
172
175
|
- spec/system_metrics/engine_spec.rb
|