librato-metrics 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +1 -2
- data/CHANGELOG.md +4 -0
- data/README.md +13 -13
- data/lib/librato/metrics.rb +10 -5
- data/lib/librato/metrics/aggregator.rb +24 -0
- data/lib/librato/metrics/client.rb +103 -24
- data/lib/librato/metrics/collection.rb +4 -0
- data/lib/librato/metrics/persistence.rb +0 -1
- data/lib/librato/metrics/processor.rb +2 -0
- data/lib/librato/metrics/version.rb +1 -1
- data/spec/integration/deprecated_methods_spec.rb +85 -0
- data/spec/integration/metrics/queue_spec.rb +4 -4
- data/spec/integration/metrics_spec.rb +53 -50
- data/spec/spec_helper.rb +2 -2
- metadata +5 -3
- metadata.gz.sig +1 -2
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
6
|
2
|
-
�'������+��JdB��xfpٟ��5J��4�J�
|
1
|
+
�ԇ��d�I�T.���`<���3��e����U�Q����6��f�M;AC�@yCf���V��H�$.��B҄&܈��LʔSOS�����$ƒ5�Ak�]�g�M�����ru��D��ؖC1f>��z���ɠ�`�ɥ/U[�aYJ���������I�+~w��sn��*�ď��:Sb�ލ�9�u �>�z����0 V��ο.�Y:0͟�=ʍL��7c�/�N]=�9��^[]3z/���풏'B���[*
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -186,52 +186,52 @@ Both options are driven by the addition of measurements. Specifically for time-b
|
|
186
186
|
|
187
187
|
Get name and properties for all metrics you have in the system:
|
188
188
|
|
189
|
-
metrics = Librato::Metrics.
|
189
|
+
metrics = Librato::Metrics.metrics
|
190
190
|
|
191
191
|
Get only metrics whose name includes `time`:
|
192
192
|
|
193
|
-
metrics = Librato::Metrics.
|
193
|
+
metrics = Librato::Metrics.metrics :name => 'time'
|
194
194
|
|
195
195
|
## Querying Metric Data
|
196
196
|
|
197
197
|
Get attributes for metric `temperature`:
|
198
198
|
|
199
|
-
data = Librato::Metrics.
|
199
|
+
data = Librato::Metrics.get_metric :temperature
|
200
200
|
|
201
201
|
Get the 20 most recent data points for `temperature`:
|
202
202
|
|
203
|
-
data = Librato::Metrics.
|
203
|
+
data = Librato::Metrics.get_measurements :temperature, :count => 20
|
204
204
|
|
205
205
|
Get the 20 most recent data points for `temperature` from a specific source:
|
206
206
|
|
207
|
-
data = Librato::Metrics.
|
207
|
+
data = Librato::Metrics.get_measurements :temperature, :count => 20, :source => 'app1'
|
208
208
|
|
209
209
|
Get the 20 most recent 15 minute data point rollups for `temperature`:
|
210
210
|
|
211
|
-
data = Librato::Metrics.
|
211
|
+
data = Librato::Metrics.get_measurements :temperature, :count => 20, :resolution => 900
|
212
212
|
|
213
|
-
There are many more options supported for querying, take a look at the [REST API docs](http://dev.librato.com/v1/get/gauges/:name) or the [
|
213
|
+
There are many more options supported for querying, take a look at the [REST API docs](http://dev.librato.com/v1/get/gauges/:name) or the [`get_metric`](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics/Client#get_metric-instance_method)/[`get_measurements`](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics/Client#get_measurements-instance_method) documentation for more details.
|
214
214
|
|
215
215
|
## Setting Metric Properties
|
216
216
|
|
217
217
|
Setting custom [properties](http://dev.librato.com/v1/metrics#metric_properties) on your metrics is easy:
|
218
218
|
|
219
219
|
# assign a period and default color
|
220
|
-
Librato::Metrics.
|
220
|
+
Librato::Metrics.update_metric :temperature, :period => 15, :attributes => { :color => 'F00' }
|
221
221
|
|
222
|
-
It is also possible to update properties for multiple metrics at once, see the [
|
222
|
+
It is also possible to update properties for multiple metrics at once, see the [`#update_metric` method documentation](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics/Client#update_metric-instance_method) for more information.
|
223
223
|
|
224
224
|
## Deleting Metrics
|
225
225
|
|
226
226
|
If you ever need to remove a metric and all of its measurements, doing so is easy:
|
227
227
|
|
228
228
|
# delete the metrics 'temperature' and 'humidity'
|
229
|
-
Librato::Metrics.
|
229
|
+
Librato::Metrics.delete_metrics :temperature, :humidity
|
230
230
|
|
231
231
|
You can also delete using wildcards:
|
232
232
|
|
233
233
|
# delete metrics that start with cpu. except for cpu.free
|
234
|
-
Librato::Metrics.
|
234
|
+
Librato::Metrics.delete_metrics :names => 'cpu.*', :exclude => ['cpu.free']
|
235
235
|
|
236
236
|
Note that deleted metrics and their measurements are unrecoverable, so use with care.
|
237
237
|
|
@@ -248,10 +248,10 @@ If you need to use metrics with multiple sets of authentication credentials simu
|
|
248
248
|
All of the same operations you can call directly from `Librato::Metrics` are available per-client:
|
249
249
|
|
250
250
|
# list Joe's metrics
|
251
|
-
joe.
|
251
|
+
joe.metrics
|
252
252
|
|
253
253
|
# fetch the last 20 data points for Mike's metric, humidity
|
254
|
-
mike.
|
254
|
+
mike.get_measurements :humidity, :count => 20
|
255
255
|
|
256
256
|
There are two ways to associate a new queue with a client:
|
257
257
|
|
data/lib/librato/metrics.rb
CHANGED
@@ -32,7 +32,7 @@ module Librato
|
|
32
32
|
# Librato::Metrics.submit :foo => 12712
|
33
33
|
#
|
34
34
|
# # fetch the last 10 values of foo
|
35
|
-
# Librato::Metrics.
|
35
|
+
# Librato::Metrics.get_measurements :foo, :count => 10
|
36
36
|
#
|
37
37
|
# @example Queuing metrics for submission
|
38
38
|
# queue = Librato::Metrics::Queue.new
|
@@ -73,10 +73,15 @@ module Librato
|
|
73
73
|
# Client.
|
74
74
|
#
|
75
75
|
def_delegators :client, :agent_identifier, :annotate, :api_endpoint,
|
76
|
-
:api_endpoint=, :authenticate, :connection,
|
77
|
-
:faraday_adapter, :faraday_adapter=,
|
78
|
-
:persistence, :persistence=, :persister,
|
79
|
-
:
|
76
|
+
:api_endpoint=, :authenticate, :connection,
|
77
|
+
:faraday_adapter, :faraday_adapter=,
|
78
|
+
:persistence, :persistence=, :persister,
|
79
|
+
:get_metric, :get_measurements, :metrics,
|
80
|
+
:delete_metrics, :update_metric, :update_metrics,
|
81
|
+
:submit,
|
82
|
+
# Deprecated metrics methods
|
83
|
+
:fetch, :list, :delete, :update
|
84
|
+
|
80
85
|
|
81
86
|
# The Librato::Metrics::Client being used by module-level
|
82
87
|
# access.
|
@@ -4,6 +4,24 @@ require 'metrics/processor'
|
|
4
4
|
module Librato
|
5
5
|
module Metrics
|
6
6
|
|
7
|
+
# If you are measuring something very frequently you can sample into
|
8
|
+
# an aggregator and it will track and submit a single aggregate
|
9
|
+
# measurement
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# aggregator = Libato::Metrics::Aggregator.new
|
13
|
+
#
|
14
|
+
# 40.times do
|
15
|
+
# # do work...
|
16
|
+
# aggregator.add 'work.time' => work_time
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # send directly
|
20
|
+
# aggregator.submit
|
21
|
+
#
|
22
|
+
# # or merge into a queue for submission
|
23
|
+
# queue.merge!(aggregator)
|
24
|
+
#
|
7
25
|
class Aggregator
|
8
26
|
SOURCE_SEPARATOR = '%%' # must not be in valid source name criteria
|
9
27
|
|
@@ -24,6 +42,12 @@ module Librato
|
|
24
42
|
|
25
43
|
# Add a metric entry to the metric set:
|
26
44
|
#
|
45
|
+
# @example Basic use
|
46
|
+
# annotator.add 'request.time' => 30.24
|
47
|
+
#
|
48
|
+
# @example With a custom source
|
49
|
+
# annotator.add 'request.time' => {value: 20.52, source: 'staging'}
|
50
|
+
#
|
27
51
|
# @param [Hash] measurements measurements to add
|
28
52
|
# @return [Aggregator] returns self
|
29
53
|
def add(measurements)
|
@@ -86,15 +86,15 @@ module Librato
|
|
86
86
|
# careful with this, this is instant and permanent.
|
87
87
|
#
|
88
88
|
# @example Delete metric 'temperature'
|
89
|
-
# Librato::Metrics.
|
89
|
+
# Librato::Metrics.delete_metrics :temperature
|
90
90
|
#
|
91
91
|
# @example Delete metrics 'foo' and 'bar'
|
92
|
-
# Librato::Metrics.
|
92
|
+
# Librato::Metrics.delete_metrics :foo, :bar
|
93
93
|
#
|
94
94
|
# @example Delete metrics that start with 'foo' except 'foobar'
|
95
|
-
# Librato::Metrics.
|
95
|
+
# Librato::Metrics.delete_metrics :names => 'foo*', :exclude => ['foobar']
|
96
96
|
#
|
97
|
-
def
|
97
|
+
def delete_metrics(*metric_names)
|
98
98
|
raise(NoMetricsProvided, 'Metric name missing.') if metric_names.empty?
|
99
99
|
if metric_names[0].respond_to?(:keys) # hash form
|
100
100
|
params = metric_names[0]
|
@@ -109,6 +109,12 @@ module Librato
|
|
109
109
|
true
|
110
110
|
end
|
111
111
|
|
112
|
+
# Completely delete metrics with the given names. Be
|
113
|
+
# careful with this, this is instant and permanent.
|
114
|
+
#
|
115
|
+
# @deprecated Use {#delete_metrics} instead
|
116
|
+
def delete(*metric_names); delete_metrics(*metric_names); end
|
117
|
+
|
112
118
|
# Return current adapter this client will use.
|
113
119
|
# Defaults to Metrics.faraday_adapter if set, otherwise
|
114
120
|
# Faraday.default_adapter
|
@@ -123,6 +129,8 @@ module Librato
|
|
123
129
|
|
124
130
|
# Query metric data
|
125
131
|
#
|
132
|
+
# @deprecated Use {#get_metric} or {#get_measurements} instead.
|
133
|
+
#
|
126
134
|
# @example Get attributes for a metric
|
127
135
|
# attrs = Librato::Metrics.fetch :temperature
|
128
136
|
#
|
@@ -146,11 +154,30 @@ module Librato
|
|
146
154
|
# :resolution => 900
|
147
155
|
#
|
148
156
|
# A full list of query parameters can be found in the API
|
149
|
-
# documentation: {http://dev.librato.com/v1/get/
|
157
|
+
# documentation: {http://dev.librato.com/v1/get/metrics/:name}
|
150
158
|
#
|
151
159
|
# @param [Symbol|String] metric Metric name
|
152
160
|
# @param [Hash] options Query options
|
153
161
|
def fetch(metric, options={})
|
162
|
+
metric = get_metric(metric, options)
|
163
|
+
options.empty? ? metric : metric["measurements"]
|
164
|
+
end
|
165
|
+
|
166
|
+
# Retrieve a specific metric by name, optionally including data points
|
167
|
+
#
|
168
|
+
# @example Get attributes for a metric
|
169
|
+
# metric = Librato::Metrics.get_metric :temperature
|
170
|
+
#
|
171
|
+
# @example Get a metric and its 20 most recent data points
|
172
|
+
# metric = Librato::Metrics.fetch :temperature, :count => 20
|
173
|
+
# metric['measurements'] # => {...}
|
174
|
+
#
|
175
|
+
# A full list of query parameters can be found in the API
|
176
|
+
# documentation: {http://dev.librato.com/v1/get/metrics/:name}
|
177
|
+
#
|
178
|
+
# @param [Symbol|String] name Metric name
|
179
|
+
# @param [Hash] options Query options
|
180
|
+
def get_metric(name, options = {})
|
154
181
|
query = options.dup
|
155
182
|
if query[:start_time].respond_to?(:year)
|
156
183
|
query[:start_time] = query[:start_time].to_i
|
@@ -162,11 +189,42 @@ module Librato
|
|
162
189
|
query[:resolution] ||= 1
|
163
190
|
end
|
164
191
|
# expects 200
|
165
|
-
url = connection.build_url("metrics/#{
|
192
|
+
url = connection.build_url("metrics/#{name}", query)
|
166
193
|
response = connection.get(url)
|
167
194
|
parsed = SmartJSON.read(response.body)
|
168
195
|
# TODO: pagination support
|
169
|
-
|
196
|
+
parsed
|
197
|
+
end
|
198
|
+
|
199
|
+
# Retrieve data points for a specific metric
|
200
|
+
#
|
201
|
+
# @example Get 20 most recent data points for metric
|
202
|
+
# data = Librato::Metrics.get_measurements :temperature, :count => 20
|
203
|
+
#
|
204
|
+
# @example Get 20 most recent data points for a specific source
|
205
|
+
# data = Librato::Metrics.get_measurements :temperature, :count => 20,
|
206
|
+
# :source => 'app1'
|
207
|
+
#
|
208
|
+
# @example Get the 20 most recent 15 minute data point rollups
|
209
|
+
# data = Librato::Metrics.get_measurements :temperature, :count => 20,
|
210
|
+
# :resolution => 900
|
211
|
+
#
|
212
|
+
# @example Get data points for the last hour
|
213
|
+
# data = Librato::Metrics.get_measurements :start_time => Time.now-3600
|
214
|
+
#
|
215
|
+
# @example Get 15 min data points from two hours to an hour ago
|
216
|
+
# data = Librato::Metrics.get_measurements :start_time => Time.now-7200,
|
217
|
+
# :end_time => Time.now-3600,
|
218
|
+
# :resolution => 900
|
219
|
+
#
|
220
|
+
# A full list of query parameters can be found in the API
|
221
|
+
# documentation: {http://dev.librato.com/v1/get/metrics/:name}
|
222
|
+
#
|
223
|
+
# @param [Symbol|String] metric_name Metric name
|
224
|
+
# @param [Hash] options Query options
|
225
|
+
def get_measurements(metric_name, options = {})
|
226
|
+
raise ArgumentError, "you must provide at least a :start_time or :count" if options.empty?
|
227
|
+
get_metric(metric_name, options)["measurements"]
|
170
228
|
end
|
171
229
|
|
172
230
|
# Purge current credentials and connection.
|
@@ -186,7 +244,7 @@ module Librato
|
|
186
244
|
# Librato::Metrics.list :name => 'foo'
|
187
245
|
#
|
188
246
|
# @param [Hash] options
|
189
|
-
def
|
247
|
+
def metrics(options={})
|
190
248
|
query = {}
|
191
249
|
query[:name] = options[:name] if options[:name]
|
192
250
|
offset = 0
|
@@ -194,6 +252,11 @@ module Librato
|
|
194
252
|
Collection.paginated_metrics(connection, path, query)
|
195
253
|
end
|
196
254
|
|
255
|
+
# List currently existing metrics
|
256
|
+
#
|
257
|
+
# @deprecated Use {#metrics} instead
|
258
|
+
def list(options={}); metrics(options); end
|
259
|
+
|
197
260
|
# Create a new queue which uses this client.
|
198
261
|
#
|
199
262
|
# @return [Queue]
|
@@ -232,32 +295,48 @@ module Librato
|
|
232
295
|
@queue.submit
|
233
296
|
end
|
234
297
|
|
235
|
-
# Update
|
236
|
-
# their own hash for updating a single metric but are included inline
|
237
|
-
# when updating multiple metrics.
|
298
|
+
# Update a single metric with new attributes.
|
238
299
|
#
|
239
300
|
# @example Update metric 'temperature'
|
240
|
-
# Librato::Metrics.
|
301
|
+
# Librato::Metrics.update_metric :temperature, :period => 15, :attributes => { :color => 'F00' }
|
241
302
|
#
|
242
303
|
# @example Update metric 'humidity', creating it if it doesn't exist
|
243
|
-
# Librato::Metrics.
|
304
|
+
# Librato::Metrics.update_metric 'humidity', :type => :gauge, :period => 60, :display_name => 'Humidity'
|
305
|
+
#
|
306
|
+
def update_metric(metric, options = {})
|
307
|
+
url = "metrics/#{metric}"
|
308
|
+
connection.put do |request|
|
309
|
+
request.url connection.build_url(url)
|
310
|
+
request.body = SmartJSON.write(options)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
# Update multiple metrics.
|
244
315
|
#
|
245
316
|
# @example Update multiple metrics by name
|
246
|
-
# Librato::Metrics.
|
317
|
+
# Librato::Metrics.update_metrics :names => ["foo", "bar"], :period => 60
|
247
318
|
#
|
248
319
|
# @example Update all metrics that start with 'foo' that aren't 'foobar'
|
249
|
-
# Librato::Metrics.
|
320
|
+
# Librato::Metrics.update_metrics :names => 'foo*', :exclude => ['foobar'], :display_min => 0
|
250
321
|
#
|
251
|
-
def
|
252
|
-
|
253
|
-
url = "metrics" # update multiple metrics
|
254
|
-
options = metric
|
255
|
-
else
|
256
|
-
url = "metrics/#{metric}" # update single
|
257
|
-
end
|
322
|
+
def update_metrics(metrics)
|
323
|
+
url = "metrics" # update multiple metrics
|
258
324
|
connection.put do |request|
|
259
325
|
request.url connection.build_url(url)
|
260
|
-
request.body = SmartJSON.write(
|
326
|
+
request.body = SmartJSON.write(metrics)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
# Update one or more metrics. Note that attributes are specified in
|
331
|
+
# their own hash for updating a single metric but are included inline
|
332
|
+
# when updating multiple metrics.
|
333
|
+
#
|
334
|
+
# @deprecated Use {#update_metric} or {#update_metrics} instead
|
335
|
+
def update(metric, options={})
|
336
|
+
if metric.respond_to?(:each)
|
337
|
+
update_metrics(metric)
|
338
|
+
else
|
339
|
+
update_metric(metric, options)
|
261
340
|
end
|
262
341
|
end
|
263
342
|
|
@@ -278,4 +357,4 @@ module Librato
|
|
278
357
|
end
|
279
358
|
|
280
359
|
end
|
281
|
-
end
|
360
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
DEPRECATED_METHODS = %w[fetch list update delete]
|
4
|
+
describe Librato::Metrics do
|
5
|
+
|
6
|
+
DEPRECATED_METHODS.each do |deprecated_method|
|
7
|
+
it { should respond_to(deprecated_method) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Client" do
|
11
|
+
let(:client) { Librato::Metrics.client }
|
12
|
+
subject { client }
|
13
|
+
|
14
|
+
before(:all) { prep_integration_tests }
|
15
|
+
|
16
|
+
before do
|
17
|
+
client.submit :test_metric => 123.0
|
18
|
+
end
|
19
|
+
|
20
|
+
DEPRECATED_METHODS.each do |deprecated_method|
|
21
|
+
it { should respond_to(deprecated_method) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#fetch" do
|
25
|
+
context "with no measurements attributes" do
|
26
|
+
let(:metric) { client.fetch(:test_metric) }
|
27
|
+
subject { metric }
|
28
|
+
|
29
|
+
it { should_not be_nil }
|
30
|
+
|
31
|
+
it "should return a metric" do
|
32
|
+
metric["name"].should == "test_metric"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with measurements attributes" do
|
37
|
+
let(:measurements) { client.fetch(:test_metric, :count => 1) }
|
38
|
+
subject { measurements }
|
39
|
+
|
40
|
+
it { should_not be_nil }
|
41
|
+
it { should_not be_empty }
|
42
|
+
|
43
|
+
it "should return the measurements" do
|
44
|
+
measurements.should have_key("unassigned")
|
45
|
+
measurements["unassigned"].should be_an(Array)
|
46
|
+
measurements["unassigned"].first["value"].should == 123.0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#list" do
|
52
|
+
let(:metrics) { client.list }
|
53
|
+
subject { metrics }
|
54
|
+
|
55
|
+
it { should_not be_nil }
|
56
|
+
it { should_not be_empty }
|
57
|
+
|
58
|
+
it "should return the list of metrics" do
|
59
|
+
metric = metrics.find { |m| m["name"] == "test_metric" }
|
60
|
+
metric.should_not be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#update" do
|
65
|
+
before do
|
66
|
+
client.update("test_metric", :display_name => "Test Deprecated Update")
|
67
|
+
end
|
68
|
+
|
69
|
+
let(:updated_metric) { client.get_metric("test_metric") }
|
70
|
+
|
71
|
+
it "should update the metric" do
|
72
|
+
updated_metric["display_name"].should == "Test Deprecated Update"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#delete" do
|
77
|
+
it "should delete the metric" do
|
78
|
+
client.metrics(:name => "test_metric").should_not be_empty
|
79
|
+
client.delete("test_metric")
|
80
|
+
client.metrics(:name => "test_metric").should be_empty
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -30,9 +30,9 @@ module Librato
|
|
30
30
|
|
31
31
|
metrics = Metrics.list
|
32
32
|
metrics.length.should == 8
|
33
|
-
counter = Metrics.
|
33
|
+
counter = Metrics.get_measurements :counter_3, :count => 1
|
34
34
|
counter['unassigned'][0]['value'].should == 3
|
35
|
-
gauge = Metrics.
|
35
|
+
gauge = Metrics.get_measurements :gauge_5, :count => 1
|
36
36
|
gauge['unassigned'][0]['value'].should == 5
|
37
37
|
end
|
38
38
|
end
|
@@ -43,10 +43,10 @@ module Librato
|
|
43
43
|
queue.add :bar => {:value => 456, :source => 'barsource'}
|
44
44
|
queue.submit
|
45
45
|
|
46
|
-
foo = Metrics.
|
46
|
+
foo = Metrics.get_measurements :foo, :count => 2
|
47
47
|
foo['default'][0]['value'].should == 123
|
48
48
|
|
49
|
-
bar = Metrics.
|
49
|
+
bar = Metrics.get_measurements :bar, :count => 2
|
50
50
|
bar['barsource'][0]['value'].should == 456
|
51
51
|
end
|
52
52
|
|
@@ -43,7 +43,7 @@ module Librato
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe "#
|
46
|
+
describe "#delete_metrics" do
|
47
47
|
before(:each) { delete_all_metrics }
|
48
48
|
|
49
49
|
context 'by names' do
|
@@ -51,19 +51,19 @@ module Librato
|
|
51
51
|
context "with a single argument" do
|
52
52
|
it "should delete named metric" do
|
53
53
|
Metrics.submit :foo => 123
|
54
|
-
Metrics.
|
55
|
-
Metrics.
|
56
|
-
Metrics.
|
54
|
+
Metrics.metrics(:name => :foo).should_not be_empty
|
55
|
+
Metrics.delete_metrics :foo
|
56
|
+
Metrics.metrics(:name => :foo).should be_empty
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context "with multiple arguments" do
|
61
61
|
it "should delete named metrics" do
|
62
62
|
Metrics.submit :foo => 123, :bar => 345, :baz => 567
|
63
|
-
Metrics.
|
64
|
-
Metrics.
|
65
|
-
Metrics.
|
66
|
-
Metrics.
|
63
|
+
Metrics.delete_metrics :foo, :bar
|
64
|
+
Metrics.metrics(:name => :foo).should be_empty
|
65
|
+
Metrics.metrics(:name => :bar).should be_empty
|
66
|
+
Metrics.metrics(:name => :baz).should_not be_empty
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -71,14 +71,14 @@ module Librato
|
|
71
71
|
it "should run cleanly" do
|
72
72
|
# the API currently returns success even if
|
73
73
|
# the metric has already been deleted or is absent.
|
74
|
-
Metrics.
|
74
|
+
Metrics.delete_metrics :missing
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
context "with no arguments" do
|
79
79
|
it "should not make request" do
|
80
80
|
lambda {
|
81
|
-
Metrics.
|
81
|
+
Metrics.delete_metrics
|
82
82
|
}.should raise_error(Metrics::NoMetricsProvided)
|
83
83
|
end
|
84
84
|
end
|
@@ -88,22 +88,22 @@ module Librato
|
|
88
88
|
context 'by pattern' do
|
89
89
|
it "should filter properly" do
|
90
90
|
Metrics.submit :foo => 1, :foobar => 2, :foobaz => 3, :bar => 4
|
91
|
-
Metrics.
|
91
|
+
Metrics.delete_metrics :names => 'fo*', :exclude => ['foobar']
|
92
92
|
|
93
93
|
%w{foo foobaz}.each do |name|
|
94
94
|
lambda {
|
95
|
-
Metrics.
|
95
|
+
Metrics.get_metric name
|
96
96
|
}.should raise_error(Librato::Metrics::NotFound)
|
97
97
|
end
|
98
98
|
|
99
99
|
%w{foobar bar}.each do |name|
|
100
|
-
Metrics.
|
100
|
+
Metrics.get_metric name # stil exist
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe "#
|
106
|
+
describe "#get_metric" do
|
107
107
|
before(:all) do
|
108
108
|
delete_all_metrics
|
109
109
|
Metrics.submit :my_counter => {:type => :counter, :value => 0, :measure_time => Time.now.to_i-60}
|
@@ -117,7 +117,7 @@ module Librato
|
|
117
117
|
|
118
118
|
context "without arguments" do
|
119
119
|
it "should get metric attributes" do
|
120
|
-
metric = Metrics.
|
120
|
+
metric = Metrics.get_metric :my_counter
|
121
121
|
metric['name'].should == 'my_counter'
|
122
122
|
metric['type'].should == 'counter'
|
123
123
|
end
|
@@ -126,7 +126,8 @@ module Librato
|
|
126
126
|
context "with a start_time" do
|
127
127
|
it "should return entries since that time" do
|
128
128
|
# 1 hr ago
|
129
|
-
|
129
|
+
metric = Metrics.get_metric :my_counter, :start_time => Time.now-3600
|
130
|
+
data = metric['measurements']
|
130
131
|
data['unassigned'].length.should == 3
|
131
132
|
data['baz'].length.should == 2
|
132
133
|
end
|
@@ -134,7 +135,8 @@ module Librato
|
|
134
135
|
|
135
136
|
context "with a count limit" do
|
136
137
|
it "should return that number of entries per source" do
|
137
|
-
|
138
|
+
metric = Metrics.get_metric :my_counter, :count => 2
|
139
|
+
data = metric['measurements']
|
138
140
|
data['unassigned'].length.should == 2
|
139
141
|
data['baz'].length.should == 2
|
140
142
|
end
|
@@ -142,7 +144,8 @@ module Librato
|
|
142
144
|
|
143
145
|
context "with a source limit" do
|
144
146
|
it "should only return that source" do
|
145
|
-
|
147
|
+
metric = Metrics.get_metric :my_counter, :source => 'baz', :start_time => Time.now-3600
|
148
|
+
data = metric['measurements']
|
146
149
|
data['baz'].length.should == 2
|
147
150
|
data['unassigned'].should be_nil
|
148
151
|
end
|
@@ -150,7 +153,7 @@ module Librato
|
|
150
153
|
|
151
154
|
end
|
152
155
|
|
153
|
-
describe "#
|
156
|
+
describe "#metrics" do
|
154
157
|
before(:all) do
|
155
158
|
delete_all_metrics
|
156
159
|
Metrics.submit :foo => 123, :bar => 345, :baz => 678, :foo_2 => 901
|
@@ -158,14 +161,14 @@ module Librato
|
|
158
161
|
|
159
162
|
context "without arguments" do
|
160
163
|
it "should list all metrics" do
|
161
|
-
metric_names = Metrics.
|
164
|
+
metric_names = Metrics.metrics.map { |metric| metric['name'] }
|
162
165
|
metric_names.sort.should == %w{foo bar baz foo_2}.sort
|
163
166
|
end
|
164
167
|
end
|
165
168
|
|
166
169
|
context "with a name argument" do
|
167
170
|
it "should list metrics that match" do
|
168
|
-
metric_names = Metrics.
|
171
|
+
metric_names = Metrics.metrics(:name => 'foo').map { |metric| metric['name'] }
|
169
172
|
metric_names.sort.should == %w{foo foo_2}.sort
|
170
173
|
end
|
171
174
|
end
|
@@ -181,13 +184,13 @@ module Librato
|
|
181
184
|
end
|
182
185
|
|
183
186
|
it "should create the metrics" do
|
184
|
-
metric = Metrics.
|
187
|
+
metric = Metrics.metrics[0]
|
185
188
|
metric['name'].should == 'foo'
|
186
189
|
metric['type'].should == 'gauge'
|
187
190
|
end
|
188
191
|
|
189
192
|
it "should store their data" do
|
190
|
-
data = Metrics.
|
193
|
+
data = Metrics.get_measurements :foo, :count => 1
|
191
194
|
data.should_not be_empty
|
192
195
|
data['unassigned'][0]['value'] == 123.0
|
193
196
|
end
|
@@ -200,13 +203,13 @@ module Librato
|
|
200
203
|
end
|
201
204
|
|
202
205
|
it "should create the metrics" do
|
203
|
-
metric = Metrics.
|
206
|
+
metric = Metrics.metrics[0]
|
204
207
|
metric['name'].should == 'bar'
|
205
208
|
metric['type'].should == 'counter'
|
206
209
|
end
|
207
210
|
|
208
211
|
it "should store their data" do
|
209
|
-
data = Metrics.
|
212
|
+
data = Metrics.get_measurements :bar, :count => 1
|
210
213
|
data.should_not be_empty
|
211
214
|
data['baz'][0]['value'] == 456.0
|
212
215
|
end
|
@@ -225,7 +228,7 @@ module Librato
|
|
225
228
|
|
226
229
|
end
|
227
230
|
|
228
|
-
describe "#
|
231
|
+
describe "#update_metric[s]" do
|
229
232
|
|
230
233
|
context 'with a single metric' do
|
231
234
|
context "with an existing metric" do
|
@@ -235,12 +238,12 @@ module Librato
|
|
235
238
|
end
|
236
239
|
|
237
240
|
it "should update the metric" do
|
238
|
-
Metrics.
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
foo = Metrics.
|
241
|
+
Metrics.update_metric :foo, :display_name => "Foo Metric",
|
242
|
+
:period => 15,
|
243
|
+
:attributes => {
|
244
|
+
:display_max => 1000
|
245
|
+
}
|
246
|
+
foo = Metrics.get_metric :foo
|
244
247
|
foo['display_name'].should == 'Foo Metric'
|
245
248
|
foo['period'].should == 15
|
246
249
|
foo['attributes']['display_max'].should == 1000
|
@@ -250,13 +253,13 @@ module Librato
|
|
250
253
|
context "without an existing metric" do
|
251
254
|
it "should create the metric if type specified" do
|
252
255
|
delete_all_metrics
|
253
|
-
Metrics.
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
foo = Metrics.
|
256
|
+
Metrics.update_metric :foo, :display_name => "Foo Metric",
|
257
|
+
:type => 'gauge',
|
258
|
+
:period => 15,
|
259
|
+
:attributes => {
|
260
|
+
:display_max => 1000
|
261
|
+
}
|
262
|
+
foo = Metrics.get_metric :foo
|
260
263
|
foo['display_name'].should == 'Foo Metric'
|
261
264
|
foo['period'].should == 15
|
262
265
|
foo['attributes']['display_max'].should == 1000
|
@@ -265,11 +268,11 @@ module Librato
|
|
265
268
|
it "should raise error if no type specified" do
|
266
269
|
delete_all_metrics
|
267
270
|
lambda {
|
268
|
-
Metrics.
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
271
|
+
Metrics.update_metric :foo, :display_name => "Foo Metric",
|
272
|
+
:period => 15,
|
273
|
+
:attributes => {
|
274
|
+
:display_max => 1000
|
275
|
+
}
|
273
276
|
}.should raise_error
|
274
277
|
end
|
275
278
|
end
|
@@ -284,28 +287,28 @@ module Librato
|
|
284
287
|
|
285
288
|
it "should support named list" do
|
286
289
|
names = ['my.1', 'my.3']
|
287
|
-
Metrics.
|
290
|
+
Metrics.update_metrics :names => names, :period => 60
|
288
291
|
|
289
292
|
names.each do |name|
|
290
|
-
metric = Metrics.
|
293
|
+
metric = Metrics.get_metric name
|
291
294
|
metric['period'].should == 60
|
292
295
|
end
|
293
296
|
end
|
294
297
|
|
295
298
|
it "should support patterns" do
|
296
|
-
Metrics.
|
299
|
+
Metrics.update_metrics :names => 'my.*', :exclude => ['my.3'],
|
297
300
|
:display_max => 100
|
298
301
|
|
299
302
|
%w{my.1 my.2 my.4}.each do |name|
|
300
|
-
metric = Metrics.
|
303
|
+
metric = Metrics.get_metric name
|
301
304
|
metric['attributes']['display_max'].should == 100
|
302
305
|
end
|
303
306
|
|
304
|
-
excluded = Metrics.
|
307
|
+
excluded = Metrics.get_metric 'my.3'
|
305
308
|
excluded['attributes']['display_max'].should_not == 100
|
306
309
|
end
|
307
310
|
end
|
308
311
|
end
|
309
312
|
|
310
313
|
end
|
311
|
-
end
|
314
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,7 @@ RSpec.configure do |config|
|
|
14
14
|
# purge all metrics from test account
|
15
15
|
def delete_all_metrics
|
16
16
|
connection = Librato::Metrics.client.connection
|
17
|
-
Librato::Metrics.
|
17
|
+
Librato::Metrics.metrics.each do |metric|
|
18
18
|
#puts "deleting #{metric['name']}..."
|
19
19
|
# expects 204
|
20
20
|
connection.delete("metrics/#{metric['name']}")
|
@@ -89,4 +89,4 @@ RSpec::Matchers.define :equal_unordered do |result|
|
|
89
89
|
end
|
90
90
|
target == result
|
91
91
|
end
|
92
|
-
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librato-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
bktaNmhlblFBRjFDSDk2WmNxY0pIMTc5UzJ0SWlLRE04a2VlUklVT1BDM1dU
|
38
38
|
MGZhb2svMgpnQTJvemRyODUxYy9uQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
|
39
39
|
LS0tLS0K
|
40
|
-
date: 2013-
|
40
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: faraday
|
@@ -221,6 +221,7 @@ files:
|
|
221
221
|
- lib/librato/metrics/smart_json.rb
|
222
222
|
- lib/librato/metrics/version.rb
|
223
223
|
- librato-metrics.gemspec
|
224
|
+
- spec/integration/deprecated_methods_spec.rb
|
224
225
|
- spec/integration/metrics/annotator_spec.rb
|
225
226
|
- spec/integration/metrics/connection_spec.rb
|
226
227
|
- spec/integration/metrics/middleware/count_requests_spec.rb
|
@@ -249,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
249
250
|
version: '0'
|
250
251
|
segments:
|
251
252
|
- 0
|
252
|
-
hash:
|
253
|
+
hash: -3545928183344149228
|
253
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
254
255
|
none: false
|
255
256
|
requirements:
|
@@ -263,6 +264,7 @@ signing_key:
|
|
263
264
|
specification_version: 2
|
264
265
|
summary: Ruby wrapper for Librato's Metrics API
|
265
266
|
test_files:
|
267
|
+
- spec/integration/deprecated_methods_spec.rb
|
266
268
|
- spec/integration/metrics/annotator_spec.rb
|
267
269
|
- spec/integration/metrics/connection_spec.rb
|
268
270
|
- spec/integration/metrics/middleware/count_requests_spec.rb
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
�i��i4�(FF�_�t���q���~���op�F�͆1�r��|� ���Ṫy�C�R�H��}���B��9�ct(�?m�+�� +�u2�.!r�˲R&�݃��Y�����Z�
|
1
|
+
����bl�~��z:�dž���g��otd�����Q�����Lfz:�_%�m�,ht��lgR6�=܅E�"�~�Z'6aSo��;�"Kg�L�q�r�_Nrb� 4������P�uo�%���5����5a�����D�r��`dfV�q�6��3���Sů/�ņ,J���ڶm�0�[Q�`��|��%�]�N9S�!���bU%��QJ��e�I�Rޡ�H�����!?�4���>�~�6��H�*��b��Ǟin+�1
|