opentsdb-consumer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c0623e847a6d3b545478b8f88ac2713f6c59ce8
4
- data.tar.gz: 2582a841255df62953b4bf9449abe1d88c650491
3
+ metadata.gz: 3946790fd8040a154653d58d3729179da5300548
4
+ data.tar.gz: efb1a9798819da7e28133d7d95f82227a36cad36
5
5
  SHA512:
6
- metadata.gz: 6502e41191581754ae67e3a40096fea1ed1b8b6c764358d0d6bd2b3a7a5234b2bbc354754c596fb6e3b983d8c4cc7024fc8e5857028429668f5ec827285d57f7
7
- data.tar.gz: c9ad627a9fc31950b5a5742469093e51a98a9d844029518e8dac69303d0c349924665607b185154646e9ade46d2f73044dd4cd7135d366538fdbd9d9086f02a6
6
+ metadata.gz: 7cccd3f3fa6cdb099815724d4640301c21cc2e9e623c89274b6c18ff71095dc2a3ee387f90e92af030935c4682b5b19c6f2038ae1bd6a0831d6c6e4db8f50f17
7
+ data.tar.gz: 60d00471c835408a5cf13b3f3b3fbc45c135614801d12abcb664f7aa986dbac5df8cd9e7d21ef7f86b5d90bfc1531e88f85417c4eadce0f844388ec308da9de8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -18,6 +18,11 @@ module OpenTSDBConsumer
18
18
  fail error_for_response(response_message), response_message
19
19
  end
20
20
 
21
+ def latest_value(start: '1m-ago')
22
+ result = run(start: start)
23
+ result.latest_value if result
24
+ end
25
+
21
26
  private
22
27
 
23
28
  def request_body(start)
@@ -13,5 +13,10 @@ module OpenTSDBConsumer
13
13
  results = response.map { |h| new(h) }
14
14
  results.length > 1 ? results : results.first
15
15
  end
16
+
17
+ def latest_value
18
+ datapoint = datapoints.max_by { |timestamp, _| timestamp }
19
+ datapoint.last if datapoint
20
+ end
16
21
  end
17
22
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: opentsdb-consumer 0.2.0 ruby lib
5
+ # stub: opentsdb-consumer 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "opentsdb-consumer"
9
- s.version = "0.2.0"
9
+ s.version = "0.3.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Philippe H\u{e4}ssig"]
14
- s.date = "2015-11-18"
14
+ s.date = "2015-12-07"
15
15
  s.description = "Client library to consume metrics from OpenTSDB"
16
16
  s.email = "phil@nine.ch"
17
17
  s.executables = ["opentsdb-consumer"]
@@ -55,4 +55,15 @@ RSpec.describe OpenTSDBConsumer::Query do
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ describe '#latest_value' do
60
+ let(:response_body) do
61
+ %([{"metric":"yolo","tags":{"node":"n1"},"dps":{"1448965805":1.95,"1448965864":2.21}}])
62
+ end
63
+
64
+ it 'returns the latest value in the series' do
65
+ expect(client).to receive(:post).and_return(mock_response)
66
+ expect(query.latest_value).to eq(2.21)
67
+ end
68
+ end
58
69
  end
@@ -30,4 +30,16 @@ RSpec.describe OpenTSDBConsumer::Result do
30
30
  expect(results.last).to be_a OpenTSDBConsumer::Result
31
31
  end
32
32
  end
33
+
34
+ describe '#latest_value' do
35
+ it 'returns to newest value in the series' do
36
+ result = OpenTSDBConsumer::Result.new 'dps' => { '111' => 1, '333' => 3, '222' => 2 }
37
+ expect(result.latest_value).to eq(3)
38
+ end
39
+
40
+ it 'returns nil when no datapoints are found' do
41
+ result = OpenTSDBConsumer::Result.new 'dps' => {}
42
+ expect(result.latest_value).to be_nil
43
+ end
44
+ end
33
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentsdb-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Hässig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon