opentsdb 0.2.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b9c05b82d4390fd75cad12cf522d8d85a4ad3120
4
- data.tar.gz: 9d7453a648b67f73f0086c992f4f7e8c6b77e247
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWNlYzdmNjdmN2MyZWZhNWFmMzkxZTI0ZTU5NWJhZmJiNGU5ODI4OQ==
5
+ data.tar.gz: !binary |-
6
+ MTYwYmQ5ZTU1NmVjMWQyNzgwOTc4Y2EyNzU4OTEwNGIwMGEyMzU3Mg==
5
7
  SHA512:
6
- metadata.gz: 80126de66e433fa14a7cf4474fc2f042978b870c0f95811c214e4c359b3ab289167cc832e8de37f3cb9de2782e34a20f1782e6abcbb658f186cf2d4e6823ea00
7
- data.tar.gz: b80ebfbd5e83730c3aa4074828bf7da05861fc8a54ffac2436d5bce5bc9621cc6846e17e24e56d994f1f5934dd26e2e956511865dbe97cbd7bd4e4128c1e1607
8
+ metadata.gz: !binary |-
9
+ MDliZGY5NTNlZmNhY2FhYmY1MDE5Yjg1ZTUwYjkzNDUxOThmYTNjNTkwNWIz
10
+ N2I0MGYwZDNiZDA3NTY5YzdmZDAyNjEzYTNlZWY1NTIzMmI3ZTg3MjA1YjEw
11
+ ZjE3MDk5ZjUzNTQzY2ViMGZmZjA5YjI5ZmQyNmE0NTdjMTcwZDI=
12
+ data.tar.gz: !binary |-
13
+ N2VlYzJlYjI4M2M0MjgzY2QyYzk2MTgyODlkYWM4MWQ3MmQxMzA4ZDBkOGFj
14
+ ZmQ2MGRhODAxMzQ2ZDgzNWE0NDk0Nzg2MjAyZDJhZjBlNGFlZDdiYjc4NThk
15
+ M2I5N2FkNzJiZjI1MzQ2YTQwOTdkZjJjMzk2ZGVhM2Q1ZTQ3ODc=
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format doc
data/.travis.yml CHANGED
@@ -1,5 +1,14 @@
1
+ before_install:
2
+ - gem install bundler
1
3
  language: ruby
2
4
  rvm:
3
- - 1.9.3
4
- - 2.0
5
- - 2.1
5
+ - 1.9.3
6
+ - 2.0
7
+ - 2.1
8
+ deploy:
9
+ provider: rubygems
10
+ gem: opentsdb
11
+ api_key:
12
+ secure: c/2n2sHe7gba+OqBrH5YKxWFJ1klbOW5LRT67oIPnYBChRpdpzAx7CNFgpzXu3TQ77LbY0WChKAai4exvM4E752vj41r3Xdrk0xPAfUY/y51szexDLk9mT1s7VdXCCmPr+Y1e5eV9VZxK+heJyy4gejPsgStNS8qgua+859Xpz4=
13
+ on:
14
+ branch: master
data/README.md CHANGED
@@ -4,21 +4,32 @@ Status](https://travis-ci.org/johnewart/ruby-opentsdb.svg?branch=master)](https:
4
4
 
5
5
  ## What is this?
6
6
 
7
- This is a Ruby client for simplifying interactions with OpenTSDB
7
+ This is a Ruby client for simplifying interactions with OpenTSDB.
8
8
 
9
9
  ## What does it do?
10
10
 
11
- As of this instant, not a whole lot except wrap the "put" method in a
12
- quick-and-dirty style. This will eventually grow to be much more useful
13
- as I expand functionality.
11
+ As of this instant, not a whole lot except wrap the "put" method in a
12
+ quick-and-dirty style. This will eventually grow to be much more useful
13
+ as I expand functionality.
14
+
15
+ ## Requirements
16
+
17
+ ruby 1.9.3+
14
18
 
15
19
  ## Quick example
16
20
 
17
- @client = OpenTSDB::Client.new({:hostname => 'localhost', :port => 4242})
21
+ ```ruby
22
+ @client = OpenTSDB::Client.new(hostname: 'localhost', port: 4242)
18
23
 
19
- sample = { :metric => 'double_rainbow.count', :value => 42, :timestamp => Time.now.to_i, :tags => {:factor => 'awesome', :host => 'ponies' } }
20
- @client.put(sample)
24
+ sample = {
25
+ metric: 'double_rainbow.count',
26
+ value: 42,
27
+ timestamp: Time.now.to_i,
28
+ tags: { factor: 'awesome', host: 'ponies' }
29
+ }
21
30
 
31
+ @client.put(sample)
32
+ ```
22
33
 
23
34
  ## License
24
35
 
data/examples/client.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require 'rubygems'
2
- $:.unshift File.dirname(__FILE__) + "/../lib"
2
+ $:.unshift File.dirname(__FILE__) + '/../lib'
3
3
  require 'opentsdb'
4
4
 
5
- @client = OpenTSDB::Client.new({:hostname => 'localhost', :port => 4242})
5
+ @client = OpenTSDB::Client.new(hostname: 'localhost', port: 4242)
6
+
7
+ sample = {
8
+ metric: 'double_rainbow.count', value: 42, timestamp: Time.now.to_i,
9
+ tags: { factor: 'awesome', host: 'ponies' }
10
+ }
6
11
 
7
- sample = { :metric => 'double_rainbow.count', :value => 42, :timestamp => Time.now.to_i, :tags => {:factor => 'awesome', :host => 'ponies' } }
8
12
  @client.put(sample)
@@ -8,25 +8,24 @@ module OpenTSDB
8
8
  attr_reader :connection
9
9
 
10
10
  def initialize(options = {})
11
- begin
12
- hostname = options[:hostname] || 'localhost'
13
- port = options[:port] || 4242
14
- @connection = TCPSocket.new(hostname, port)
15
- rescue
16
- raise "Unable to connect or invalid connection data"
17
- end
11
+ hostname = options[:hostname] || 'localhost'
12
+ port = options[:port] || 4242
13
+ @connection = TCPSocket.new(hostname, port)
14
+ rescue
15
+ raise Errors::UnableToConnectError
18
16
  end
19
17
 
20
- def to_command( options )
21
- timestamp = options[:timestamp].to_i
18
+ def to_command(options)
19
+ timestamp = options[:timestamp].to_i
22
20
  metric_name = options[:metric]
23
- value = options[:value].to_f
24
- tags = options[:tags].map{|k,v| "#{k}=#{v}"}.join(" ")
21
+ value = options[:value].to_f
22
+ tags = options[:tags].map { |k, v| "#{k}=#{v}" }.join(' ')
23
+
25
24
  "put #{metric_name} #{timestamp} #{value} #{tags}"
26
25
  end
27
26
 
28
- def build_command(input)
29
- if input.kind_of?(Array)
27
+ def build_command(input)
28
+ if input.is_a?(Array)
30
29
  input.collect { |unit| to_command(unit) }.join("\n")
31
30
  else
32
31
  to_command(input)
@@ -0,0 +1,9 @@
1
+ module OpenTSDB
2
+ module Errors
3
+ class UnableToConnectError < StandardError
4
+ def to_s
5
+ 'Unable to connect or invalid connection data'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module OpenTSDB
2
- VERSION = "0.2.0"
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/opentsdb.rb CHANGED
@@ -12,4 +12,5 @@ module OpenTSDB
12
12
  end
13
13
  end
14
14
 
15
+ require 'opentsdb/errors'
15
16
  require 'opentsdb/client'
data/opentsdb.gemspec CHANGED
@@ -1,25 +1,27 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "opentsdb/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'opentsdb/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "opentsdb"
6
+ s.name = 'opentsdb'
7
7
  s.version = OpenTSDB::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["John Ewart"]
10
- s.email = ["john@johnewart.net"]
11
- s.homepage = "https://github.com/johnewart/ruby-opentsdb"
12
- s.summary = %q{Ruby client for OpenTSDB}
13
- s.description = %q{A Ruby implementation of a client library for sending data points to OpenTSDB}
9
+ s.authors = ['John Ewart']
10
+ s.email = ['john@johnewart.net']
11
+ s.homepage = 'https://github.com/johnewart/ruby-opentsdb'
12
+ s.summary = 'Ruby client for OpenTSDB'
13
+ s.description = 'A Ruby implementation of a client library for sending data points to OpenTSDB'
14
14
  s.license = 'MIT'
15
15
 
16
- s.rubyforge_project = "opentsdb"
16
+ s.rubyforge_project = 'opentsdb'
17
17
 
18
- s.add_development_dependency "rspec"
19
- s.add_development_dependency "simplecov", [">= 0.3.8"] #, :require => false
18
+ s.required_ruby_version = '>= 1.9.3'
19
+
20
+ s.add_development_dependency 'rspec'
21
+ s.add_development_dependency 'simplecov', ['>= 0.3.8']
20
22
 
21
23
  s.files = `git ls-files`.split("\n")
22
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
25
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
- s.require_paths = ["lib"]
26
+ s.require_paths = ['lib']
25
27
  end
data/spec/client_spec.rb CHANGED
@@ -1,45 +1,60 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe OpenTSDB::Client do
4
- before :each do
5
- @socket = double('socket').as_null_object
6
- expect(TCPSocket).to receive(:new).and_return(@socket)
7
- @client = OpenTSDB::Client.new
4
+ let(:socket) { double('socket').as_null_object }
5
+ let(:client) { described_class.new }
6
+
7
+ before(:each) do
8
+ allow(TCPSocket).to receive(:new).and_return(socket)
8
9
  end
9
-
10
- it "should create a new client" do
10
+
11
+ describe 'error handling' do
12
+ subject { described_class.new }
13
+
14
+ it 'raises a custom error if the connection failed' do
15
+ expect(TCPSocket).to receive(:new).and_raise('connection error')
16
+
17
+ expect { subject }.to raise_error(OpenTSDB::Errors::UnableToConnectError)
18
+ end
11
19
  end
12
20
 
13
- it "should write a single metric to the socket" do
14
- expect(@socket).to receive(:puts).with("put users 1411104988 100.0 foo=bar")
21
+ it 'creates a new client' do
22
+ expect { client }.to_not raise_error
23
+ end
24
+
25
+ it 'writes a single metric to the socket' do
26
+ expect(socket).to receive(:puts).with('put users 1411104988 100.0 foo=bar')
27
+
15
28
  metric = {
16
- :timestamp => 1411104988,
17
- :metric => "users",
18
- :value => 100,
19
- :tags => { :foo => "bar" }
29
+ timestamp: 1411104988,
30
+ metric: 'users',
31
+ value: 100,
32
+ tags: { foo: 'bar' },
20
33
  }
21
- @client.put(metric)
34
+
35
+ client.put(metric)
22
36
  end
23
37
 
24
- it "should write multiple metrics to the socket" do
25
- expect(@socket).to receive(:puts).with("put users 1411104988 100.0 foo=bar\nput users 1411104999 150.0 bar=baz")
26
- metrics = []
27
- metrics << {
28
- :timestamp => 1411104988,
29
- :metric => "users",
30
- :value => 100,
31
- :tags => { :foo => "bar" }
32
- }
38
+ it 'writes multiple metrics to the socket' do
39
+ expect(socket).to receive(:puts).with(
40
+ "put users 1411104988 100.0 foo=bar\nput users 1411104999 150.0 bar=baz"
41
+ )
33
42
 
34
- metrics << {
35
- :timestamp => 1411104999,
36
- :metric => "users",
37
- :value => 150,
38
- :tags => { :bar => "baz" }
39
- }
43
+ metrics = [
44
+ {
45
+ timestamp: 1411104988,
46
+ metric: 'users',
47
+ value: 100,
48
+ tags: { foo: 'bar' },
49
+ },
50
+ {
51
+ timestamp: 1411104999,
52
+ metric: 'users',
53
+ value: 150,
54
+ tags: { bar: 'baz' },
55
+ },
56
+ ]
40
57
 
41
- @client.put(metrics)
42
-
58
+ client.put(metrics)
43
59
  end
44
-
45
60
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentsdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.3.8
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.8
41
41
  description: A Ruby implementation of a client library for sending data points to
@@ -47,6 +47,7 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - .gitignore
50
+ - .rspec
50
51
  - .travis.yml
51
52
  - CHANGELOG.md
52
53
  - Gemfile
@@ -57,6 +58,7 @@ files:
57
58
  - examples/client.rb
58
59
  - lib/opentsdb.rb
59
60
  - lib/opentsdb/client.rb
61
+ - lib/opentsdb/errors.rb
60
62
  - lib/opentsdb/logging.rb
61
63
  - lib/opentsdb/version.rb
62
64
  - opentsdb.gemspec
@@ -72,20 +74,18 @@ require_paths:
72
74
  - lib
73
75
  required_ruby_version: !ruby/object:Gem::Requirement
74
76
  requirements:
75
- - - '>='
77
+ - - ! '>='
76
78
  - !ruby/object:Gem::Version
77
- version: '0'
79
+ version: 1.9.3
78
80
  required_rubygems_version: !ruby/object:Gem::Requirement
79
81
  requirements:
80
- - - '>='
82
+ - - ! '>='
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  requirements: []
84
86
  rubyforge_project: opentsdb
85
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.5.1
86
88
  signing_key:
87
89
  specification_version: 4
88
90
  summary: Ruby client for OpenTSDB
89
- test_files:
90
- - spec/client_spec.rb
91
- - spec/spec_helper.rb
91
+ test_files: []