ruby-metrics-opentsdb 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-metrics/reporters/opentsdb.rb +77 -0
- metadata +79 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'ruby-metrics'
|
2
|
+
require 'ruby-metrics/logging'
|
3
|
+
require 'opentsdb'
|
4
|
+
|
5
|
+
module Metrics
|
6
|
+
module Reporters
|
7
|
+
class OpenTSDBReporter
|
8
|
+
|
9
|
+
include Logging
|
10
|
+
|
11
|
+
attr_reader :hostname
|
12
|
+
attr_reader :port
|
13
|
+
attr_reader :client
|
14
|
+
attr_reader :tags
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@hostname = options[:hostname]
|
18
|
+
@port = options[:port]
|
19
|
+
@client = OpenTSDB::Client.new({:hostname => @hostname, :port => @port})
|
20
|
+
@tags = options[:tags] || {:units => 'none'}
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_data(name, value, units = nil)
|
24
|
+
tsdb_data = {
|
25
|
+
:metric => name,
|
26
|
+
:timestamp => Time.now.to_i,
|
27
|
+
:value => value,
|
28
|
+
:tags => @tags
|
29
|
+
}
|
30
|
+
|
31
|
+
if units
|
32
|
+
tsdb_data[:tags][:units] = units
|
33
|
+
end
|
34
|
+
|
35
|
+
@client.put(tsdb_data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def report(agent)
|
39
|
+
agent.instruments.clone.each do |name, instrument|
|
40
|
+
case instrument
|
41
|
+
when Metrics::Instruments::Counter
|
42
|
+
value = instrument.to_i
|
43
|
+
send_data name, value
|
44
|
+
when Metrics::Instruments::Gauge
|
45
|
+
if instrument.get.is_a? Hash
|
46
|
+
instrument.get.each do |key, value|
|
47
|
+
send_data "#{name}.#{key}", value
|
48
|
+
end
|
49
|
+
else
|
50
|
+
send_data name, instrument.get, instrument.units
|
51
|
+
end
|
52
|
+
when Metrics::Instruments::Timer
|
53
|
+
rate_units = "#{instrument.units}/sec"
|
54
|
+
time_units = "sec/#{instrument.units}"
|
55
|
+
send_data "#{name}.count", instrument.count, instrument.units
|
56
|
+
[:fifteen_minute_rate, :five_minute_rate, :one_minute_rate].each do |attribute|
|
57
|
+
send_data "#{name}.#{attribute}", instrument.send(attribute), rate_units
|
58
|
+
end
|
59
|
+
|
60
|
+
[:min, :max, :mean].each do |attribute|
|
61
|
+
send_data "#{name}.#{attribute}", instrument.send(attribute), time_units
|
62
|
+
end
|
63
|
+
when Metrics::Instruments::Meter
|
64
|
+
rate_units = "#{instrument.units}/sec"
|
65
|
+
send_data "#{name}.count", instrument.count, instrument.units
|
66
|
+
[:fifteen_minute_rate, :five_minute_rate, :one_minute_rate, :mean_rate].each do |attribute|
|
67
|
+
send_data "#{name}.#{attribute}", instrument.send(attribute), rate_units
|
68
|
+
end
|
69
|
+
else
|
70
|
+
puts 'Unhandled instrument'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-metrics-opentsdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Ewart
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: opentsdb
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby-metrics
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.0
|
46
|
+
description: A reporter that uses OpenTSDB to stash metric data
|
47
|
+
email:
|
48
|
+
- john@johnewart.net
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/ruby-metrics/reporters/opentsdb.rb
|
54
|
+
homepage: https://github.com/johnewart/ruby-metrics-opentsdb
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.23.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: OpenTSDB reporter for ruby-metrics
|
79
|
+
test_files: []
|