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 +13 -5
- data/.rspec +3 -0
- data/.travis.yml +12 -3
- data/README.md +18 -7
- data/examples/client.rb +7 -3
- data/lib/opentsdb/client.rb +12 -13
- data/lib/opentsdb/errors.rb +9 -0
- data/lib/opentsdb/version.rb +1 -1
- data/lib/opentsdb.rb +1 -0
- data/opentsdb.gemspec +14 -12
- data/spec/client_spec.rb +46 -31
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWNlYzdmNjdmN2MyZWZhNWFmMzkxZTI0ZTU5NWJhZmJiNGU5ODI4OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTYwYmQ5ZTU1NmVjMWQyNzgwOTc4Y2EyNzU4OTEwNGIwMGEyMzU3Mg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDliZGY5NTNlZmNhY2FhYmY1MDE5Yjg1ZTUwYjkzNDUxOThmYTNjNTkwNWIz
|
10
|
+
N2I0MGYwZDNiZDA3NTY5YzdmZDAyNjEzYTNlZWY1NTIzMmI3ZTg3MjA1YjEw
|
11
|
+
ZjE3MDk5ZjUzNTQzY2ViMGZmZjA5YjI5ZmQyNmE0NTdjMTcwZDI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2VlYzJlYjI4M2M0MjgzY2QyYzk2MTgyODlkYWM4MWQ3MmQxMzA4ZDBkOGFj
|
14
|
+
ZmQ2MGRhODAxMzQ2ZDgzNWE0NDk0Nzg2MjAyZDJhZjBlNGFlZDdiYjc4NThk
|
15
|
+
M2I5N2FkNzJiZjI1MzQ2YTQwOTdkZjJjMzk2ZGVhM2Q1ZTQ3ODc=
|
data/.rspec
ADDED
data/.travis.yml
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem install bundler
|
1
3
|
language: ruby
|
2
4
|
rvm:
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
21
|
+
```ruby
|
22
|
+
@client = OpenTSDB::Client.new(hostname: 'localhost', port: 4242)
|
18
23
|
|
19
|
-
|
20
|
-
|
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__) +
|
2
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
3
3
|
require 'opentsdb'
|
4
4
|
|
5
|
-
@client = OpenTSDB::Client.new(
|
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)
|
data/lib/opentsdb/client.rb
CHANGED
@@ -8,25 +8,24 @@ module OpenTSDB
|
|
8
8
|
attr_reader :connection
|
9
9
|
|
10
10
|
def initialize(options = {})
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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(
|
21
|
-
timestamp
|
18
|
+
def to_command(options)
|
19
|
+
timestamp = options[:timestamp].to_i
|
22
20
|
metric_name = options[:metric]
|
23
|
-
value
|
24
|
-
tags
|
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.
|
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)
|
data/lib/opentsdb/version.rb
CHANGED
data/lib/opentsdb.rb
CHANGED
data/opentsdb.gemspec
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'opentsdb/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'opentsdb'
|
7
7
|
s.version = OpenTSDB::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
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 =
|
16
|
+
s.rubyforge_project = 'opentsdb'
|
17
17
|
|
18
|
-
s.
|
19
|
-
|
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 = [
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
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
|
14
|
-
expect
|
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
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
29
|
+
timestamp: 1411104988,
|
30
|
+
metric: 'users',
|
31
|
+
value: 100,
|
32
|
+
tags: { foo: 'bar' },
|
20
33
|
}
|
21
|
-
|
34
|
+
|
35
|
+
client.put(metric)
|
22
36
|
end
|
23
37
|
|
24
|
-
it
|
25
|
-
expect(
|
26
|
-
|
27
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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.
|
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:
|
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:
|
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.
|
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: []
|