rubycut-metriks 0.9.9.5 → 0.9.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,109 @@
1
+ require 'net/https'
2
+ require 'socket'
3
+ require 'io/wait'
4
+
5
+ module Metriks::Reporter
6
+ class Opentsdb
7
+ attr_accessor :prefix, :source
8
+
9
+ def initialize(host, port, options = {})
10
+ @host = host
11
+ @port = port
12
+ @prefix = options[:prefix]
13
+ @source = options[:source]
14
+ @interval = options[:interval] || 60
15
+ @registry = options[:registry] || Metriks::Registry.default
16
+ @on_error = options[:on_error] || proc { |ex| }
17
+
18
+ end
19
+ def open_connection
20
+ @connection = TCPSocket.new(@host, @port)
21
+ end
22
+ def connection
23
+ @connection
24
+ end
25
+ def start
26
+ @thread ||= Thread.new do
27
+ loop do
28
+ sleep @interval
29
+ Thread.new do
30
+ begin
31
+ write
32
+ rescue Exception => ex
33
+ @on_error[ex] rescue nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def stop
41
+ @thread.kill if @thread
42
+ @thread = nil
43
+ end
44
+
45
+ def restart
46
+ stop
47
+ start
48
+ end
49
+
50
+ def write
51
+ open_connection
52
+ @registry.each do |name, metric|
53
+ case metric
54
+ when Metriks::Meter
55
+ send_metric name, metric, [
56
+ :count, :one_minute_rate, :five_minute_rate,
57
+ :fifteen_minute_rate, :mean_rate
58
+ ]
59
+ when Metriks::Counter
60
+ send_metric name, metric, [
61
+ :count
62
+ ]
63
+ when Metriks::Gauge
64
+ send_metric name, metric, [
65
+ :value
66
+ ]
67
+ when Metriks::UtilizationTimer
68
+ send_metric name, metric, [
69
+ :count, :one_minute_rate, :five_minute_rate,
70
+ :fifteen_minute_rate, :mean_rate,
71
+ :min, :max, :mean, :stddev,
72
+ :one_minute_utilization, :five_minute_utilization,
73
+ :fifteen_minute_utilization, :mean_utilization,
74
+ ], [
75
+ :median, :get_95th_percentile
76
+ ]
77
+ when Metriks::Timer
78
+ send_metric name, metric, [
79
+ :count, :one_minute_rate, :five_minute_rate,
80
+ :fifteen_minute_rate, :mean_rate,
81
+ :min, :max, :mean, :stddev
82
+ ], [
83
+ :median, :get_95th_percentile
84
+ ]
85
+ when Metriks::Histogram
86
+ send_metric name, metric, [
87
+ :count, :min, :max, :mean, :stddev
88
+ ], [
89
+ :median, :get_95th_percentile
90
+ ]
91
+ end
92
+ end
93
+ close_connection
94
+
95
+ end
96
+ def close_connection
97
+ if connection.ready?
98
+ raise "Error while pushing data: #{connection.gets}"
99
+ end
100
+ connection.close
101
+ end
102
+ def send_metric(compound_name, metric, keys, snapshot_keys = [])
103
+ name, tags = compound_name.split("#")
104
+ keys.each do |key|
105
+ connection.puts("put #{name}.#{key} #{Time.now.to_i} #{metric.send(key)} #{tags}")
106
+ end
107
+ end
108
+ end
109
+ end
data/metriks.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'rubycut-metriks'
16
- s.version = '0.9.9.5'
16
+ s.version = '0.9.9.6'
17
17
  s.date = '2013-04-28'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
71
71
  lib/metriks/reporter/logger.rb
72
72
  lib/metriks/reporter/proc_title.rb
73
73
  lib/metriks/reporter/riemann.rb
74
+ lib/metriks/reporter/opentsdb.rb
74
75
  lib/metriks/simple_moving_average.rb
75
76
  lib/metriks/snapshot.rb
76
77
  lib/metriks/time_tracker.rb
@@ -92,6 +93,7 @@ Gem::Specification.new do |s|
92
93
  test/thread_error_handling_tests.rb
93
94
  test/timer_test.rb
94
95
  test/utilization_timer_test.rb
96
+ test/opentsdb_metrics_reporter_test.rb
95
97
  ]
96
98
  # = MANIFEST =
97
99
 
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'thread_error_handling_tests'
3
+
4
+ require 'metriks/reporter/opentsdb'
5
+
6
+ class OpentsdbReporterTest < Test::Unit::TestCase
7
+ include ThreadErrorHandlingTests
8
+
9
+ def build_reporter(options={})
10
+ Metriks::Reporter::Opentsdb.new('localhost', 4242, { :registry => @registry }.merge(options))
11
+ end
12
+
13
+ def setup
14
+ @registry = Metriks::Registry.new
15
+ @reporter = build_reporter
16
+ end
17
+
18
+ def teardown
19
+ @reporter.stop
20
+ @registry.stop
21
+ end
22
+
23
+ def test_write
24
+ @registry.meter('meter.testing#tag=test').mark
25
+ @registry.counter('counter.testing#tag=test').increment
26
+ @registry.timer('timer.testing#tag=test').update(1.5)
27
+ @registry.histogram('histogram.testing#tag=test').update(1.5)
28
+ @registry.utilization_timer('utilization_timer.testing#tag=test').update(1.5)
29
+ @registry.gauge('gauge.testing#tag=test') { 123 }
30
+ tcp_socket = mock
31
+ @reporter.stubs(:connection).returns(tcp_socket)
32
+ tcp_socket.expects(:puts).at_least_once
33
+ tcp_socket.expects(:ready?).returns(false)
34
+ tcp_socket.expects(:close)
35
+
36
+ @reporter.connection.expects(:puts).with("put counter.testing.count #{Time.now.to_i} 1 tag=test")
37
+ @reporter.write
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycut-metriks
3
3
  version: !ruby/object:Gem::Version
4
- hash: 41
4
+ hash: 47
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 9
10
- - 5
11
- version: 0.9.9.5
10
+ - 6
11
+ version: 0.9.9.6
12
12
  platform: ruby
13
13
  authors:
14
14
  - Eric Lindvall
@@ -107,6 +107,7 @@ files:
107
107
  - lib/metriks/reporter/logger.rb
108
108
  - lib/metriks/reporter/proc_title.rb
109
109
  - lib/metriks/reporter/riemann.rb
110
+ - lib/metriks/reporter/opentsdb.rb
110
111
  - lib/metriks/simple_moving_average.rb
111
112
  - lib/metriks/snapshot.rb
112
113
  - lib/metriks/time_tracker.rb
@@ -128,6 +129,7 @@ files:
128
129
  - test/thread_error_handling_tests.rb
129
130
  - test/timer_test.rb
130
131
  - test/utilization_timer_test.rb
132
+ - test/opentsdb_metrics_reporter_test.rb
131
133
  homepage: https://github.com/rubycut/metriks
132
134
  licenses: []
133
135
 
@@ -174,4 +176,5 @@ test_files:
174
176
  - test/riemann_reporter_test.rb
175
177
  - test/timer_test.rb
176
178
  - test/utilization_timer_test.rb
179
+ - test/opentsdb_metrics_reporter_test.rb
177
180
  has_rdoc: