wavefront-client 0.5.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWMxMGEzMDUzMzU2NDg2MGEwNGM0ZWMzM2I4MGFkOTg1MmQ0NTA5OQ==
4
+ ZWYzOTdiOTVhYzhlMDhlNzYwMGQzZDMwZGU5ZWM5NGY1NGE4ODgxMQ==
5
5
  data.tar.gz: !binary |-
6
- ZjI1YzE1YjVmMDZlMjBkMmUzZTdhMmQxNjlhNTY2MDFlN2YwZTVlYQ==
6
+ MDBhYzIwNDM5YmZmZjkzNTU2YTc1NzVkNWM1NWEzMjJhMDdlYTgxZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmE3ODcyMzUxMDE1YjkzN2U1Y2QwZDRkZTdmODg4NTY3NzIyYTAxZDJjMzI4
10
- Mjg3NDE5Njc0NDkzMjE1ZmQxMTgwY2I3NzIxMmFkN2UwMjhkY2ZjNGQ2ZTlh
11
- NDc1NDkwMzgyNWQ2MmVmODU0Mjc3YzA0MjJmMWYzOTNkMzkzOTc=
9
+ MTJkMDUxMmQyZTcxNTk4MTkyNzQyMDQ0Njk0MmFmNmQxMmYwYzQ4NGU0ODVm
10
+ NDMxNDZjNjNhNjAwNjk5YjMzNTMxNWE4NWY5ODI5ZjczYWNhMDgxMGU1MWZm
11
+ NjJkMWNiOWM3YjM0ZWRhMmMwYjViNmQzZDJiZDQzMzgzNTIwOTU=
12
12
  data.tar.gz: !binary |-
13
- OTA1ZDg2MDVlYTEzZmEwMjUxMGRjOGMwYjM0MDFmODg5MzE5YzM0OTk3ZDg4
14
- MjQzMTMwOGE4NWRmYzhkYWM4OGFlMmUxYjkzYjYwMmFmM2MyZDJjNWJiODBk
15
- NTk0NTFmYjZlMTcxNzU4NDQ0YTI3ZGMxNzQ5Njg1NGRjNzQ3MGU=
13
+ YTE4OTg4YTAwYWI3N2MzZWYwYzFhMmZhNjE3ZjFiOGRhZjkzYzc5MTBlYWY0
14
+ Njc4Y2Q1NzY0MDI4OWI1OWY2MGJhZGM2ZDAyZWYwYTAzNDgyNjU4YTMzNWU0
15
+ ZWE1MDAyYjcyNGZkZTVmYjc4NmEwZGZjNjFmZjY2NmE2ZDI3YmE=
data/README.md CHANGED
@@ -20,7 +20,7 @@ writer = Wavefront::Writer.new({:agent_host => 'agent.local.com', :host_name =>
20
20
  # value of the metric at current timestamp is: 5
21
21
  writer.write(5)
22
22
  # Let's write a different metric overwriting the default options from the constructor
23
- writer.write(6, 'namespace.my.other.metric', 'server2', {})
23
+ writer.write(6, 'namespace.my.other.metric', {host_name: 'server2'})
24
24
  ```
25
25
 
26
26
  * The initializer takes a hash of options, wherein one can set
@@ -32,9 +32,17 @@ writer.write(6, 'namespace.my.other.metric', 'server2', {})
32
32
  * The write method parameters are:
33
33
  * `metric_value` - A number, the value of the metric reporting at the current timestamp
34
34
  * `metric_name` - A `String`, this must be present, either within the write method call or set on the Writer class
35
- * `host_name` - A `String`, which will appear as the host for the sent metric in Wavefront.
36
- * `point_tags` - A `Map` of key, value pairs of strings which will be sent to Wavefront. Not required. Note that if you specify these as part of the write method call they replace any set at the class level. The two maps are _not_ merged.
37
- * `timestamp` - The Epoch Seconds of the reported point. Default: `Time.now`
35
+ * A hash of options:
36
+ * `host_name` - A `String`, which will appear as the host for the sent
37
+ metric in Wavefront. Defaults to the `host_name` used to initialize
38
+ the class.
39
+ * `point_tags` - A `Map` of key, value pairs of strings which will be
40
+ sent to Wavefront. Not required. Note that if you specify these as
41
+ part of the write method call they replace any set at the class level.
42
+ The two maps are _not_ merged. Defaults to the `point_tags` used to
43
+ initialize the class
44
+ * `timestamp` - The Epoch Seconds (`Fixnum`), or a Ruby `Time` object, of
45
+ the reported point Default: `Time.now`
38
46
 
39
47
  ### Host Tags
40
48
 
@@ -52,13 +60,13 @@ meta.add_tags(["host.server1.server.com","host.server2.server.com"],["tag1","tag
52
60
  meta.remove_tags(["server1.server.com","server2.server.com"],["tag1","tag2"]) # Remove an arbitrary number of tags from an arbitrary number of hosts
53
61
  ```
54
62
 
55
- * The initializer takes up to 3 parameters:
63
+ * The initializer takes up to 3 parameters:
56
64
  * `token` - A valid Wavefront API Token. This is required.
57
65
  * `host` - A `String` representing the Wavefront endpoint to connect to. Default: `metrics.wavefront.com`.
58
66
  * `debug` `true|false` - When set to `true` output `RestClient` debugging to `stdout`. Default: `false`.
59
67
 
60
68
  ### Query Client
61
-
69
+
62
70
  The `Wavefront::Client` class can be used to send queries to Wavefront and get a response
63
71
 
64
72
  Example usage:
@@ -72,7 +80,7 @@ response = wave.query('<TS_EXPRESSION>') # <TS_EXPRESSION> : Placeholder for a
72
80
  response = wave.query('<TS_EXPRESSION>', 'm', {:start_time => Time.now - 86400, :end_time => Time.now}) # <TS_EXPRESSION> : Placeholder for a valid Wavefront ts() query
73
81
  ```
74
82
 
75
- * Like the Metadata class, the initializer takes up to 3 parameters:
83
+ * Like the Metadata class, the initializer takes up to 3 parameters:
76
84
  * `token` - A valid Wavefront API Token. This is required.
77
85
  * `host` - A `String` representing the Wavefront endpoint to connect to. Default: `metrics.wavefront.com`.
78
86
  * `debug` `true|false` - When set to `true` output `RestClient` debugging to `stdout`. Default: `false`.
@@ -84,6 +92,7 @@ response = wave.query('<TS_EXPRESSION>', 'm', {:start_time => Time.now - 86400,
84
92
  * `:start_time` - An object of class `Time` that specifies the query start time. Default: `Time.now - 600`.
85
93
  * `:end_time` - And object of class `Time` that specifies the query end time. Default: `Time.now`.
86
94
  * `:response_format` `[ :raw, :ruby, :graphite, :highcharts ]` - See the section "Response Classes" below. Default: `:raw`.
95
+ * `:prefix_length` - Used when performing schema manipulations. See the Graphite response format below. Default `1`.
87
96
 
88
97
 
89
98
  ### Response Classes
@@ -105,7 +114,7 @@ response.class # Wavefront::Response::Raw
105
114
  response = wave.query('<TS_EXPRESSION>', 'm', {:response_format => :ruby}) # <TS_EXPRESSION> : Placeholder for a valid Wavefront ts() query
106
115
  response.class # Wavefront::Response::Ruby
107
116
  response.instance_variables # [:@response, :@query, :@name, :@timeseries, :@stats]
108
- response.query
117
+ response.query
109
118
  ```
110
119
 
111
120
  * `:response_format => :graphite`
@@ -117,6 +126,17 @@ response = wave.query('<TS_EXPRESSION>', 'm', {:response_format => :graphite}) #
117
126
  response.graphite[0]['datapoints'].first # [99.8, 1403702640]
118
127
  ```
119
128
 
129
+ **Note:** The `target` schema String is constructed from the `label` and the `host` portions of the raw Wavefront response in order to be idiomatically Graphite. In order to determine how to do this properly one must split the `label` into a prefix and a postfix, inserting the `host` between then.
130
+
131
+ For example, `label: "web.prod.base.host.cpu-0.percent-idle"` and `host: i-12345678`, by default, would yield: `web.i-12345678.prod.base.host.cpu-0.percent-idle` as the Graphite target.
132
+
133
+ Depending on the vagaries of your particular configuration you may wish to specify more than the default 1 field as a prefix. This can be achieved passing the `:prefix_length` key as an option with an appropriate `Fixnum`. For example:
134
+
135
+ ```
136
+ response = wave.query('<TS_EXPRESSION>', 'm', {:response_format => :graphite, :prefix_length => 2})
137
+ response.graphite[0]['target'] # web.prod.i-12345678.base.host.cpu-0.percent-idle
138
+ ```
139
+
120
140
  * `:response_format => :highcharts`
121
141
 
122
142
  A ruby object that returns highcharts-format data via the `response` method:
@@ -155,4 +175,15 @@ rake install
155
175
  5. Create new Pull Request
156
176
 
157
177
 
178
+ ## Credits
179
+
180
+ Many thanks to SpaceApe games for initially contributing this Ruby client. Contributors include:
181
+
182
+ Sam Pointer
183
+ Louis McCormack
184
+ Joshua McGhee
185
+ Robert Fisher
186
+ Salil Deshmukh
187
+ Conor Beverland
188
+
158
189
  [1]: http://wavefront.com
data/bin/wavefront-client CHANGED
@@ -15,6 +15,8 @@
15
15
 
16
16
  require 'wavefront/client'
17
17
  require 'slop'
18
+ require 'pp'
19
+ require 'json'
18
20
 
19
21
  @opts = Slop.parse(strict: true) do
20
22
  banner 'Usage: wavefront-client QUERY (OPTIONS)'
@@ -24,6 +26,8 @@ require 'slop'
24
26
  on 's', 'start=', 'Time in UNIX epoch seconds to begin the query from'
25
27
  on 't', 'token=', 'Wavefront authentication token'
26
28
  on 'e', 'end=', 'Time in UNIX epoch seconds to query to'
29
+ on 'f', 'format=', "Output format (#{Wavefront::Client::FORMATS.join(', ')})", default: Wavefront::Client::DEFAULT_FORMAT.to_s
30
+ on 'p', 'prefixlength=', 'The number of path elements to treat as a prefix when doing schema manipulations', default: 1
27
31
  on 'h', 'help', 'Display this message'
28
32
  end
29
33
 
@@ -44,14 +48,29 @@ else
44
48
  exit 1
45
49
  end
46
50
 
51
+ unless Wavefront::Client::FORMATS.include?(@opts[:format].to_sym)
52
+ puts "The output format must be on of #{Wavefront::Client::FORMATS.join(', ')}"
53
+ exit 1
54
+ end
55
+
47
56
  options = Hash.new
57
+ options[:response_format] = @opts[:format].to_sym
58
+ options[:prefix_length] = @opts[:prefixlength].to_i
59
+
48
60
  if @opts[:start]
49
- options[:start_time] = @opts[:start]
61
+ options[:start_time] = Time.at(@opts[:start].to_i)
50
62
  end
51
63
 
52
64
  if @opts[:end]
53
- options[:end_time] = @opts[:end]
65
+ options[:end_time] = Time.at(@opts[:end].to_i)
54
66
  end
55
67
 
56
68
  wave = Wavefront::Client.new(@opts[:token])
57
- puts wave.query(query, granularity, options)
69
+ case options[:response_format]
70
+ when :raw
71
+ puts wave.query(query, granularity, options)
72
+ when :graphite
73
+ puts wave.query(query, granularity, options).graphite.to_json
74
+ else
75
+ pp wave.query(query, granularity, options)
76
+ end
@@ -16,6 +16,6 @@ See the License for the specific language governing permissions and
16
16
 
17
17
  module Wavefront
18
18
  class Client
19
- VERSION = "0.5.3"
19
+ VERSION = "1.0.1"
20
20
  end
21
21
  end
@@ -43,10 +43,12 @@ module Wavefront
43
43
  options[:end_time] ||= Time.now
44
44
  options[:start_time] ||= options[:end_time] - DEFAULT_PERIOD_SECONDS
45
45
  options[:response_format] ||= DEFAULT_FORMAT
46
+ options[:prefix_length] ||= 1
46
47
 
47
48
  [ options[:start_time], options[:end_time] ].each { |o| raise Wavefront::Exception::InvalidTimeFormat unless o.is_a?(Time) }
48
49
  raise Wavefront::Exception::InvalidGranularity unless GRANULARITIES.include?(granularity)
49
50
  raise Wavefront::Exception::InvalidResponseFormat unless FORMATS.include?(options[:response_format])
51
+ raise InvalidPrefixLength unless options[:prefix_length].is_a?(Fixnum)
50
52
 
51
53
  args = {:params =>
52
54
  {:q => query, :g => granularity, :n => 'Unknown',
@@ -54,7 +56,7 @@ module Wavefront
54
56
  response = RestClient.get @base_uri.to_s, args
55
57
 
56
58
  klass = Object.const_get('Wavefront').const_get('Response').const_get(options[:response_format].to_s.capitalize)
57
- return klass.new(response)
59
+ return klass.new(response, options)
58
60
 
59
61
  end
60
62
 
@@ -23,5 +23,6 @@ module Wavefront
23
23
  class InvaldResponseFormat < ::Exception; end
24
24
  class EmptyMetricName < ::Exception; end
25
25
  class NotImplemented < ::Exception; end
26
+ class InvalidPrefixLength < ::Exception; end
26
27
  end
27
28
  end
@@ -0,0 +1,29 @@
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
+ module Wavefront
18
+ module Mixins
19
+ def interpolate_schema(label, host, prefix_length)
20
+ label_parts = label.split('.')
21
+ interpolated = Array.new
22
+ interpolated << label_parts.shift(prefix_length)
23
+ interpolated << host
24
+ interpolated << label_parts
25
+ interpolated.flatten!
26
+ return interpolated.join('.')
27
+ end
28
+ end
29
+ end
@@ -16,15 +16,17 @@ See the License for the specific language governing permissions and
16
16
 
17
17
  require 'wavefront/client/version'
18
18
  require 'wavefront/exception'
19
+ require 'wavefront/mixins'
19
20
  require 'json'
20
21
 
21
22
  module Wavefront
22
23
  class Response
23
24
  class Raw
24
- attr_reader :response
25
+ attr_reader :response, :options
25
26
 
26
- def initialize(response)
27
+ def initialize(response, options={})
27
28
  @response = response
29
+ @options = options
28
30
  end
29
31
 
30
32
  def to_s
@@ -35,10 +37,11 @@ module Wavefront
35
37
 
36
38
  class Ruby
37
39
  include JSON
38
- attr_reader :response
40
+ attr_reader :response, :options
39
41
 
40
- def initialize(response)
42
+ def initialize(response, options={})
41
43
  @response = response
44
+ @options = options
42
45
 
43
46
  JSON.parse(response).each_pair do |k,v|
44
47
  self.instance_variable_set("@#{k}", v) # Dynamically populate instance vars
@@ -49,43 +52,61 @@ module Wavefront
49
52
  end
50
53
 
51
54
  class Graphite < Wavefront::Response::Ruby
52
- attr_reader :response, :graphite
55
+ include Wavefront::Mixins
56
+ attr_reader :response, :graphite, :options
53
57
 
54
- def initialize(response)
58
+ def initialize(response, options={})
55
59
  super
60
+ options[:prefix_length] ||= 1 # See also Wavefront::Client
56
61
 
57
- datapoints = Array.new
62
+ @graphite = Array.new
58
63
  self.timeseries.each do |ts|
64
+
65
+ output_timeseries = Hash.new
66
+ output_timeseries['target'] = interpolate_schema(ts['label'], ts['host'], options[:prefix_length])
67
+
68
+ datapoints = Array.new
59
69
  ts['data'].each do |d|
60
70
  datapoints << [d[1], d[0]]
61
71
  end
62
- end
63
72
 
64
- @graphite = [{ 'target' => self.query, 'datapoints' => datapoints }]
73
+ output_timeseries['datapoints'] = datapoints
74
+ @graphite << output_timeseries
75
+
76
+ end
65
77
  end
66
78
 
67
79
  end
68
80
 
69
81
  class Highcharts < Wavefront::Response::Ruby
70
82
  include JSON
71
- attr_reader :response, :highcharts
83
+ attr_reader :response, :highcharts, :options
72
84
 
73
- def initialize(response)
85
+ def initialize(response, options={})
74
86
  super
75
87
 
76
88
  @response = JSON.parse(response)
77
-
78
- @highcharts = []
79
- self.timeseries.each do |series|
80
- # Highcharts expects the time in milliseconds since the epoch
81
- # And for some reason the first value tends to be BS
82
-
83
- @highcharts << { 'name' => series['label'], 'data' => series['data'][1..-1].map!{|x,y| [ x * 1000, y ]} }
84
- end
89
+ @highcharts = []
90
+ self.timeseries.each do |series|
91
+ # Highcharts expects the time in milliseconds since the epoch
92
+ # And for some reason the first value tends to be BS
93
+ # We also have to deal with missing (null/nil) data points.
94
+ amended_data = Array.new
95
+ next unless series['data'].size > 0
96
+ series['data'][1..-1].each do |time_value_pair|
97
+ if time_value_pair[0]
98
+ time_value_pair[0] = time_value_pair[0] * 1000
99
+ else
100
+ time_value_pair[0] = "null"
101
+ end
102
+ amended_data << time_value_pair
103
+ end
104
+ @highcharts << { 'name' => series['label'], 'data' => amended_data }
105
+ end
85
106
  end
86
107
 
87
108
  def to_json
88
- @highcharts.to_json
109
+ @highcharts.to_json
89
110
  end
90
111
  end
91
112
 
@@ -1,4 +1,4 @@
1
- =begin
1
+ =begin
2
2
  Copyright 2015 Wavefront Inc.
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -31,23 +31,37 @@ module Wavefront
31
31
  options[:host_name] ||= DEFAULT_HOSTNAME
32
32
  options[:metric_name] ||= ''
33
33
  options[:point_tags] ||= {}
34
-
34
+
35
35
  @host_name = options[:host_name]
36
36
  @metric_name = options[:metric_name]
37
37
  @point_tags = options[:point_tags]
38
-
38
+
39
39
  @socket = get_socket(options[:agent_host], options[:agent_port])
40
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}"
41
+
42
+ def write(metric_value, metric_name = @metric_name, options = {})
43
+ options[:host_name] ||= @host_name
44
+ options[:point_tags] ||= @point_tags
45
+ options[:timestamp] ||= Time.now
46
+
47
+ if metric_name.empty?
48
+ raise Wavefront::Exception::EmptyMetricName
49
+ end
50
+
51
+ if options[:point_tags].empty?
52
+ append = "host=#{options[:host_name]}"
53
+ else
54
+ tags = options[:point_tags].map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
55
+ append = "host=#{options[:host_name]} #{tags}"
56
+ end
57
+
58
+ @socket.puts [metric_name, metric_value, options[:timestamp].to_i,
59
+ append].join(' ')
47
60
  end
48
61
 
49
62
  private
50
- def get_socket(host,port)
63
+
64
+ def get_socket(host, port)
51
65
  TCPSocket.new(host, port)
52
66
  end
53
67
 
@@ -1 +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}}
1
+ {"query":"100 - ts(ops.prod.base.host.cpu-*.percent-idle)","name":"Unknown","timeseries":[{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-0ae6d2a7","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-0de6d2a0","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-32388c9f","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-406d6eed","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-4fe968e2","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-5b3f8bf6","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-ba3f8b17","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-bce7d311","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-bd971010","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"ip-172-31-31-195","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"unknown","data":[]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-24292a89","data":[[1439371440,0.4000000000000033],[1439371500,0.5826666666666659],[1439371560,0.3335000000000008],[1439371620,0.5326666666666663],[1439371680,0.3000000000000019],[1439371740,0.44983333333333303],[1439371800,0.4170000000000016],[1439371860,0.3999999999999986],[1439371920,0.46683333333333366],[1439371980,0.4163333333333341],[1439372040,0.48316666666666447],[1439372100,0.43299999999999983],[1439372160,0.4165000000000016],[1439372220,0.3498333333333316],[1439372280,0.6000000000000014],[1439372340,0.4168333333333365],[1439372400,87.93666666666667],[1439372460,99.65514166666667],[1439372520,11.878333333333334],[1439372580,0.449333333333333],[1439372640,0.3499999999999967],[1439372700,0.6333333333333305],[1439372760,0.5168333333333308],[1439372820,0.38333333333333286],[1439372880,0.3498333333333316],[1439372940,0.4824999999999993],[1439373000,0.416666666666669],[1439373060,0.4660000000000011],[1439373120,0.4001666666666684],[1439373180,0.4164999999999992],[1439373240,0.36666666666666714]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-249e1f89","data":[[1439371440,0.38283333333333286],[1439371500,0.34983333333333394],[1439371560,0.34966666666666885],[1439371620,0.36616666666666714],[1439371680,0.38333333333333286],[1439371740,0.3333333333333333],[1439371800,0.5495000000000019],[1439371860,0.25],[1439371920,0.2666666666666681],[1439371980,0.36616666666666714],[1439372040,0.28350000000000125],[1439372100,0.4829999999999994],[1439372160,0.43283333333333474],[1439372220,0.4659999999999987],[1439372280,0.36649999999999966],[1439372340,0.333333333333331],[1439372400,84.88483333333333],[1439372460,99.59467666666667],[1439372520,2.799333333333337],[1439372580,0.28316666666666873],[1439372640,0.2500000000000024],[1439372700,0.3498333333333363],[1439372760,0.4164999999999992],[1439372820,0.3495000000000014],[1439372880,0.44933333333333064],[1439372940,0.28333333333333616],[1439373000,0.36650000000000205],[1439373060,0.24983333333333255],[1439373120,0.3163333333333351],[1439373180,0.38350000000000267],[1439373240,0.36666666666666475]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-27292a8a","data":[[1439371440,0.3000000000000019],[1439371500,0.28333333333333616],[1439371560,0.2666666666666681],[1439371620,0.36633333333333223],[1439371680,0.3330000000000008],[1439371740,0.31650000000000017],[1439371800,0.5498333333333321],[1439371860,0.34966666666666885],[1439371920,0.36650000000000205],[1439371980,0.5998333333333316],[1439372040,0.3335000000000008],[1439372100,0.34983333333333394],[1439372160,0.2833333333333338],[1439372220,0.3166666666666676],[1439372280,0.29999999999999954],[1439372340,0.36649999999999966],[1439372400,90.50422833333333],[1439372460,96.05833333333334],[1439372520,0.9016666666666684],[1439372580,0.28316666666666396],[1439372640,0.3990000000000009],[1439372700,0.44966666666666794],[1439372760,0.44966666666666794],[1439372820,0.4165000000000016],[1439372880,0.3833333333333305],[1439372940,0.3330000000000008],[1439373000,0.5326666666666663],[1439373060,0.4331666666666673],[1439373120,0.416166666666669],[1439373180,0.4993333333333349],[1439373240,0.31650000000000017]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-4bb938e6","data":[[1439371440,0.28316666666666634],[1439371500,0.4159999999999992],[1439371560,0.2833333333333338],[1439371620,0.28333333333333144],[1439371680,0.36600000000000205],[1439371740,0.29983333333333445],[1439371800,0.3333333333333333],[1439371860,0.36633333333333457],[1439371920,0.4159999999999992],[1439371980,0.28316666666666873],[1439372040,0.3333333333333357],[1439372100,0.3500000000000038],[1439372160,0.2666666666666681],[1439372220,0.2666666666666657],[1439372280,0.4001666666666684],[1439372340,0.5328333333333338],[1439372400,93.83716666666666],[1439372460,99.36666666666667],[1439372520,0.8335000000000008],[1439372580,0.4330000000000022],[1439372640,0.382666666666663],[1439372700,0.3000000000000019],[1439372760,0.44966666666666794],[1439372820,0.3830000000000003],[1439372880,0.3668333333333346],[1439372940,0.3000000000000019],[1439373000,0.4161666666666667],[1439373060,0.25],[1439373120,0.3333333333333333],[1439373180,0.31700000000000017],[1439373240,0.3331666666666659]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-0bab2aa6","data":[[1439371440,0.28333333333333616],[1439371500,0.3000000000000019],[1439371560,0.23333333333333428],[1439371620,0.23333333333333192],[1439371680,0.3501666666666665],[1439371740,0.36650000000000443],[1439371800,0.3334999999999984],[1439371860,0.29983333333333445],[1439371920,0.36650000000000205],[1439371980,0.2833333333333338],[1439372040,0.43283333333333707],[1439372100,0.3168333333333327],[1439372160,0.2498333333333349],[1439372220,0.3334999999999984],[1439372280,0.38333333333333525],[1439372340,0.3500000000000038],[1439372400,94.44966666666667],[1439372460,94.86545833333334],[1439372520,0.950833333333333],[1439372580,0.29983333333333445],[1439372640,0.2833333333333338],[1439372700,0.3330000000000008],[1439372760,0.3498333333333363],[1439372820,0.29983333333333206],[1439372880,0.28316666666666634],[1439372940,0.3333333333333333],[1439373000,0.3828333333333328],[1439373060,0.29983333333333445],[1439373120,0.2833333333333338],[1439373180,0.3161666666666652],[1439373240,0.36633333333333223]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-592f2cf4","data":[[1439371440,0.28333333333333616],[1439371500,0.36616666666666947],[1439371560,0.31666666666667],[1439371620,0.23333333333333428],[1439371680,0.4336666666666673],[1439371740,0.3496666666666665],[1439371800,0.4333333333333371],[1439371860,0.2665000000000006],[1439371920,0.3164999999999978],[1439371980,0.36650000000000205],[1439372040,0.3500000000000014],[1439372100,0.38333333333333286],[1439372160,0.350333333333334],[1439372220,0.44966666666667027],[1439372280,0.3333333333333333],[1439372340,0.3328333333333333],[1439372400,90.5225],[1439372460,99.21745333333334],[1439372520,0.617000000000002],[1439372580,0.2666666666666681],[1439372640,0.2998333333333368],[1439372700,0.36649999999999966],[1439372760,0.38333333333333286],[1439372820,0.2666666666666657],[1439372880,0.29983333333333445],[1439372940,0.43316666666666964],[1439373000,0.44933333333333536],[1439373060,0.3164999999999978],[1439373120,0.3830000000000003],[1439373180,0.43283333333333474],[1439373240,0.3500000000000014]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-a99e1f04","data":[[1439371440,0.34983333333333394],[1439371500,0.3666666666666695],[1439371560,0.23333333333333192],[1439371620,0.38283333333333286],[1439371680,0.23333333333333428],[1439371740,0.2166666666666662],[1439371800,0.29999999999999954],[1439371860,0.2500000000000024],[1439371920,0.3660000000000044],[1439371980,0.29983333333333206],[1439372040,0.3500000000000014],[1439372100,0.44983333333333536],[1439372160,0.28316666666666873],[1439372220,0.3165000000000025],[1439372280,0.44949999999999807],[1439372340,0.21666666666666856],[1439372400,90.03998333333334],[1439372460,93.50291666666666],[1439372520,0.5836666666666683],[1439372580,0.36616666666666714],[1439372640,0.3329999999999984],[1439372700,0.2666666666666681],[1439372760,0.3328333333333357],[1439372820,0.3330000000000008],[1439372880,0.30016666666666464],[1439372940,0.28316666666666873],[1439373000,0.29999999999999954],[1439373060,0.2996666666666646],[1439373120,0.3830000000000003],[1439373180,0.3330000000000008],[1439373240,0.399666666666666]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-743635d9","data":[[1439371440,0.3831666666666654],[1439371500,0.3500000000000014],[1439371560,0.29983333333333206],[1439371620,0.43333333333333],[1439371680,0.38333333333333286],[1439371740,0.34983333333333394],[1439371800,0.4494999999999981],[1439371860,0.36616666666666475],[1439371920,0.46633333333333366],[1439371980,0.3000000000000019],[1439372040,0.3335000000000008],[1439372100,0.3000000000000019],[1439372160,0.31650000000000017],[1439372220,0.333333333333331],[1439372280,0.3996666666666684],[1439372340,0.3666666666666695],[1439372400,91.44183333333334],[1439372460,99.75181666666667],[1439372520,2.2713333333333354],[1439372580,0.24983333333333016],[1439372640,0.29999999999999954],[1439372700,0.40000000000000097],[1439372760,0.30016666666666464],[1439372820,0.43283333333333474],[1439372880,0.4829999999999994],[1439372940,0.2500000000000024],[1439373000,0.4833333333333319],[1439373060,0.2666666666666657],[1439373120,0.2666666666666681],[1439373180,0.36649999999999966],[1439373240,0.4670000000000011]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-bbc7c416","data":[[1439371440,0.4831666666666668],[1439371500,0.3331666666666706],[1439371560,0.28350000000000125],[1439371620,0.28300000000000125],[1439371680,0.30016666666666697],[1439371740,0.3331666666666682],[1439371800,0.3831666666666654],[1439371860,0.2500000000000024],[1439371920,0.34933333333333155],[1439371980,0.3333333333333357],[1439372040,0.3331666666666659],[1439372100,0.3333333333333333],[1439372160,0.44949999999999807],[1439372220,0.36650000000000205],[1439372280,0.3168333333333351],[1439372340,0.4333333333333371],[1439372400,86.07533333333333],[1439372460,99.82667666666667],[1439372520,2.8129999999999997],[1439372580,0.38333333333333286],[1439372640,0.3999999999999986],[1439372700,0.4163333333333365],[1439372760,0.4165000000000016],[1439372820,0.40016666666666606],[1439372880,0.41616666666666663],[1439372940,0.3331666666666635],[1439373000,0.3998333333333311],[1439373060,0.36650000000000205],[1439373120,0.2666666666666681],[1439373180,0.3331666666666659],[1439373240,0.40000000000000097]]},{"label":"ops.prod.base.host.cpu-0.percent-idle","host":"i-e0a1204d","data":[[1439371440,0.5160000000000006],[1439371500,0.44983333333333064],[1439371560,0.41616666666666663],[1439371620,0.4826666666666668],[1439371680,0.2833333333333338],[1439371740,0.3500000000000014],[1439371800,0.4833333333333343],[1439371860,0.3999999999999986],[1439371920,0.2666666666666681],[1439371980,0.3166666666666676],[1439372040,0.28299999999999886],[1439372100,0.2666666666666681],[1439372160,0.5],[1439372220,0.3830000000000003],[1439372280,0.36633333333333223],[1439372340,0.43266666666666725],[1439372400,95.13166666666666],[1439372460,94.40085],[1439372520,0.9680000000000035],[1439372580,0.449333333333333],[1439372640,0.3331666666666682],[1439372700,0.4826666666666668],[1439372760,0.3168333333333351],[1439372820,0.44966666666666555],[1439372880,0.31650000000000017],[1439372940,0.36633333333333223],[1439373000,0.3669999999999997],[1439373060,0.4663333333333336],[1439373120,0.4826666666666668],[1439373180,0.46683333333333127],[1439373240,0.3999999999999986]]}],"granularity":60,"stats":{"keys":1269,"points":15452,"summaries":14338,"summarized_points":0,"summarized_summaries":0,"buffer_keys":1259,"compacted_keys":155,"compacted_points":14338,"latency":4,"queries":20,"s3_keys":0,"cpu_ns":15186747,"skipped_compacted_keys":144}}
@@ -0,0 +1,29 @@
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 'wavefront/mixins'
19
+
20
+ HOST = 'i-12345678'
21
+
22
+ describe Wavefront::Mixins do
23
+ include Wavefront::Mixins
24
+ it 'provides a method to interpolate the schema' do
25
+ wavefront_schema = "a.b.c.d.e"
26
+ expect(interpolate_schema(wavefront_schema, HOST, 1)).to eq("a.#{HOST}.b.c.d.e")
27
+ expect(interpolate_schema(wavefront_schema, HOST, 2)).to eq("a.b.#{HOST}.c.d.e")
28
+ end
29
+ end
@@ -16,6 +16,7 @@ See the License for the specific language governing permissions and
16
16
 
17
17
  require 'spec_helper'
18
18
  require 'pathname'
19
+ require 'json'
19
20
 
20
21
  RESPONSE = 'test'
21
22
 
@@ -52,14 +53,18 @@ describe Wavefront::Response::Ruby do
52
53
  end
53
54
 
54
55
  describe Wavefront::Response::Graphite do
56
+ include Wavefront::Mixins
57
+ include JSON
55
58
  it 'returns something that resembles some graphite output' do
56
59
  example_response = File.read(Pathname.new(__FILE__).parent.parent.join('example_response.json'))
57
60
  response = Wavefront::Response::Graphite.new(example_response)
61
+ response_hash = JSON.parse(example_response)
62
+ schema = interpolate_schema(response_hash['timeseries'][0]['label'], response_hash['timeseries'][0]['host'], 1)
58
63
 
59
- expect(response.graphite.size).to eq(1)
64
+ expect(response.graphite.size).to eq(21)
60
65
  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)
66
+ expect(response.graphite[0]['target']).to eq(schema)
67
+ expect(response.graphite[15]['datapoints'].size).to eq(31)
63
68
  end
64
69
  end
65
70
 
@@ -68,7 +73,7 @@ describe Wavefront::Response::Highcharts do
68
73
  example_response = File.read(Pathname.new(__FILE__).parent.parent.join('example_response.json'))
69
74
  response = Wavefront::Response::Highcharts.new(example_response)
70
75
 
71
- expect(JSON.parse(response.to_json).size).to eq(response.timeseries.size)
76
+ expect(response.highcharts[0]['data'].size).to eq(30)
72
77
  JSON.parse(response.to_json).each { |m| expect(m.keys.size).to eq(2) }
73
78
  end
74
79
  end
@@ -1,4 +1,4 @@
1
- =begin
1
+ =begin
2
2
  Copyright 2015 Wavefront Inc.
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -28,11 +28,11 @@ describe Wavefront::Writer do
28
28
 
29
29
  it 'has some defaults' do
30
30
  expect(Wavefront::Writer::DEFAULT_HOST).to_not be_nil
31
- expect(Wavefront::Writer::DEFAULT_HOST).to be_a_kind_of String
31
+ expect(Wavefront::Writer::DEFAULT_HOST).to be_a_kind_of String
32
32
  expect(Wavefront::Writer::DEFAULT_PORT).to_not be_nil
33
- expect(Wavefront::Writer::DEFAULT_PORT).to be_a_kind_of Fixnum
33
+ expect(Wavefront::Writer::DEFAULT_PORT).to be_a_kind_of Fixnum
34
34
  expect(Wavefront::Writer::DEFAULT_HOSTNAME).to_not be_nil
35
- expect(Wavefront::Writer::DEFAULT_HOSTNAME).to be_a_kind_of String
35
+ expect(Wavefront::Writer::DEFAULT_HOSTNAME).to be_a_kind_of String
36
36
  end
37
37
 
38
38
 
@@ -62,9 +62,9 @@ describe Wavefront::Writer do
62
62
  allow(Time).to receive(:now).and_return(123456789)
63
63
  expect(socket).to receive(:puts).with("metric 50 123456789 host=somehost")
64
64
  writer = Wavefront::Writer.new
65
- writer.write(50, "metric", host, {}, 123456789)
65
+ writer.write(50, "metric", {host_name: host, timestamp: 123456789})
66
66
  end
67
-
67
+
68
68
  it 'should accept a single tag and append it correctly' do
69
69
  host = 'somehost'
70
70
  port = '8566'
@@ -74,7 +74,8 @@ describe Wavefront::Writer do
74
74
  allow(Time).to receive(:now).and_return(123456789)
75
75
  expect(socket).to receive(:puts).with("metric 50 123456789 host=somehost tag_key_one=\"tag_val_one\"")
76
76
  writer = Wavefront::Writer.new
77
- writer.write(50, "metric", host, tags, 123456789)
77
+ writer.write(50, "metric",
78
+ {host_name: host, point_tags: tags, timestamp: 123456789})
78
79
  end
79
80
 
80
81
  it 'should accept multiple tags and append them correctly' do
@@ -86,9 +87,9 @@ describe Wavefront::Writer do
86
87
  allow(Time).to receive(:now).and_return(123456789)
87
88
  expect(socket).to receive(:puts).with("metric 50 123456789 host=somehost tag_key_one=\"tag_val_one\" k2=\"v2\"")
88
89
  writer = Wavefront::Writer.new
89
- writer.write(50, "metric", host, tags, 123456789)
90
+ writer.write(50, "metric",
91
+ {host_name: host, point_tags: tags, timestamp: 123456789})
90
92
 
91
93
  end
92
94
  end
93
-
94
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Pointer
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-08-07 00:00:00.000000000 Z
15
+ date: 2015-08-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -108,12 +108,14 @@ files:
108
108
  - lib/wavefront/events.rb
109
109
  - lib/wavefront/exception.rb
110
110
  - lib/wavefront/metadata.rb
111
+ - lib/wavefront/mixins.rb
111
112
  - lib/wavefront/response.rb
112
113
  - lib/wavefront/writer.rb
113
114
  - spec/example_response.json
114
115
  - spec/spec_helper.rb
115
116
  - spec/wavefront/client_spec.rb
116
117
  - spec/wavefront/metadata_spec.rb
118
+ - spec/wavefront/mixins_spec.rb
117
119
  - spec/wavefront/response_spec.rb
118
120
  - spec/wavefront/writer_spec.rb
119
121
  - wavefront-client.gemspec
@@ -146,5 +148,6 @@ test_files:
146
148
  - spec/spec_helper.rb
147
149
  - spec/wavefront/client_spec.rb
148
150
  - spec/wavefront/metadata_spec.rb
151
+ - spec/wavefront/mixins_spec.rb
149
152
  - spec/wavefront/response_spec.rb
150
153
  - spec/wavefront/writer_spec.rb