simple_metrics 0.2.3 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.travis.yml +3 -0
  2. data/README.markdown +16 -53
  3. data/Rakefile +17 -0
  4. data/bin/populate +26 -13
  5. data/bin/simple_metrics_server +4 -3
  6. data/bin/simple_metrics_web +11 -0
  7. data/config.ru +6 -0
  8. data/default_config.yml +34 -0
  9. data/lib/simple_metrics/app.rb +136 -0
  10. data/lib/simple_metrics/array_aggregation.rb +84 -0
  11. data/lib/simple_metrics/bucket.rb +74 -63
  12. data/lib/simple_metrics/configuration.rb +79 -0
  13. data/lib/simple_metrics/data_point/base.rb +59 -0
  14. data/lib/simple_metrics/data_point/counter.rb +13 -0
  15. data/lib/simple_metrics/data_point/event.rb +12 -0
  16. data/lib/simple_metrics/data_point/gauge.rb +13 -0
  17. data/lib/simple_metrics/data_point/timing.rb +12 -0
  18. data/lib/simple_metrics/data_point.rb +32 -136
  19. data/lib/simple_metrics/data_point_repository.rb +131 -0
  20. data/lib/simple_metrics/functions.rb +5 -5
  21. data/lib/simple_metrics/graph.rb +10 -14
  22. data/lib/simple_metrics/metric.rb +28 -0
  23. data/lib/simple_metrics/metric_repository.rb +54 -0
  24. data/lib/simple_metrics/public/css/bootstrap-responsive.min.css +12 -0
  25. data/lib/simple_metrics/public/css/bootstrap.min.css +689 -0
  26. data/lib/simple_metrics/public/css/graph.css +45 -0
  27. data/lib/simple_metrics/public/css/rickshaw.min.css +1 -0
  28. data/lib/simple_metrics/public/img/glyphicons-halflings-white.png +0 -0
  29. data/lib/simple_metrics/public/img/glyphicons-halflings.png +0 -0
  30. data/lib/simple_metrics/public/js/application.js +278 -0
  31. data/lib/simple_metrics/public/js/backbone-0.9.2.min.js +38 -0
  32. data/lib/simple_metrics/public/js/bootstrap.min.js +6 -0
  33. data/lib/simple_metrics/public/js/d3.v2.min.js +4 -0
  34. data/lib/simple_metrics/public/js/handlebars-1.0.0.beta.6.js +1550 -0
  35. data/lib/simple_metrics/public/js/jquery-1.7.1.min.js +4 -0
  36. data/lib/simple_metrics/public/js/rickshaw.min.js +1 -0
  37. data/lib/simple_metrics/public/js/underscore-1.3.1.min.js +31 -0
  38. data/lib/simple_metrics/repository.rb +34 -0
  39. data/lib/simple_metrics/udp_server.rb +81 -0
  40. data/lib/simple_metrics/update_aggregation.rb +62 -0
  41. data/lib/simple_metrics/value_aggregation.rb +63 -0
  42. data/lib/simple_metrics/version.rb +1 -1
  43. data/lib/simple_metrics/views/graph.erb +93 -0
  44. data/lib/simple_metrics/views/index.erb +0 -0
  45. data/lib/simple_metrics/views/layout.erb +119 -0
  46. data/lib/simple_metrics/views/show.erb +31 -0
  47. data/lib/simple_metrics.rb +19 -76
  48. data/simple_metrics.gemspec +6 -0
  49. data/spec/array_aggregation_spec.rb +51 -0
  50. data/spec/bucket_spec.rb +24 -62
  51. data/spec/data_point_repository_spec.rb +114 -0
  52. data/spec/data_point_spec.rb +1 -70
  53. data/spec/graph_spec.rb +2 -20
  54. data/spec/metric_repository_spec.rb +53 -0
  55. data/spec/spec_helper.rb +3 -3
  56. data/spec/value_aggregation_spec.rb +52 -0
  57. metadata +131 -24
  58. data/bin/simple_metrics_client +0 -64
  59. data/lib/simple_metrics/client.rb +0 -83
  60. data/lib/simple_metrics/mongo.rb +0 -48
  61. data/lib/simple_metrics/server.rb +0 -66
@@ -54,78 +54,9 @@ module SimpleMetrics
54
54
  end
55
55
 
56
56
  it "parses increment timing with sample rate" do
57
+ # TODO
57
58
  end
58
59
  end
59
60
 
60
-
61
- describe "#aggregate" do
62
- it "aggregates counter data points" do
63
- stats1 = DataPoint.create_counter(:name => "key1", :value => 5)
64
- stats2 = DataPoint.create_counter(:name => "key1", :value => 7)
65
- result = DataPoint.aggregate([stats1, stats2])
66
- result.value.should == 12
67
- result.name.should == "key1"
68
- result.should be_counter
69
- end
70
-
71
- it "aggregates counter data points with custom name" do
72
- stats1 = DataPoint.create_counter(:name => "key1", :value => 5)
73
- stats2 = DataPoint.create_counter(:name => "key1", :value => 7)
74
- result = DataPoint.aggregate([stats1, stats2], "new_name")
75
- result.value.should == 12
76
- result.name.should == "new_name"
77
- result.should be_counter
78
- end
79
-
80
- it "aggregates gauge data points" do
81
- stats1 = DataPoint.create_gauge(:name => "key1", :value => 5)
82
- stats2 = DataPoint.create_gauge(:name => "key1", :value => 7)
83
- result = DataPoint.aggregate([stats1, stats2])
84
- result.value.should == 6
85
- result.name.should == "key1"
86
- result.should be_gauge
87
- end
88
-
89
- it "aggregates timing data points" do
90
- end
91
-
92
- it "aggregates event data points" do
93
- end
94
- end
95
-
96
- describe "#aggregate_array" do
97
- it "aggregates counter data points" do
98
- stats1 = DataPoint.create_counter(:name => "com.test.key1", :value => 5, :ts => ts)
99
- stats2 = DataPoint.create_counter(:name => "com.test.key1", :value => 7, :ts => ts)
100
- stats3 = DataPoint.create_counter(:name => "com.test.key1", :value => 9, :ts => (ts + 60) )
101
-
102
- results = DataPoint.aggregate_array([stats1, stats2, stats3], "com.test.*")
103
- results.should have(2).data_points
104
- results.first.name.should == "com.test.*"
105
- results.last.name.should == "com.test.*"
106
- results.first.value.should == 12
107
- results.last.value.should == 9
108
- end
109
-
110
- it "aggregates gauge data points" do
111
- stats1 = DataPoint.create_gauge(:name => "com.test.key1", :value => 5, :ts => ts)
112
- stats2 = DataPoint.create_gauge(:name => "com.test.key1", :value => 7, :ts => ts)
113
- stats3 = DataPoint.create_gauge(:name => "com.test.key1", :value => 9, :ts => (ts + 60) )
114
-
115
- results = DataPoint.aggregate_array([stats1, stats2, stats3], "com.test.*")
116
- results.should have(2).data_points
117
- results.first.name.should == "com.test.*"
118
- results.last.name.should == "com.test.*"
119
- results.first.value.should == 6
120
- results.last.value.should == 9
121
- end
122
-
123
- it "raises NonMatchingTypesError if types are different" do
124
- stats1 = DataPoint.create_counter(:name => "com.test.key1", :value => 5, :ts => ts)
125
- stats2 = DataPoint.create_gauge(:name => "com.test.key1", :value => 5, :ts => ts)
126
- expect { DataPoint.aggregate_array([stats1, stats2], "com.test.*") }.to raise_error(SimpleMetrics::DataPoint::NonMatchingTypesError)
127
- end
128
- end
129
61
  end
130
-
131
62
  end
data/spec/graph_spec.rb CHANGED
@@ -14,8 +14,8 @@ module SimpleMetrics
14
14
  end
15
15
 
16
16
  before do
17
- Mongo.truncate_collections
18
- Mongo.ensure_collections_exist
17
+ DataPointRepository.truncate_collections
18
+ DataPointRepository.ensure_collections_exist
19
19
  end
20
20
 
21
21
  describe "#query" do
@@ -66,24 +66,6 @@ module SimpleMetrics
66
66
  result.should be_counter
67
67
  end
68
68
 
69
- it "returns regexp request data points with aggregate gauge" do
70
- dp1 = DataPoint.create_gauge(:name => "com.test.key1", :value => 5)
71
- dp2 = DataPoint.create_gauge(:name => "com.test.key2", :value => 7)
72
-
73
- bucket.save(dp1, ts)
74
- bucket.save(dp2, ts)
75
-
76
- current_ts = bucket.ts_bucket(ts)
77
- from = current_ts
78
- to = current_ts
79
-
80
- results = Graph.query(bucket, from, to, /com\.test(.*)/)
81
- results.should have(1).data_point
82
- result = results.first
83
- result.name.should == "/com\\.test(.*)/"
84
- result.value.should == 6
85
- result.should be_gauge
86
- end
87
69
  end
88
70
  end
89
71
  end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ module SimpleMetrics
5
+
6
+ describe MetricRepository do
7
+
8
+ before do
9
+ MetricRepository.truncate_collections
10
+ end
11
+
12
+ let(:ts) do
13
+ Time.now.utc.to_i
14
+ end
15
+
16
+ describe "#save" do
17
+ it "saves metric correctly" do
18
+ metric = Metric.new(:name => "test", :total => 1)
19
+ MetricRepository.save(metric)
20
+
21
+ results = MetricRepository.find_all
22
+ results.should have(1).metric
23
+ results.first.name.should == "test"
24
+ results.first.total.should == 1
25
+ end
26
+ end
27
+
28
+ describe "#find_all" do
29
+ it "returns all metrics" do
30
+ metric1 = Metric.new(:name => "test", :total => 1)
31
+ metric2 = Metric.new(:name => "test2", :total => 1)
32
+ MetricRepository.save(metric1)
33
+ MetricRepository.save(metric2)
34
+
35
+ results = MetricRepository.find_all
36
+ results.should have(2).metrics
37
+ end
38
+ end
39
+
40
+ describe "#find_one_by_name" do
41
+ it "returns all metrics" do
42
+ metric1 = Metric.new(:name => "test", :total => 1)
43
+ metric2 = Metric.new(:name => "test2", :total => 1)
44
+ MetricRepository.save(metric1)
45
+ MetricRepository.save(metric2)
46
+
47
+ result = MetricRepository.find_one_by_name("test")
48
+ result.name.should == "test"
49
+ end
50
+ end
51
+ end # describe MetricRepository
52
+
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,6 @@ RSpec.configure do |config|
5
5
  end
6
6
 
7
7
  SimpleMetrics.logger = Logger.new('/dev/null')
8
- SimpleMetrics.db_config = { :host => 'localhost', :prefix => 'test' }
9
-
10
-
8
+ SimpleMetrics.configure do |config|
9
+ config.db = { 'host' => 'localhost', 'prefix' => 'test', 'options' => {} }
10
+ end
@@ -0,0 +1,52 @@
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
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.2.3
4
+ version: 0.3.2
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-10 00:00:00.000000000 Z
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70351255266000 !ruby/object:Gem::Requirement
16
+ requirement: &70208853226100 !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: *70351255266000
24
+ version_requirements: *70208853226100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70351255265220 !ruby/object:Gem::Requirement
27
+ requirement: &70208853225360 !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: *70351255265220
35
+ version_requirements: *70208853225360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rr
38
- requirement: &70351255264460 !ruby/object:Gem::Requirement
38
+ requirement: &70208853224800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70351255264460
46
+ version_requirements: *70208853224800
47
+ - !ruby/object:Gem::Dependency
48
+ name: shotgun
49
+ requirement: &70208853224200 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70208853224200
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: eventmachine
49
- requirement: &70351255263760 !ruby/object:Gem::Requirement
60
+ requirement: &70208853223700 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :runtime
56
67
  prerelease: false
57
- version_requirements: *70351255263760
68
+ version_requirements: *70208853223700
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: daemons
60
- requirement: &70351255263280 !ruby/object:Gem::Requirement
71
+ requirement: &70208853223080 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :runtime
67
78
  prerelease: false
68
- version_requirements: *70351255263280
79
+ version_requirements: *70208853223080
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: mongo
71
- requirement: &70351255262760 !ruby/object:Gem::Requirement
82
+ requirement: &70208853238880 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ~>
@@ -76,10 +87,21 @@ dependencies:
76
87
  version: '1.6'
77
88
  type: :runtime
78
89
  prerelease: false
79
- version_requirements: *70351255262760
90
+ version_requirements: *70208853238880
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: bson
82
- requirement: &70351255262240 !ruby/object:Gem::Requirement
93
+ requirement: &70208853238180 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '1.6'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *70208853238180
102
+ - !ruby/object:Gem::Dependency
103
+ name: bson_ext
104
+ requirement: &70208853237480 !ruby/object:Gem::Requirement
83
105
  none: false
84
106
  requirements:
85
107
  - - ~>
@@ -87,40 +109,121 @@ dependencies:
87
109
  version: '1.6'
88
110
  type: :runtime
89
111
  prerelease: false
90
- version_requirements: *70351255262240
112
+ version_requirements: *70208853237480
113
+ - !ruby/object:Gem::Dependency
114
+ name: sinatra
115
+ requirement: &70208853236920 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: *70208853236920
124
+ - !ruby/object:Gem::Dependency
125
+ name: erubis
126
+ requirement: &70208853236320 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: *70208853236320
135
+ - !ruby/object:Gem::Dependency
136
+ name: vegas
137
+ requirement: &70208853235540 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 0.1.2
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: *70208853235540
146
+ - !ruby/object:Gem::Dependency
147
+ name: json
148
+ requirement: &70208853234900 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :runtime
155
+ prerelease: false
156
+ version_requirements: *70208853234900
91
157
  description: SimpleMetrics
92
158
  email:
93
159
  - fdietz@gmail.com
94
160
  executables:
95
161
  - populate
96
- - simple_metrics_client
97
162
  - simple_metrics_server
163
+ - simple_metrics_web
98
164
  extensions: []
99
165
  extra_rdoc_files: []
100
166
  files:
101
167
  - .gitignore
102
168
  - .rvmrc
169
+ - .travis.yml
103
170
  - Gemfile
104
171
  - README.markdown
105
172
  - Rakefile
106
173
  - bin/populate
107
- - bin/simple_metrics_client
108
174
  - bin/simple_metrics_server
175
+ - bin/simple_metrics_web
176
+ - config.ru
177
+ - default_config.yml
109
178
  - example/increment.rb
110
179
  - lib/simple_metrics.rb
180
+ - lib/simple_metrics/app.rb
181
+ - lib/simple_metrics/array_aggregation.rb
111
182
  - lib/simple_metrics/bucket.rb
112
- - lib/simple_metrics/client.rb
183
+ - lib/simple_metrics/configuration.rb
113
184
  - lib/simple_metrics/data_point.rb
185
+ - lib/simple_metrics/data_point/base.rb
186
+ - lib/simple_metrics/data_point/counter.rb
187
+ - lib/simple_metrics/data_point/event.rb
188
+ - lib/simple_metrics/data_point/gauge.rb
189
+ - lib/simple_metrics/data_point/timing.rb
190
+ - lib/simple_metrics/data_point_repository.rb
114
191
  - lib/simple_metrics/functions.rb
115
192
  - lib/simple_metrics/graph.rb
116
- - lib/simple_metrics/mongo.rb
117
- - lib/simple_metrics/server.rb
193
+ - lib/simple_metrics/metric.rb
194
+ - lib/simple_metrics/metric_repository.rb
195
+ - lib/simple_metrics/public/css/bootstrap-responsive.min.css
196
+ - lib/simple_metrics/public/css/bootstrap.min.css
197
+ - lib/simple_metrics/public/css/graph.css
198
+ - lib/simple_metrics/public/css/rickshaw.min.css
199
+ - lib/simple_metrics/public/img/glyphicons-halflings-white.png
200
+ - lib/simple_metrics/public/img/glyphicons-halflings.png
201
+ - lib/simple_metrics/public/js/application.js
202
+ - lib/simple_metrics/public/js/backbone-0.9.2.min.js
203
+ - lib/simple_metrics/public/js/bootstrap.min.js
204
+ - lib/simple_metrics/public/js/d3.v2.min.js
205
+ - lib/simple_metrics/public/js/handlebars-1.0.0.beta.6.js
206
+ - lib/simple_metrics/public/js/jquery-1.7.1.min.js
207
+ - lib/simple_metrics/public/js/rickshaw.min.js
208
+ - lib/simple_metrics/public/js/underscore-1.3.1.min.js
209
+ - lib/simple_metrics/repository.rb
210
+ - lib/simple_metrics/udp_server.rb
211
+ - lib/simple_metrics/update_aggregation.rb
212
+ - lib/simple_metrics/value_aggregation.rb
118
213
  - lib/simple_metrics/version.rb
214
+ - lib/simple_metrics/views/graph.erb
215
+ - lib/simple_metrics/views/index.erb
216
+ - lib/simple_metrics/views/layout.erb
217
+ - lib/simple_metrics/views/show.erb
119
218
  - simple_metrics.gemspec
219
+ - spec/array_aggregation_spec.rb
120
220
  - spec/bucket_spec.rb
221
+ - spec/data_point_repository_spec.rb
121
222
  - spec/data_point_spec.rb
122
223
  - spec/graph_spec.rb
224
+ - spec/metric_repository_spec.rb
123
225
  - spec/spec_helper.rb
226
+ - spec/value_aggregation_spec.rb
124
227
  homepage: ''
125
228
  licenses: []
126
229
  post_install_message:
@@ -135,7 +238,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
238
  version: '0'
136
239
  segments:
137
240
  - 0
138
- hash: 1198545675235569375
241
+ hash: -3589789120249469613
139
242
  required_rubygems_version: !ruby/object:Gem::Requirement
140
243
  none: false
141
244
  requirements:
@@ -144,15 +247,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
247
  version: '0'
145
248
  segments:
146
249
  - 0
147
- hash: 1198545675235569375
250
+ hash: -3589789120249469613
148
251
  requirements: []
149
252
  rubyforge_project:
150
- rubygems_version: 1.8.17
253
+ rubygems_version: 1.8.15
151
254
  signing_key:
152
255
  specification_version: 3
153
256
  summary: SimpleMetrics
154
257
  test_files:
258
+ - spec/array_aggregation_spec.rb
155
259
  - spec/bucket_spec.rb
260
+ - spec/data_point_repository_spec.rb
156
261
  - spec/data_point_spec.rb
157
262
  - spec/graph_spec.rb
263
+ - spec/metric_repository_spec.rb
158
264
  - spec/spec_helper.rb
265
+ - spec/value_aggregation_spec.rb