simple_metrics 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +53 -16
- data/Rakefile +0 -17
- data/bin/populate +13 -26
- data/bin/simple_metrics_client +64 -0
- data/bin/simple_metrics_server +3 -4
- data/lib/simple_metrics.rb +76 -17
- data/lib/simple_metrics/bucket.rb +106 -43
- data/lib/simple_metrics/client.rb +83 -0
- data/lib/simple_metrics/data_point.rb +137 -45
- data/lib/simple_metrics/functions.rb +5 -5
- data/lib/simple_metrics/graph.rb +32 -69
- data/lib/simple_metrics/mongo.rb +48 -0
- data/lib/simple_metrics/server.rb +66 -0
- data/lib/simple_metrics/version.rb +1 -1
- data/simple_metrics.gemspec +0 -6
- data/spec/bucket_spec.rb +152 -17
- data/spec/data_point_spec.rb +64 -14
- data/spec/graph_spec.rb +19 -30
- data/spec/spec_helper.rb +3 -3
- metadata +24 -139
- data/.travis.yml +0 -3
- data/bin/simple_metrics_web +0 -11
- data/config.ru +0 -6
- data/default_config.yml +0 -34
- data/lib/simple_metrics/app.rb +0 -52
- data/lib/simple_metrics/configuration.rb +0 -97
- data/lib/simple_metrics/data_point/base.rb +0 -59
- data/lib/simple_metrics/data_point/counter.rb +0 -20
- data/lib/simple_metrics/data_point/event.rb +0 -16
- data/lib/simple_metrics/data_point/gauge.rb +0 -19
- data/lib/simple_metrics/data_point/timing.rb +0 -15
- data/lib/simple_metrics/data_point_repository.rb +0 -114
- data/lib/simple_metrics/importer.rb +0 -64
- data/lib/simple_metrics/metric.rb +0 -29
- data/lib/simple_metrics/metric_repository.rb +0 -54
- data/lib/simple_metrics/public/css/bootstrap-responsive.min.css +0 -12
- data/lib/simple_metrics/public/css/bootstrap.min.css +0 -689
- data/lib/simple_metrics/public/css/graph.css +0 -45
- data/lib/simple_metrics/public/css/rickshaw.min.css +0 -1
- data/lib/simple_metrics/public/img/glyphicons-halflings-white.png +0 -0
- data/lib/simple_metrics/public/img/glyphicons-halflings.png +0 -0
- data/lib/simple_metrics/public/js/app.js +0 -20
- data/lib/simple_metrics/public/js/collections/graph.js +0 -16
- data/lib/simple_metrics/public/js/collections/metric.js +0 -9
- data/lib/simple_metrics/public/js/helpers.js +0 -23
- data/lib/simple_metrics/public/js/lib/backbone-0.9.2.min.js +0 -38
- data/lib/simple_metrics/public/js/lib/bootstrap.min.js +0 -6
- data/lib/simple_metrics/public/js/lib/d3.v2.min.js +0 -4
- data/lib/simple_metrics/public/js/lib/handlebars-1.0.0.beta.6.js +0 -1550
- data/lib/simple_metrics/public/js/lib/jquery-1.7.1.min.js +0 -4
- data/lib/simple_metrics/public/js/lib/moment.min.js +0 -6
- data/lib/simple_metrics/public/js/lib/rickshaw.min.js +0 -1
- data/lib/simple_metrics/public/js/lib/underscore-1.3.1.min.js +0 -31
- data/lib/simple_metrics/public/js/models/graph.js +0 -6
- data/lib/simple_metrics/public/js/models/metric.js +0 -7
- data/lib/simple_metrics/public/js/router.js +0 -42
- data/lib/simple_metrics/public/js/views/app.js +0 -18
- data/lib/simple_metrics/public/js/views/dashboard.js +0 -10
- data/lib/simple_metrics/public/js/views/graph.js +0 -101
- data/lib/simple_metrics/public/js/views/metric.js +0 -82
- data/lib/simple_metrics/public/js/views/metrics.js +0 -10
- data/lib/simple_metrics/repository.rb +0 -34
- data/lib/simple_metrics/udp_server.rb +0 -81
- data/lib/simple_metrics/views/graph.erb +0 -93
- data/lib/simple_metrics/views/index.erb +0 -0
- data/lib/simple_metrics/views/layout.erb +0 -138
- data/lib/simple_metrics/views/show.erb +0 -31
- data/spec/data_point_repository_spec.rb +0 -77
- data/spec/importer_spec.rb +0 -126
- data/spec/metric_repository_spec.rb +0 -53
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.
|
9
|
-
|
10
|
-
|
8
|
+
SimpleMetrics.db_config = { :host => 'localhost', :prefix => 'test' }
|
9
|
+
|
10
|
+
|
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.
|
4
|
+
version: 0.4.0
|
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-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70302462447680 !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: *70302462447680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70302462446940 !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: *70302462446940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rr
|
38
|
-
requirement: &
|
38
|
+
requirement: &70302462446200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,21 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: shotgun
|
49
|
-
requirement: &70211252364740 !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: *70211252364740
|
46
|
+
version_requirements: *70302462446200
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
48
|
name: eventmachine
|
60
|
-
requirement: &
|
49
|
+
requirement: &70302462445460 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
52
|
- - ! '>='
|
@@ -65,10 +54,10 @@ dependencies:
|
|
65
54
|
version: '0'
|
66
55
|
type: :runtime
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *70302462445460
|
69
58
|
- !ruby/object:Gem::Dependency
|
70
59
|
name: daemons
|
71
|
-
requirement: &
|
60
|
+
requirement: &70302462444740 !ruby/object:Gem::Requirement
|
72
61
|
none: false
|
73
62
|
requirements:
|
74
63
|
- - ! '>='
|
@@ -76,10 +65,10 @@ dependencies:
|
|
76
65
|
version: '0'
|
77
66
|
type: :runtime
|
78
67
|
prerelease: false
|
79
|
-
version_requirements: *
|
68
|
+
version_requirements: *70302462444740
|
80
69
|
- !ruby/object:Gem::Dependency
|
81
70
|
name: mongo
|
82
|
-
requirement: &
|
71
|
+
requirement: &70302462444200 !ruby/object:Gem::Requirement
|
83
72
|
none: false
|
84
73
|
requirements:
|
85
74
|
- - ~>
|
@@ -87,21 +76,10 @@ dependencies:
|
|
87
76
|
version: '1.6'
|
88
77
|
type: :runtime
|
89
78
|
prerelease: false
|
90
|
-
version_requirements: *
|
79
|
+
version_requirements: *70302462444200
|
91
80
|
- !ruby/object:Gem::Dependency
|
92
81
|
name: bson
|
93
|
-
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: *70211252378520
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
name: bson_ext
|
104
|
-
requirement: &70211252377940 !ruby/object:Gem::Requirement
|
82
|
+
requirement: &70302462443660 !ruby/object:Gem::Requirement
|
105
83
|
none: false
|
106
84
|
requirements:
|
107
85
|
- - ~>
|
@@ -109,129 +87,39 @@ dependencies:
|
|
109
87
|
version: '1.6'
|
110
88
|
type: :runtime
|
111
89
|
prerelease: false
|
112
|
-
version_requirements: *
|
113
|
-
- !ruby/object:Gem::Dependency
|
114
|
-
name: sinatra
|
115
|
-
requirement: &70211252377400 !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: *70211252377400
|
124
|
-
- !ruby/object:Gem::Dependency
|
125
|
-
name: erubis
|
126
|
-
requirement: &70211252376600 !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: *70211252376600
|
135
|
-
- !ruby/object:Gem::Dependency
|
136
|
-
name: vegas
|
137
|
-
requirement: &70211252375960 !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: *70211252375960
|
146
|
-
- !ruby/object:Gem::Dependency
|
147
|
-
name: json
|
148
|
-
requirement: &70211252375460 !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: *70211252375460
|
90
|
+
version_requirements: *70302462443660
|
157
91
|
description: SimpleMetrics
|
158
92
|
email:
|
159
93
|
- fdietz@gmail.com
|
160
94
|
executables:
|
161
95
|
- populate
|
96
|
+
- simple_metrics_client
|
162
97
|
- simple_metrics_server
|
163
|
-
- simple_metrics_web
|
164
98
|
extensions: []
|
165
99
|
extra_rdoc_files: []
|
166
100
|
files:
|
167
101
|
- .gitignore
|
168
102
|
- .rvmrc
|
169
|
-
- .travis.yml
|
170
103
|
- Gemfile
|
171
104
|
- README.markdown
|
172
105
|
- Rakefile
|
173
106
|
- bin/populate
|
107
|
+
- bin/simple_metrics_client
|
174
108
|
- bin/simple_metrics_server
|
175
|
-
- bin/simple_metrics_web
|
176
|
-
- config.ru
|
177
|
-
- default_config.yml
|
178
109
|
- example/increment.rb
|
179
110
|
- lib/simple_metrics.rb
|
180
|
-
- lib/simple_metrics/app.rb
|
181
111
|
- lib/simple_metrics/bucket.rb
|
182
|
-
- lib/simple_metrics/
|
112
|
+
- lib/simple_metrics/client.rb
|
183
113
|
- lib/simple_metrics/data_point.rb
|
184
|
-
- lib/simple_metrics/data_point/base.rb
|
185
|
-
- lib/simple_metrics/data_point/counter.rb
|
186
|
-
- lib/simple_metrics/data_point/event.rb
|
187
|
-
- lib/simple_metrics/data_point/gauge.rb
|
188
|
-
- lib/simple_metrics/data_point/timing.rb
|
189
|
-
- lib/simple_metrics/data_point_repository.rb
|
190
114
|
- lib/simple_metrics/functions.rb
|
191
115
|
- lib/simple_metrics/graph.rb
|
192
|
-
- lib/simple_metrics/
|
193
|
-
- lib/simple_metrics/
|
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/app.js
|
202
|
-
- lib/simple_metrics/public/js/collections/graph.js
|
203
|
-
- lib/simple_metrics/public/js/collections/metric.js
|
204
|
-
- lib/simple_metrics/public/js/helpers.js
|
205
|
-
- lib/simple_metrics/public/js/lib/backbone-0.9.2.min.js
|
206
|
-
- lib/simple_metrics/public/js/lib/bootstrap.min.js
|
207
|
-
- lib/simple_metrics/public/js/lib/d3.v2.min.js
|
208
|
-
- lib/simple_metrics/public/js/lib/handlebars-1.0.0.beta.6.js
|
209
|
-
- lib/simple_metrics/public/js/lib/jquery-1.7.1.min.js
|
210
|
-
- lib/simple_metrics/public/js/lib/moment.min.js
|
211
|
-
- lib/simple_metrics/public/js/lib/rickshaw.min.js
|
212
|
-
- lib/simple_metrics/public/js/lib/underscore-1.3.1.min.js
|
213
|
-
- lib/simple_metrics/public/js/models/graph.js
|
214
|
-
- lib/simple_metrics/public/js/models/metric.js
|
215
|
-
- lib/simple_metrics/public/js/router.js
|
216
|
-
- lib/simple_metrics/public/js/views/app.js
|
217
|
-
- lib/simple_metrics/public/js/views/dashboard.js
|
218
|
-
- lib/simple_metrics/public/js/views/graph.js
|
219
|
-
- lib/simple_metrics/public/js/views/metric.js
|
220
|
-
- lib/simple_metrics/public/js/views/metrics.js
|
221
|
-
- lib/simple_metrics/repository.rb
|
222
|
-
- lib/simple_metrics/udp_server.rb
|
116
|
+
- lib/simple_metrics/mongo.rb
|
117
|
+
- lib/simple_metrics/server.rb
|
223
118
|
- lib/simple_metrics/version.rb
|
224
|
-
- lib/simple_metrics/views/graph.erb
|
225
|
-
- lib/simple_metrics/views/index.erb
|
226
|
-
- lib/simple_metrics/views/layout.erb
|
227
|
-
- lib/simple_metrics/views/show.erb
|
228
119
|
- simple_metrics.gemspec
|
229
120
|
- spec/bucket_spec.rb
|
230
|
-
- spec/data_point_repository_spec.rb
|
231
121
|
- spec/data_point_spec.rb
|
232
122
|
- spec/graph_spec.rb
|
233
|
-
- spec/importer_spec.rb
|
234
|
-
- spec/metric_repository_spec.rb
|
235
123
|
- spec/spec_helper.rb
|
236
124
|
homepage: ''
|
237
125
|
licenses: []
|
@@ -247,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
247
135
|
version: '0'
|
248
136
|
segments:
|
249
137
|
- 0
|
250
|
-
hash: -
|
138
|
+
hash: -520904601544402240
|
251
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
252
140
|
none: false
|
253
141
|
requirements:
|
@@ -256,18 +144,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
144
|
version: '0'
|
257
145
|
segments:
|
258
146
|
- 0
|
259
|
-
hash: -
|
147
|
+
hash: -520904601544402240
|
260
148
|
requirements: []
|
261
149
|
rubyforge_project:
|
262
|
-
rubygems_version: 1.8.
|
150
|
+
rubygems_version: 1.8.17
|
263
151
|
signing_key:
|
264
152
|
specification_version: 3
|
265
153
|
summary: SimpleMetrics
|
266
154
|
test_files:
|
267
155
|
- spec/bucket_spec.rb
|
268
|
-
- spec/data_point_repository_spec.rb
|
269
156
|
- spec/data_point_spec.rb
|
270
157
|
- spec/graph_spec.rb
|
271
|
-
- spec/importer_spec.rb
|
272
|
-
- spec/metric_repository_spec.rb
|
273
158
|
- spec/spec_helper.rb
|
data/.travis.yml
DELETED
data/bin/simple_metrics_web
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
-
|
5
|
-
require "rubygems"
|
6
|
-
require 'vegas'
|
7
|
-
require "simple_metrics"
|
8
|
-
|
9
|
-
Vegas::Runner.new(SimpleMetrics::App, 'simple_metrics_web') do |runner, opts, app|
|
10
|
-
# add more options here
|
11
|
-
end
|
data/config.ru
DELETED
data/default_config.yml
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
server:
|
2
|
-
host: 'localhost'
|
3
|
-
port: 8125
|
4
|
-
flush_interval: 10
|
5
|
-
|
6
|
-
db:
|
7
|
-
host: 'localhost'
|
8
|
-
port: 27017
|
9
|
-
prefix: 'development'
|
10
|
-
options:
|
11
|
-
pool_size: 5
|
12
|
-
timeout: 5
|
13
|
-
|
14
|
-
web:
|
15
|
-
host: 'localhost'
|
16
|
-
port: 5678
|
17
|
-
|
18
|
-
buckets:
|
19
|
-
- name: 'stats_per_10s'
|
20
|
-
seconds: 10
|
21
|
-
capped: true
|
22
|
-
size: 180_000 # 6*30 = 180 (30 min ttl), 180 * 100 = 18.000 (100 data points), 18.000 * 10 (bytes each) = 180.000
|
23
|
-
- name: 'stats_per_1min'
|
24
|
-
seconds: 60
|
25
|
-
capped: true
|
26
|
-
size: 120_000 # 60*3 = 180 (3h ttl), 120 * 100 = 18.000 (100 data points), 18.000 * 10 (bytes each) = 180.000
|
27
|
-
- name: 'stats_per_10min'
|
28
|
-
seconds: 600
|
29
|
-
size: 0
|
30
|
-
capped: false
|
31
|
-
- name: 'stats_per_day'
|
32
|
-
seconds: 86400 # 600*6*24
|
33
|
-
size: 0
|
34
|
-
capped: false
|
data/lib/simple_metrics/app.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require "sinatra"
|
2
|
-
require "erubis"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
if defined? Encoding
|
6
|
-
Encoding.default_external = Encoding::UTF_8
|
7
|
-
end
|
8
|
-
|
9
|
-
module SimpleMetrics
|
10
|
-
class App < Sinatra::Base
|
11
|
-
|
12
|
-
set :views, ::File.expand_path('../views', __FILE__)
|
13
|
-
set :public_folder, File.expand_path('../public', __FILE__)
|
14
|
-
|
15
|
-
helpers do
|
16
|
-
end
|
17
|
-
|
18
|
-
get "/api/metrics" do
|
19
|
-
content_type :json
|
20
|
-
metrics = SimpleMetrics::MetricRepository.find_all
|
21
|
-
metrics.inject([]) { |result, m| result << m.attributes }.to_json
|
22
|
-
end
|
23
|
-
|
24
|
-
get "/api/metrics/:name" do
|
25
|
-
content_type :json
|
26
|
-
metric = SimpleMetrics::MetricRepository.find_one_by_name(params[:name])
|
27
|
-
metric.attributes.to_json
|
28
|
-
end
|
29
|
-
|
30
|
-
get "/api/graph" do
|
31
|
-
content_type :json
|
32
|
-
from = (params[:from] || Time.now).to_i
|
33
|
-
time = params[:time] || 'minute'
|
34
|
-
targets = params[:targets]
|
35
|
-
data_points = prepare_data_points(from, time, *targets)
|
36
|
-
data_points.to_json
|
37
|
-
end
|
38
|
-
|
39
|
-
get "/*" do
|
40
|
-
erb :index
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def prepare_data_points(from, time, *targets)
|
46
|
-
bucket = SimpleMetrics::Bucket.for_time(time)
|
47
|
-
to = from - SimpleMetrics::Graph.time_range(time)
|
48
|
-
SimpleMetrics::Graph.query_all(bucket, to, from, *targets)
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module SimpleMetrics
|
4
|
-
class Configuration
|
5
|
-
|
6
|
-
attr_reader :config
|
7
|
-
|
8
|
-
def initialize(hash = {}, &block)
|
9
|
-
@config = load_defaults.merge(symbolize_keys(hash))
|
10
|
-
end
|
11
|
-
|
12
|
-
def configure(hash = {}, &block)
|
13
|
-
yield self if block_given?
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def db
|
18
|
-
@db ||= config.fetch(:db)
|
19
|
-
end
|
20
|
-
|
21
|
-
def db=(db)
|
22
|
-
@db = db
|
23
|
-
end
|
24
|
-
|
25
|
-
def buckets
|
26
|
-
@buckets ||= begin
|
27
|
-
tmp = config.fetch(:buckets)
|
28
|
-
tmp.map { |b| symbolize_keys(b)}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def buckets=(buckets)
|
33
|
-
@buckets = buckets
|
34
|
-
end
|
35
|
-
|
36
|
-
def server
|
37
|
-
@server ||= config.fetch(:server)
|
38
|
-
end
|
39
|
-
|
40
|
-
def server=(server)
|
41
|
-
@server = server
|
42
|
-
end
|
43
|
-
|
44
|
-
def web
|
45
|
-
@web ||= config.fetch(:web)
|
46
|
-
end
|
47
|
-
|
48
|
-
def web=(web)
|
49
|
-
@web = web
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def load_defaults
|
55
|
-
@config = symbolize_keys(load_config)
|
56
|
-
rescue Errno::ENOENT # not found error
|
57
|
-
logger.info "Creating initial config file: #{config_file}"
|
58
|
-
FileUtils.cp(default_config_file, config_file)
|
59
|
-
@config = load_config
|
60
|
-
end
|
61
|
-
|
62
|
-
def config_file
|
63
|
-
File.expand_path('~/.simple_metrics.conf')
|
64
|
-
end
|
65
|
-
|
66
|
-
def default_config_file
|
67
|
-
File.expand_path('../../../default_config.yml', __FILE__)
|
68
|
-
end
|
69
|
-
|
70
|
-
def load_config
|
71
|
-
YAML.load_file(config_file)
|
72
|
-
rescue ArgumentError => e
|
73
|
-
logger.error "Error parsing config file: #{e}"
|
74
|
-
rescue IOError => e
|
75
|
-
logger.error "Error reading config file: #{e}"
|
76
|
-
end
|
77
|
-
|
78
|
-
def symbolize_keys(hash)
|
79
|
-
hash.inject({}){|result, (key, value)|
|
80
|
-
new_key = case key
|
81
|
-
when String then key.to_sym
|
82
|
-
else key
|
83
|
-
end
|
84
|
-
new_value = case value
|
85
|
-
when Hash then symbolize_keys(value)
|
86
|
-
else value
|
87
|
-
end
|
88
|
-
result[new_key] = new_value
|
89
|
-
result
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
def logger
|
94
|
-
SimpleMetrics.logger
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|