simple_metrics 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/populate +2 -2
- data/lib/simple_metrics/app.rb +5 -89
- data/lib/simple_metrics/bucket.rb +25 -99
- data/lib/simple_metrics/configuration.rb +24 -6
- data/lib/simple_metrics/data_point/counter.rb +7 -0
- data/lib/simple_metrics/data_point/event.rb +4 -0
- data/lib/simple_metrics/data_point/gauge.rb +6 -0
- data/lib/simple_metrics/data_point/timing.rb +3 -0
- data/lib/simple_metrics/data_point.rb +1 -17
- data/lib/simple_metrics/data_point_repository.rb +11 -28
- data/lib/simple_metrics/graph.rb +37 -21
- data/lib/simple_metrics/importer.rb +90 -0
- data/lib/simple_metrics/metric.rb +2 -1
- data/lib/simple_metrics/public/js/application.js +4 -4
- data/lib/simple_metrics/repository.rb +4 -4
- data/lib/simple_metrics/udp_server.rb +1 -1
- data/lib/simple_metrics/version.rb +1 -1
- data/lib/simple_metrics/views/layout.erb +1 -1
- data/lib/simple_metrics.rb +1 -2
- data/spec/array_aggregation_spec.rb +8 -8
- data/spec/bucket_spec.rb +7 -104
- data/spec/data_point_repository_spec.rb +9 -46
- data/spec/graph_spec.rb +33 -4
- data/spec/importer_spec.rb +126 -0
- data/spec/spec_helper.rb +1 -1
- metadata +33 -34
- data/lib/simple_metrics/update_aggregation.rb +0 -62
- data/lib/simple_metrics/value_aggregation.rb +0 -63
- data/spec/value_aggregation_spec.rb +0 -52
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70191513973620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70191513973620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70191513972880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70191513972880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rr
|
38
|
-
requirement: &
|
38
|
+
requirement: &70191513972300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70191513972300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shotgun
|
49
|
-
requirement: &
|
49
|
+
requirement: &70191513971780 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70191513971780
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: eventmachine
|
60
|
-
requirement: &
|
60
|
+
requirement: &70191513971140 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70191513971140
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: daemons
|
71
|
-
requirement: &
|
71
|
+
requirement: &70191513970580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70191513970580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: mongo
|
82
|
-
requirement: &
|
82
|
+
requirement: &70191513969960 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '1.6'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70191513969960
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: bson
|
93
|
-
requirement: &
|
93
|
+
requirement: &70191513985680 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '1.6'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70191513985680
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: bson_ext
|
104
|
-
requirement: &
|
104
|
+
requirement: &70191513985040 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '1.6'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70191513985040
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sinatra
|
115
|
-
requirement: &
|
115
|
+
requirement: &70191513984480 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70191513984480
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: erubis
|
126
|
-
requirement: &
|
126
|
+
requirement: &70191513983800 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ! '>='
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *70191513983800
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: vegas
|
137
|
-
requirement: &
|
137
|
+
requirement: &70191513983000 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ~>
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 0.1.2
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *70191513983000
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: json
|
148
|
-
requirement: &
|
148
|
+
requirement: &70191513982480 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,7 +153,7 @@ dependencies:
|
|
153
153
|
version: '0'
|
154
154
|
type: :runtime
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *70191513982480
|
157
157
|
description: SimpleMetrics
|
158
158
|
email:
|
159
159
|
- fdietz@gmail.com
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/simple_metrics/data_point_repository.rb
|
191
191
|
- lib/simple_metrics/functions.rb
|
192
192
|
- lib/simple_metrics/graph.rb
|
193
|
+
- lib/simple_metrics/importer.rb
|
193
194
|
- lib/simple_metrics/metric.rb
|
194
195
|
- lib/simple_metrics/metric_repository.rb
|
195
196
|
- lib/simple_metrics/public/css/bootstrap-responsive.min.css
|
@@ -208,8 +209,6 @@ files:
|
|
208
209
|
- lib/simple_metrics/public/js/underscore-1.3.1.min.js
|
209
210
|
- lib/simple_metrics/repository.rb
|
210
211
|
- lib/simple_metrics/udp_server.rb
|
211
|
-
- lib/simple_metrics/update_aggregation.rb
|
212
|
-
- lib/simple_metrics/value_aggregation.rb
|
213
212
|
- lib/simple_metrics/version.rb
|
214
213
|
- lib/simple_metrics/views/graph.erb
|
215
214
|
- lib/simple_metrics/views/index.erb
|
@@ -221,9 +220,9 @@ files:
|
|
221
220
|
- spec/data_point_repository_spec.rb
|
222
221
|
- spec/data_point_spec.rb
|
223
222
|
- spec/graph_spec.rb
|
223
|
+
- spec/importer_spec.rb
|
224
224
|
- spec/metric_repository_spec.rb
|
225
225
|
- spec/spec_helper.rb
|
226
|
-
- spec/value_aggregation_spec.rb
|
227
226
|
homepage: ''
|
228
227
|
licenses: []
|
229
228
|
post_install_message:
|
@@ -238,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
238
237
|
version: '0'
|
239
238
|
segments:
|
240
239
|
- 0
|
241
|
-
hash:
|
240
|
+
hash: 878091864515966970
|
242
241
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
243
242
|
none: false
|
244
243
|
requirements:
|
@@ -247,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
246
|
version: '0'
|
248
247
|
segments:
|
249
248
|
- 0
|
250
|
-
hash:
|
249
|
+
hash: 878091864515966970
|
251
250
|
requirements: []
|
252
251
|
rubyforge_project:
|
253
252
|
rubygems_version: 1.8.15
|
@@ -260,6 +259,6 @@ test_files:
|
|
260
259
|
- spec/data_point_repository_spec.rb
|
261
260
|
- spec/data_point_spec.rb
|
262
261
|
- spec/graph_spec.rb
|
262
|
+
- spec/importer_spec.rb
|
263
263
|
- spec/metric_repository_spec.rb
|
264
264
|
- spec/spec_helper.rb
|
265
|
-
- spec/value_aggregation_spec.rb
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module SimpleMetrics
|
2
|
-
module UpdateAggregation
|
3
|
-
extend self
|
4
|
-
|
5
|
-
class Base
|
6
|
-
def aggregate(existing_dp, dp)
|
7
|
-
raise "subclass must implement me!"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Counter < Base
|
12
|
-
def aggregate(existing_dp, dp)
|
13
|
-
existing_dp.total += 1
|
14
|
-
existing_dp.value += dp.value
|
15
|
-
existing_dp.sum += dp.value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Gauge < Base
|
20
|
-
def aggregate(existing_dp, dp)
|
21
|
-
existing_dp.total += 1
|
22
|
-
existing_dp.sum += dp.value
|
23
|
-
existing_dp.value = existing_dp.sum / existing_dp.total
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class Timing < Base
|
28
|
-
def aggregate(existing_dp, dp)
|
29
|
-
# TODO implement timing
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Event < Base
|
34
|
-
def aggregate(existing_dp, dp)
|
35
|
-
# TODO implement event
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def aggregate(existing_dp, dp)
|
40
|
-
raise SimpleMetrics::DataPoint::NonMatchingTypesError if existing_dp.type != dp.type
|
41
|
-
strategy(existing_dp).aggregate(existing_dp, dp)
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def strategy(dp)
|
47
|
-
if dp.counter?
|
48
|
-
Counter.new
|
49
|
-
elsif dp.gauge?
|
50
|
-
Gauge.new
|
51
|
-
elsif dp.timing?
|
52
|
-
Timing.new
|
53
|
-
elsif dp.event?
|
54
|
-
Event.new
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def has_non_matching_types?(dps)
|
59
|
-
dps.group_by { |dp| dp.type }.size != 1
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module SimpleMetrics
|
2
|
-
module ValueAggregation
|
3
|
-
extend self
|
4
|
-
|
5
|
-
class Base
|
6
|
-
def aggregate(dps)
|
7
|
-
raise "subclass must implement me!"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Counter < Base
|
12
|
-
def aggregate(dps)
|
13
|
-
dps.map { |dp| dp.value }.inject(0) { |result, value| result += value }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Gauge < Base
|
18
|
-
def aggregate(dps)
|
19
|
-
total_value = dps.map { |dp| dp.value }.inject(0) { |result, value| result += value }
|
20
|
-
total_value / dps.size
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Timing < Base
|
25
|
-
def aggregate(dps)
|
26
|
-
# TODO implement timing
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Event < Base
|
31
|
-
def aggregate(dps)
|
32
|
-
# TODO implement event
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def aggregate(dps, name = nil)
|
37
|
-
raise SimpleMetrics::DataPoint::NonMatchingTypesError if has_non_matching_types?(dps)
|
38
|
-
|
39
|
-
dp = dps.first.dup
|
40
|
-
dp.name = name if name
|
41
|
-
dp.value = strategy(dp).aggregate(dps)
|
42
|
-
dp
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def strategy(dp)
|
48
|
-
if dp.counter?
|
49
|
-
Counter.new
|
50
|
-
elsif dp.gauge?
|
51
|
-
Gauge.new
|
52
|
-
elsif dp.timing?
|
53
|
-
Timing.new
|
54
|
-
elsif dp.event?
|
55
|
-
Event.new
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def has_non_matching_types?(dps)
|
60
|
-
dps.group_by { |dp| dp.type }.size != 1
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module SimpleMetrics
|
5
|
-
|
6
|
-
describe ArrayAggregation do
|
7
|
-
|
8
|
-
before do
|
9
|
-
DataPointRepository.truncate_collections
|
10
|
-
DataPointRepository.ensure_collections_exist
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:ts) do
|
14
|
-
Time.now.utc.to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#aggregate" do
|
18
|
-
it "aggregates counter data points" do
|
19
|
-
stats1 = DataPoint.create_counter(:name => "key1", :value => 5)
|
20
|
-
stats2 = DataPoint.create_counter(:name => "key1", :value => 7)
|
21
|
-
result = ValueAggregation.aggregate([stats1, stats2])
|
22
|
-
result.value.should == 12
|
23
|
-
result.name.should == "key1"
|
24
|
-
result.should be_counter
|
25
|
-
end
|
26
|
-
|
27
|
-
it "aggregates counter data points with custom name" do
|
28
|
-
stats1 = DataPoint.create_counter(:name => "key1", :value => 5)
|
29
|
-
stats2 = DataPoint.create_counter(:name => "key1", :value => 7)
|
30
|
-
result = ValueAggregation.aggregate([stats1, stats2], "new_name")
|
31
|
-
result.value.should == 12
|
32
|
-
result.name.should == "new_name"
|
33
|
-
result.should be_counter
|
34
|
-
end
|
35
|
-
|
36
|
-
it "aggregates gauge data points" do
|
37
|
-
stats1 = DataPoint.create_gauge(:name => "key1", :value => 5)
|
38
|
-
stats2 = DataPoint.create_gauge(:name => "key1", :value => 7)
|
39
|
-
result = ValueAggregation.aggregate([stats1, stats2])
|
40
|
-
result.value.should == 6
|
41
|
-
result.name.should == "key1"
|
42
|
-
result.should be_gauge
|
43
|
-
end
|
44
|
-
|
45
|
-
it "aggregates timing data points" do
|
46
|
-
end
|
47
|
-
|
48
|
-
it "aggregates event data points" do
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|