librato-metrics 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/librato/metrics.rb +1 -0
- data/lib/librato/metrics/client.rb +32 -0
- data/lib/librato/metrics/version.rb +1 -1
- data/spec/integration/metrics_spec.rb +30 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -287,4 +287,4 @@ We also maintain a set of [examples of common uses](https://github.com/librato/l
|
|
287
287
|
|
288
288
|
## Copyright
|
289
289
|
|
290
|
-
Copyright (c) 2011-
|
290
|
+
Copyright (c) 2011-2014 [Librato Inc.](http://librato.com) See LICENSE for details.
|
data/lib/librato/metrics.rb
CHANGED
@@ -387,6 +387,38 @@ module Librato
|
|
387
387
|
end
|
388
388
|
end
|
389
389
|
|
390
|
+
# Create a snapshot of an instrument
|
391
|
+
#
|
392
|
+
# @example Take a snapshot of the instrument at https://metrics-api.librato.com/v1/instruments/42 using a
|
393
|
+
# duration of 3 hours and ending at now.
|
394
|
+
# Librato::Metrics.snapshot(subject: {instrument: {href: "https://metrics-api.librato.com/v1/instruments/42"}},
|
395
|
+
# duration: 3.hours, end_time: Time.now)
|
396
|
+
#
|
397
|
+
# @param Hash options Params for the snapshot
|
398
|
+
# @options options [Hash] :subject An object representing the subject of the snapshot. For now, only instruments are supported
|
399
|
+
# @options options [Numeric] :duration Time interval over which to take the snapshot, defaults to 1 hour
|
400
|
+
# @options options [Numeric, Time] :end_time Snapshot the time period of the duration, ending with end_time. Default is "now".
|
401
|
+
def create_snapshot(options = {})
|
402
|
+
url = "snapshots"
|
403
|
+
response = connection.post do |request|
|
404
|
+
request.url connection.build_url(url)
|
405
|
+
request.body = SmartJSON.write(options)
|
406
|
+
end
|
407
|
+
parsed = SmartJSON.read(response.body)
|
408
|
+
end
|
409
|
+
|
410
|
+
# Retrive a snapshot, to check its progress or find its image_href
|
411
|
+
#
|
412
|
+
# @example Get a snapshot identified by 42
|
413
|
+
# Librato::Metrics.get_snapshot 42
|
414
|
+
#
|
415
|
+
# @param [Integer|String] id
|
416
|
+
def get_snapshot(id)
|
417
|
+
url = "snapshots/#{id}"
|
418
|
+
response = connection.get(url)
|
419
|
+
parsed = SmartJSON.read(response.body)
|
420
|
+
end
|
421
|
+
|
390
422
|
private
|
391
423
|
|
392
424
|
def default_faraday_adapter
|
@@ -355,5 +355,35 @@ module Librato
|
|
355
355
|
|
356
356
|
end
|
357
357
|
|
358
|
+
describe "Snapshots API" do
|
359
|
+
|
360
|
+
let(:instrument_id) do
|
361
|
+
instrument_options = {name: "Snapshot test subject"}
|
362
|
+
conn = Metrics.connection
|
363
|
+
resp = conn.post do |req|
|
364
|
+
req.url conn.build_url("/v1/instruments")
|
365
|
+
req.body = Librato::Metrics::SmartJSON.write(instrument_options)
|
366
|
+
end
|
367
|
+
instrument_id = Librato::Metrics::SmartJSON.read(resp.body)["id"]
|
368
|
+
end
|
369
|
+
|
370
|
+
let(:subject) do
|
371
|
+
{instrument: {href: "http://api.librato.dev/v1/instruments/#{instrument_id}"}}
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should #create_snapshot" do
|
375
|
+
result = Metrics.create_snapshot(subject: subject)
|
376
|
+
result["href"].should =~ /snapshots\/\d+$/
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should #get_snapshot" do
|
380
|
+
result = Metrics.create_snapshot(subject: subject)
|
381
|
+
snapshot_id = result["href"][/(\d+)$/]
|
382
|
+
|
383
|
+
result = Metrics.get_snapshot(snapshot_id)
|
384
|
+
result["href"].should =~ /snapshots\/\d+$/
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
358
388
|
end
|
359
389
|
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.4.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: 2014-
|
40
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: faraday
|
@@ -251,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
251
251
|
version: '0'
|
252
252
|
segments:
|
253
253
|
- 0
|
254
|
-
hash: -
|
254
|
+
hash: -879066088464311398
|
255
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
256
|
none: false
|
257
257
|
requirements:
|
metadata.gz.sig
CHANGED
Binary file
|