harness-rabbitmq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 113d0b5365ff84c4628152b8e8436fd6c9c67e22
4
+ data.tar.gz: 5c68da56c97556ad069ec4f4a0fb17102957167d
5
+ SHA512:
6
+ metadata.gz: 262b13a132c727cac6e9297ed66e3c98c9b6d8e3b3e737778108920ed480a126a704e7679e02297db996a617ed23c8d38d6ad1e1339a10a6adcce0a10140a1fc
7
+ data.tar.gz: d3f3c6bc14e60eb352a620b195f2eb9f3a5cdd327cc3deacbe35f8db1e21b60b69e6e676e05751bcac83f1d6237d9bb1ac775607cadeefcabd9698f9a64ad35a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in harness-varnish.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ahawkins
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.
@@ -0,0 +1,29 @@
1
+ # Harness::Rabbitmq
2
+
3
+ Log RabbitMQ message stats to Harness
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'harness-rabbitmq'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install harness-rabbitmq
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'harness/rabbitmq/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "harness-rabbitmq"
8
+ spec.version = Harness::Rabbitmq::VERSION
9
+ spec.authors = ["ahawkins"]
10
+ spec.email = ["adam@hawkins.io"]
11
+ spec.description = %q{RabbitMQ gauge for Harness}
12
+ spec.summary = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "harness"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "webmock"
26
+ end
@@ -0,0 +1 @@
1
+ require 'harness/rabbitmq'
@@ -0,0 +1,61 @@
1
+ require "harness/rabbitmq/version"
2
+
3
+ require 'harness'
4
+
5
+ require 'uri'
6
+ require 'net/https'
7
+ require 'multi_json'
8
+
9
+ module Harness
10
+ class RabbitmqGauge
11
+ include Instrumentation
12
+
13
+ BadResponseError = Class.new StandardError
14
+
15
+ def initialize(url)
16
+ @url = url
17
+ end
18
+
19
+ def log
20
+ uri = URI.parse @url
21
+
22
+ http = Net::HTTP.new uri.host, uri.port
23
+ http.use_ssl = uri.scheme == 'https'
24
+
25
+ request = Net::HTTP::Get.new uri.request_uri
26
+
27
+ if uri.user || uri.password
28
+ request.basic_auth uri.user, uri.password
29
+ end
30
+
31
+ response = http.request request
32
+ body = MultiJson.load response.body
33
+
34
+ if response.code.to_i != 200
35
+ raise BadResponseError, "Server did not respond correctly! #{response.inspect}"
36
+ end
37
+
38
+ body = MultiJson.load response.body
39
+
40
+ body.each do |exchange|
41
+ next unless exchange.key? 'message_stats'
42
+ name, stats = exchange.fetch('name'), exchange.fetch('message_stats')
43
+
44
+ if stats.key?('confirm')
45
+ gauge "rabbitmq.#{name}.confirmed.count", stats.fetch('confirm')
46
+ gauge "rabbitmq.#{name}.confirmed.rate", stats.fetch('confirm_details').fetch('rate')
47
+ end
48
+
49
+ if stats.key?('publish_in')
50
+ gauge "rabbitmq.#{name}.published.count", stats.fetch('publish_in')
51
+ gauge "rabbitmq.#{name}.published.rate", stats.fetch('publish_in_details').fetch('rate')
52
+ end
53
+
54
+ if stats.key?('publish_out')
55
+ gauge "rabbitmq.#{name}.consumed.count", stats.fetch('publish_out')
56
+ gauge "rabbitmq.#{name}.consumed.rate", stats.fetch('publish_out_details').fetch('rate')
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module Harness
2
+ module Rabbitmq
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ [
2
+ {
3
+ "message_stats":{
4
+ "confirm":1,
5
+ "confirm_details":{
6
+ "rate":0.0
7
+ },
8
+ "publish_in":90803,
9
+ "publish_in_details":{
10
+ "rate":0.0
11
+ },
12
+ "publish_out":83055,
13
+ "publish_out_details":{
14
+ "rate":0.0
15
+ }
16
+ },
17
+ "name":"dummy",
18
+ "vhost":"pibhbhyv",
19
+ "type":"fanout",
20
+ "durable":true,
21
+ "auto_delete":false,
22
+ "internal":false,
23
+ "arguments":{
24
+
25
+ },
26
+ "policy":"HA"
27
+ }
28
+ ]
@@ -0,0 +1,61 @@
1
+ require_relative 'test_helper'
2
+
3
+ class RabbitmqGaugeTest < MiniTest::Unit::TestCase
4
+ attr_accessor :url, :gauge
5
+
6
+ def setup
7
+ super
8
+ @url = 'http://foo.com:517672/api/exchanges/some_vhost'
9
+ @gauge = Harness::RabbitmqGauge.new url
10
+
11
+ stub_request(:get, url).to_return({
12
+ status: 200,
13
+ body: File.read(File.expand_path('../fixture.json', __FILE__))
14
+ })
15
+ end
16
+
17
+ def test_records_total_confirmed
18
+ log
19
+ assert_gauge 'rabbitmq.dummy.confirmed.count'
20
+ end
21
+
22
+ def test_records_confirmation_rate
23
+ log
24
+ assert_gauge 'rabbitmq.dummy.confirmed.rate'
25
+ end
26
+
27
+ def test_records_total_published
28
+ log
29
+ assert_gauge 'rabbitmq.dummy.published.count'
30
+ end
31
+
32
+ def test_records_publish_rate
33
+ log
34
+ assert_gauge 'rabbitmq.dummy.published.rate'
35
+ end
36
+
37
+ def test_records_total_consumed
38
+ log
39
+ assert_gauge 'rabbitmq.dummy.consumed.count'
40
+ end
41
+
42
+ def test_records_consumption_rate
43
+ log
44
+ assert_gauge 'rabbitmq.dummy.consumed.rate'
45
+ end
46
+
47
+ def test_blows_up_if_server_does_not_return_a_200
48
+ assert_raises Harness::RabbitmqGauge::BadResponseError do
49
+ stub_request(:get, 'http://bad.host').to_return({
50
+ status: 400,
51
+ body: File.read(File.expand_path('../fixture.json', __FILE__))
52
+ })
53
+ Harness::RabbitmqGauge.new('http://bad.host').log
54
+ end
55
+ end
56
+
57
+ private
58
+ def log
59
+ gauge.log
60
+ end
61
+ end
@@ -0,0 +1,64 @@
1
+ require 'bundler/setup'
2
+ require 'harness-rabbitmq'
3
+ require 'minitest/unit'
4
+ require 'minitest/autorun'
5
+ require 'webmock/minitest'
6
+
7
+ class MiniTest::Unit::TestCase
8
+ def setup
9
+ Harness.config.collector = Harness::FakeCollector.new
10
+ Harness.config.queue = Harness::SyncQueue.new
11
+ end
12
+
13
+ def assert_timer(name)
14
+ refute_empty timers
15
+ timer = timers.find { |t| t.name == name }
16
+ assert timer, "Timer #{name} not logged!"
17
+ end
18
+
19
+ def assert_increment(name)
20
+ refute_empty increments
21
+ increment = increments.find { |i| i.name == name }
22
+ assert increment, "Increment #{name} not logged!"
23
+ end
24
+
25
+ def assert_decrement(name)
26
+ refute_empty decrements
27
+ decrement = decrements.find { |i| i.name == name }
28
+ assert decrement, "decrement #{name} not logged!"
29
+ end
30
+
31
+ def assert_gauge(name)
32
+ refute_empty gauges
33
+ gauge = gauges.find { |g| g.name == name }
34
+ assert gauge, "gauge #{name} not logged!"
35
+ end
36
+
37
+ def instrument(name, data = {}, &block)
38
+ ActiveSupport::Notifications.instrument name, data, &block
39
+ end
40
+
41
+ def collector
42
+ Harness.config.collector
43
+ end
44
+
45
+ def timers
46
+ collector.timers
47
+ end
48
+
49
+ def increments
50
+ collector.increments
51
+ end
52
+
53
+ def decrements
54
+ collector.decrements
55
+ end
56
+
57
+ def counters
58
+ collector.counters
59
+ end
60
+
61
+ def gauges
62
+ collector.gauges
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harness-rabbitmq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ahawkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: harness
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: RabbitMQ gauge for Harness
70
+ email:
71
+ - adam@hawkins.io
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - harness-rabbitmq.gemspec
82
+ - lib/harness-rabbitmq.rb
83
+ - lib/harness/rabbitmq.rb
84
+ - lib/harness/rabbitmq/version.rb
85
+ - test/fixture.json
86
+ - test/rabbitmq_test.rb
87
+ - test/test_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: ''
112
+ test_files:
113
+ - test/fixture.json
114
+ - test/rabbitmq_test.rb
115
+ - test/test_helper.rb