wavefront-client 0.5.2

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.
@@ -0,0 +1,55 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ require "wavefront/client/version"
18
+ require "wavefront/exception"
19
+ require 'uri'
20
+ require 'socket'
21
+
22
+ module Wavefront
23
+ class Writer
24
+ DEFAULT_AGENT_HOST = 'localhost'
25
+ DEFAULT_PORT = 2878
26
+ DEFAULT_HOSTNAME = %x{hostname -f}.chomp
27
+
28
+ def initialize(options = {})
29
+ options[:agent_host] ||= DEFAULT_AGENT_HOST
30
+ options[:agent_port] ||= DEFAULT_PORT
31
+ options[:host_name] ||= DEFAULT_HOSTNAME
32
+ options[:metric_name] ||= ''
33
+ options[:point_tags] ||= {}
34
+
35
+ @host_name = options[:host_name]
36
+ @metric_name = options[:metric_name]
37
+ @point_tags = options[:point_tags]
38
+
39
+ @socket = get_socket(options[:agent_host], options[:agent_port])
40
+ end
41
+
42
+ def write(metric_value, metric_name=@metric_name, host=@host_name, point_tags=@point_tags, timestamp=Time.now)
43
+ raise Wavefront::Exception::EmptyMetricName if metric_name.empty?
44
+ tags = point_tags.empty? ? '' : point_tags.map{|k,v| "#{k}=\"#{v}\""}.join(' ')
45
+ append = tags.empty? ? "host=#{host}" : "host=#{host} #{tags}"
46
+ @socket.puts "#{metric_name} #{metric_value} #{timestamp.to_i} #{append}"
47
+ end
48
+
49
+ private
50
+ def get_socket(host,port)
51
+ TCPSocket.new(host, port)
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1 @@
1
+ {"query":"ts(\"collectd.memory.memory.cached\", host=\"test.server\")","name":"Unknown","timeseries":[{"label":"collectd.memory.memory.cached","host":"test.server","data":[[1436487780,4.625565013333333E8],[1436487840,4.625646933333333E8],[1436487900,4.625728853333333E8],[1436487960,4.625810773333333E8],[1436488020,4.625926826666667E8],[1436488080,4.626015573333333E8],[1436488140,4.626097493333333E8],[1436488200,4.626179413333333E8],[1436488260,4.626261333333333E8],[1436488320,4.626343253333333E8],[1436488380,4.626425173333333E8],[1436488440,4.626507093333333E8],[1436488500,4.626589013333333E8],[1436488560,4.626670933333333E8],[1436488620,4.626752853333333E8],[1436488680,4.626868906666667E8],[1436488740,4.626957653333333E8],[1436488800,4.627039573333333E8],[1436488860,4.627121493333333E8],[1436488920,4.627203413333333E8],[1436488980,4.6272512E8]]}],"granularity":60,"stats":{"keys":24,"points":1336,"summaries":1314,"summarized_points":0,"summarized_summaries":0,"buffer_keys":24,"compacted_keys":2,"compacted_points":1314,"latency":78,"queries":2,"s3_keys":0,"cpu_ns":5412921}}
@@ -0,0 +1,23 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
18
+ require 'wavefront/client'
19
+ require 'wavefront/writer'
20
+ require 'wavefront/metadata'
21
+
22
+ TEST_TOKEN = "test"
23
+ TEST_HOST = "metrics.wavefront.com"
@@ -0,0 +1,47 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ require 'spec_helper'
18
+ require 'pathname'
19
+
20
+ describe Wavefront::Client do
21
+ it 'has a version number' do
22
+ expect(Wavefront::Client::VERSION).to_not be_nil
23
+ end
24
+
25
+ it 'has some defaults' do
26
+ expect(Wavefront::Client::DEFAULT_PERIOD_SECONDS).to_not be_nil
27
+ expect(Wavefront::Client::DEFAULT_PERIOD_SECONDS).to be_a_kind_of Fixnum
28
+ expect(Wavefront::Client::DEFAULT_HOST).to_not be_nil
29
+ expect(Wavefront::Client::DEFAULT_HOST).to be_a_kind_of String
30
+ expect(Wavefront::Client::DEFAULT_PATH).to_not be_nil
31
+ expect(Wavefront::Client::DEFAULT_PATH).to be_a_kind_of String
32
+ expect(Wavefront::Client::DEFAULT_FORMAT).to_not be_nil
33
+ expect(Wavefront::Client::DEFAULT_FORMAT).to be_a_kind_of Symbol
34
+ expect(Wavefront::Client::GRANULARITIES).to_not be_nil
35
+ expect(Wavefront::Client::GRANULARITIES).to be_a_kind_of Array
36
+ end
37
+
38
+
39
+ describe "#initialize" do
40
+ it 'accepts a token when initialized and expose it for reading' do
41
+ wave = Wavefront::Client.new(TEST_TOKEN)
42
+ headers = {'X-AUTH-TOKEN' => TEST_TOKEN}
43
+ expect(wave.headers).to eq headers
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,38 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ require 'spec_helper'
18
+ require 'pathname'
19
+
20
+ describe Wavefront::Metadata do
21
+
22
+ it 'has some defaults' do
23
+ expect(Wavefront::Metadata::DEFAULT_HOST).to_not be_nil
24
+ expect(Wavefront::Metadata::DEFAULT_HOST).to be_a_kind_of String
25
+ expect(Wavefront::Metadata::DEFAULT_PATH).to_not be_nil
26
+ expect(Wavefront::Metadata::DEFAULT_PATH).to be_a_kind_of String
27
+ end
28
+
29
+
30
+ describe "#initialize" do
31
+ it 'accepts a token option initialized and exposes request header for reading' do
32
+ wave = Wavefront::Metadata.new(TEST_TOKEN)
33
+ headers = {'X-AUTH-TOKEN' => TEST_TOKEN}
34
+ expect(wave.headers).to eq headers
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,74 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ require 'spec_helper'
18
+ require 'pathname'
19
+
20
+ RESPONSE = 'test'
21
+
22
+ describe Wavefront::Response::Raw do
23
+ it 'exposes the response' do
24
+ response = Wavefront::Response::Raw.new(RESPONSE)
25
+ expect(response).to respond_to(:response)
26
+ expect(response.response).to eq RESPONSE
27
+ end
28
+
29
+ it 'overloads to_s and returns the response' do
30
+ response = Wavefront::Response::Raw.new(RESPONSE)
31
+ expect(response).to respond_to(:to_s)
32
+ expect(response.to_s).to eq RESPONSE
33
+ end
34
+ end
35
+
36
+ describe Wavefront::Response::Ruby do
37
+ it 'exposes the response' do
38
+ example_response = File.read(Pathname.new(__FILE__).parent.parent.join('example_response.json'))
39
+ response = Wavefront::Response::Ruby.new(example_response)
40
+ expect(response).to respond_to(:response)
41
+ expect(response.response).to eq example_response
42
+ end
43
+
44
+ it 'dynamically sets accessors for each part of the response' do
45
+ example_response = File.read(Pathname.new(__FILE__).parent.parent.join('example_response.json'))
46
+ response = Wavefront::Response::Ruby.new(example_response)
47
+
48
+ %w(response query name timeseries stats).each do |part|
49
+ expect(response).to respond_to(part)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe Wavefront::Response::Graphite do
55
+ it 'returns something that resembles some graphite output' do
56
+ example_response = File.read(Pathname.new(__FILE__).parent.parent.join('example_response.json'))
57
+ response = Wavefront::Response::Graphite.new(example_response)
58
+
59
+ expect(response.graphite.size).to eq(1)
60
+ expect(response.graphite[0].keys.size).to eq(2)
61
+ expect(response.graphite[0]['target']).to eq(response.query)
62
+ expect(response.graphite[0]['datapoints'].size).to eq(21)
63
+ end
64
+ end
65
+
66
+ describe Wavefront::Response::Highcharts do
67
+ it 'returns something that resembles highcharts output' do
68
+ example_response = File.read(Pathname.new(__FILE__).parent.parent.join('example_response.json'))
69
+ response = Wavefront::Response::Highcharts.new(example_response)
70
+
71
+ expect(JSON.parse(response.to_json).size).to eq(response.timeseries.size)
72
+ JSON.parse(response.to_json).each { |m| expect(m.keys.size).to eq(2) }
73
+ end
74
+ end
@@ -0,0 +1,94 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ require 'spec_helper'
18
+ require 'pathname'
19
+ require 'socket'
20
+
21
+ class Mocket
22
+ def puts(str)
23
+ return true
24
+ end
25
+ end
26
+
27
+ describe Wavefront::Writer do
28
+
29
+ it 'has some defaults' do
30
+ expect(Wavefront::Writer::DEFAULT_HOST).to_not be_nil
31
+ expect(Wavefront::Writer::DEFAULT_HOST).to be_a_kind_of String
32
+ expect(Wavefront::Writer::DEFAULT_PORT).to_not be_nil
33
+ expect(Wavefront::Writer::DEFAULT_PORT).to be_a_kind_of Fixnum
34
+ expect(Wavefront::Writer::DEFAULT_HOSTNAME).to_not be_nil
35
+ expect(Wavefront::Writer::DEFAULT_HOSTNAME).to be_a_kind_of String
36
+ end
37
+
38
+
39
+ describe "#initialize" do
40
+ it 'creates a socket object with the default parameters' do
41
+ allow(TCPSocket).to receive(:new)
42
+ expect(TCPSocket).to receive(:new).with('localhost', Wavefront::Writer::DEFAULT_PORT)
43
+ writer = Wavefront::Writer.new
44
+ end
45
+
46
+ it 'creates a socket object with parameters if specified' do
47
+ host = 'somehost'
48
+ port = '8566'
49
+ allow(TCPSocket).to receive(:new)
50
+ expect(TCPSocket).to receive(:new).with(host, port)
51
+ writer = Wavefront::Writer.new({:agent_host => host, :agent_port => port})
52
+ end
53
+ end
54
+
55
+ describe "#write" do
56
+ it 'should write a metric to a socket object' do
57
+ host = 'somehost'
58
+ port = '8566'
59
+ delay = 0
60
+ socket = Mocket.new
61
+ allow(TCPSocket).to receive(:new).and_return(socket)
62
+ allow(Time).to receive(:now).and_return(123456789)
63
+ expect(socket).to receive(:puts).with("metric 50 123456789 host=somehost")
64
+ writer = Wavefront::Writer.new
65
+ writer.write(50, "metric", host, {}, 123456789)
66
+ end
67
+
68
+ it 'should accept a single tag and append it correctly' do
69
+ host = 'somehost'
70
+ port = '8566'
71
+ tags = {'tag_key_one' => 'tag_val_one'}
72
+ socket = Mocket.new
73
+ allow(TCPSocket).to receive(:new).and_return(socket)
74
+ allow(Time).to receive(:now).and_return(123456789)
75
+ expect(socket).to receive(:puts).with("metric 50 123456789 host=somehost tag_key_one=\"tag_val_one\"")
76
+ writer = Wavefront::Writer.new
77
+ writer.write(50, "metric", host, tags, 123456789)
78
+ end
79
+
80
+ it 'should accept multiple tags and append them correctly' do
81
+ host = 'somehost'
82
+ port = '8566'
83
+ tags = {'tag_key_one' => 'tag_val_one', 'k2' => 'v2'}
84
+ socket = Mocket.new
85
+ allow(TCPSocket).to receive(:new).and_return(socket)
86
+ allow(Time).to receive(:now).and_return(123456789)
87
+ expect(socket).to receive(:puts).with("metric 50 123456789 host=somehost tag_key_one=\"tag_val_one\" k2=\"v2\"")
88
+ writer = Wavefront::Writer.new
89
+ writer.write(50, "metric", host, tags, 123456789)
90
+
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,46 @@
1
+ =begin
2
+ Copyright 2015 Wavefront Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ =end
16
+
17
+ # coding: utf-8
18
+ lib = File.expand_path('../lib', __FILE__)
19
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
+ require 'wavefront/client/version'
21
+
22
+ Gem::Specification.new do |spec|
23
+ spec.name = "wavefront-client"
24
+ spec.version = Wavefront::Client::VERSION
25
+ spec.authors = ["Sam Pointer", "Louis McCormack", "Joshua McGhee", "Conor Beverland", "Salil Deshmukh"]
26
+ spec.email = ["support@wavefront.com"]
27
+ spec.description = %q{A simple abstraction for talking to wavefront in ruby}
28
+ spec.summary = %q{A simple abstraction for talking to wavefront in ruby}
29
+ spec.homepage = "https://github.com/wavefrontHQ/ruby-client"
30
+ spec.license = "Apache License 2.0"
31
+
32
+ spec.files = `git ls-files`.split($/)
33
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
34
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.3"
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "rspec"
40
+
41
+ spec.add_dependency "rest-client", "~> 1.6.7"
42
+ spec.add_dependency "slop", "= 3.4.7"
43
+ spec.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
44
+
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wavefront-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Sam Pointer
8
+ - Louis McCormack
9
+ - Joshua McGhee
10
+ - Conor Beverland
11
+ - Salil Deshmukh
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2015-08-07 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: bundler
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.3'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.3'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ - !ruby/object:Gem::Dependency
60
+ name: rest-client
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.7
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ version: 1.6.7
73
+ - !ruby/object:Gem::Dependency
74
+ name: slop
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '='
78
+ - !ruby/object:Gem::Version
79
+ version: 3.4.7
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '='
85
+ - !ruby/object:Gem::Version
86
+ version: 3.4.7
87
+ description: A simple abstraction for talking to wavefront in ruby
88
+ email:
89
+ - support@wavefront.com
90
+ executables:
91
+ - wavefront-client
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - .gitignore
96
+ - .ruby-version
97
+ - .travis.yml
98
+ - Gemfile
99
+ - LICENSE
100
+ - NOTICE
101
+ - README.md
102
+ - Rakefile
103
+ - bin/wavefront-client
104
+ - lib/wavefront/alerting.rb
105
+ - lib/wavefront/client.rb
106
+ - lib/wavefront/client/constants.rb
107
+ - lib/wavefront/client/version.rb
108
+ - lib/wavefront/events.rb
109
+ - lib/wavefront/exception.rb
110
+ - lib/wavefront/metadata.rb
111
+ - lib/wavefront/response.rb
112
+ - lib/wavefront/writer.rb
113
+ - spec/example_response.json
114
+ - spec/spec_helper.rb
115
+ - spec/wavefront/client_spec.rb
116
+ - spec/wavefront/metadata_spec.rb
117
+ - spec/wavefront/response_spec.rb
118
+ - spec/wavefront/writer_spec.rb
119
+ - wavefront-client.gemspec
120
+ homepage: https://github.com/wavefrontHQ/ruby-client
121
+ licenses:
122
+ - Apache License 2.0
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: 1.9.3
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A simple abstraction for talking to wavefront in ruby
144
+ test_files:
145
+ - spec/example_response.json
146
+ - spec/spec_helper.rb
147
+ - spec/wavefront/client_spec.rb
148
+ - spec/wavefront/metadata_spec.rb
149
+ - spec/wavefront/response_spec.rb
150
+ - spec/wavefront/writer_spec.rb