rtsd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/rtsd.rb +6 -0
- data/lib/rtsd/client.rb +17 -0
- data/lib/rtsd/connection.rb +53 -0
- data/lib/rtsd/version.rb +3 -0
- data/rtsd.gemspec +30 -0
- data/spec/rtsd/client_spec.rb +76 -0
- data/spec/spec_helper.rb +23 -0
- metadata +201 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Donald Plummer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Rtsd
|
2
|
+
|
3
|
+
A Ruby client for OpenTSDB.
|
4
|
+
|
5
|
+
* Initial release planned to just support write API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'rtsd'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rtsd
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Rtsd::Client.new(:hostname => 'localhost', :port => 4242)
|
27
|
+
|
28
|
+
client.put(:metric => 'cheezeburgers.per_second',
|
29
|
+
:value => 9001,
|
30
|
+
:timestamp => Time.now.to_i,
|
31
|
+
:tags => {:ya => 'nope', :host => 'strongbadia')
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rtsd.rb
ADDED
data/lib/rtsd/client.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rtsd
|
2
|
+
class Client
|
3
|
+
attr_reader :connection
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@connection = Rtsd::Connection.new(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def put(params)
|
10
|
+
metric = params.fetch(:metric)
|
11
|
+
timestamp = params[:timestamp] || Time.now.to_i
|
12
|
+
value = params.fetch(:value).to_f
|
13
|
+
tags = params.fetch(:tags, []).map{|k,v| "#{k}=#{v}"}.join(" ")
|
14
|
+
connection.puts "put %s %d %s %s" % [metric, timestamp, value, tags]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'socket'
|
2
|
+
module Rtsd
|
3
|
+
class Connection
|
4
|
+
attr_reader :hostname, :port
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@hostname = options.fetch(:hostname, 'localhost')
|
8
|
+
@port = options.fetch(:port, 4242)
|
9
|
+
end
|
10
|
+
|
11
|
+
def puts(message)
|
12
|
+
reconnect unless connected?
|
13
|
+
|
14
|
+
send_message(message)
|
15
|
+
end
|
16
|
+
|
17
|
+
def connected?
|
18
|
+
!tcp_socket.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def send_message(message)
|
24
|
+
tries = 0
|
25
|
+
|
26
|
+
begin
|
27
|
+
if tcp_socket
|
28
|
+
tcp_socket.puts message
|
29
|
+
end
|
30
|
+
rescue Errno::EPIPE
|
31
|
+
disconnect
|
32
|
+
if tries < 2
|
33
|
+
tries += 1
|
34
|
+
retry if reconnect
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def disconnect
|
40
|
+
@tcp_socket = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def tcp_socket
|
44
|
+
@tcp_socket
|
45
|
+
end
|
46
|
+
|
47
|
+
def reconnect
|
48
|
+
@tcp_socket = TCPSocket.new(hostname, port)
|
49
|
+
rescue Errno::ECONNREFUSED
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/rtsd/version.rb
ADDED
data/rtsd.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rtsd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rtsd"
|
8
|
+
spec.version = Rtsd::VERSION
|
9
|
+
spec.authors = ["Donald Plummer"]
|
10
|
+
spec.email = ["donald.plummer@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby client for OpenTSDB, for writing metrics to the API.}
|
12
|
+
spec.summary = %q{A Ruby client for OpenTSDB.}
|
13
|
+
spec.homepage = "https://github.com/dplummer/rtsd"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.signing_key = "#{ENV['HOME']}/.gem/gem-private_key.pem"
|
16
|
+
spec.cert_chain = ["#{ENV['HOME']}/.gem/gem-public_cert.pem"]
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", ">= 1.1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
28
|
+
spec.add_development_dependency "guard-bundler"
|
29
|
+
spec.add_development_dependency "rb-inotify"
|
30
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rtsd::Client do
|
4
|
+
subject { Rtsd::Client.new(:hostname => 'localhost', :port => 4242) }
|
5
|
+
let(:socket) { mock("Socket", :puts => nil) }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
TCPSocket.stub(:new).and_return(socket)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#put" do
|
12
|
+
let(:timestamp) { Time.now.to_i }
|
13
|
+
let(:params) {{:metric => "cows.count",
|
14
|
+
:value => 42,
|
15
|
+
:timestamp => timestamp,
|
16
|
+
:tags => {:cats => 'meow', :foo => 'bar'}}}
|
17
|
+
|
18
|
+
it "builds a tcp socket connection" do
|
19
|
+
TCPSocket.should_receive(:new).with('localhost', 4242)
|
20
|
+
subject.put(params)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "puts the formatted data on the socket" do
|
24
|
+
socket.should_receive(:puts).with("put cows.count #{timestamp} 42.0 cats=meow foo=bar")
|
25
|
+
subject.put(params)
|
26
|
+
end
|
27
|
+
|
28
|
+
context "no server listening" do
|
29
|
+
before(:each) do
|
30
|
+
TCPSocket.stub(:new).and_raise(Errno::ECONNREFUSED)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not raise" do
|
34
|
+
expect {
|
35
|
+
subject.put(params)
|
36
|
+
}.to_not raise_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "server goes away" do
|
41
|
+
before(:each) do
|
42
|
+
socket.stub(:puts).and_raise(Errno::EPIPE)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not raise" do
|
46
|
+
expect {
|
47
|
+
subject.put(params)
|
48
|
+
}.to_not raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it "retries 3 times" do
|
52
|
+
socket.should_receive(:puts).exactly(3).times
|
53
|
+
subject.put(params)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "server has really gone away" do
|
57
|
+
before(:each) do
|
58
|
+
@times = 0
|
59
|
+
TCPSocket.stub(:new) do |h,p|
|
60
|
+
@times += 1
|
61
|
+
if @times == 1
|
62
|
+
socket
|
63
|
+
else
|
64
|
+
raise Errno::ECONNREFUSED
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does not retry 3 times" do
|
70
|
+
socket.should_receive(:puts).exactly(1).times
|
71
|
+
subject.put(params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
if RUBY_VERSION =~ /1.8/
|
20
|
+
require 'require_relative'
|
21
|
+
end
|
22
|
+
|
23
|
+
require_relative '../lib/rtsd'
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtsd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Donald Plummer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRcwFQYDVQQDDA5kb25h
|
20
|
+
bGQucGx1bW1lcjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQB
|
21
|
+
GRYDY29tMB4XDTEzMDQwNzE3MzA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
83hy5JO2AhXPlQJF/Tc0VdNU
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2013-04-07 00:00:00 Z
|
40
|
+
dependencies:
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 25
|
50
|
+
segments:
|
51
|
+
- 1
|
52
|
+
- 1
|
53
|
+
- 5
|
54
|
+
version: 1.1.5
|
55
|
+
type: :development
|
56
|
+
version_requirements: *id001
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rake
|
59
|
+
prerelease: false
|
60
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id002
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id003
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: guard
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
type: :development
|
98
|
+
version_requirements: *id004
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: guard-rspec
|
101
|
+
prerelease: false
|
102
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
type: :development
|
112
|
+
version_requirements: *id005
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: guard-bundler
|
115
|
+
prerelease: false
|
116
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
type: :development
|
126
|
+
version_requirements: *id006
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: rb-inotify
|
129
|
+
prerelease: false
|
130
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
type: :development
|
140
|
+
version_requirements: *id007
|
141
|
+
description: A Ruby client for OpenTSDB, for writing metrics to the API.
|
142
|
+
email:
|
143
|
+
- donald.plummer@gmail.com
|
144
|
+
executables: []
|
145
|
+
|
146
|
+
extensions: []
|
147
|
+
|
148
|
+
extra_rdoc_files: []
|
149
|
+
|
150
|
+
files:
|
151
|
+
- .gitignore
|
152
|
+
- .rspec
|
153
|
+
- Gemfile
|
154
|
+
- Guardfile
|
155
|
+
- LICENSE.txt
|
156
|
+
- README.md
|
157
|
+
- Rakefile
|
158
|
+
- lib/rtsd.rb
|
159
|
+
- lib/rtsd/client.rb
|
160
|
+
- lib/rtsd/connection.rb
|
161
|
+
- lib/rtsd/version.rb
|
162
|
+
- rtsd.gemspec
|
163
|
+
- spec/rtsd/client_spec.rb
|
164
|
+
- spec/spec_helper.rb
|
165
|
+
homepage: https://github.com/dplummer/rtsd
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
none: false
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
hash: 3
|
179
|
+
segments:
|
180
|
+
- 0
|
181
|
+
version: "0"
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
hash: 3
|
188
|
+
segments:
|
189
|
+
- 0
|
190
|
+
version: "0"
|
191
|
+
requirements: []
|
192
|
+
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 1.8.24
|
195
|
+
signing_key:
|
196
|
+
specification_version: 3
|
197
|
+
summary: A Ruby client for OpenTSDB.
|
198
|
+
test_files:
|
199
|
+
- spec/rtsd/client_spec.rb
|
200
|
+
- spec/spec_helper.rb
|
201
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|