newrelic-rmq-plugin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.gitlab-ci.yml +36 -0
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +17 -0
- data/bin/setup +8 -0
- data/config/template_newrelic_plugin.yml +22 -0
- data/exe/newrelic-rmq-plugin +15 -0
- data/lib/newrelic-rmq-plugin.rb +12 -0
- data/lib/newrelic-rmq-plugin/agent.rb +117 -0
- data/lib/newrelic-rmq-plugin/cli.rb +64 -0
- data/lib/newrelic-rmq-plugin/config.rb +71 -0
- data/lib/newrelic-rmq-plugin/helpers/configuration.rb +57 -0
- data/lib/newrelic-rmq-plugin/util.rb +71 -0
- data/lib/newrelic-rmq-plugin/version.rb +3 -0
- data/newrelic-rmq-plugin.gemspec +41 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7af33a39962a1845d9b493e94eedd67808d2c645
|
4
|
+
data.tar.gz: 512227ba2e5474b91f553be22ee9606feaa946a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e76862b37f8d7d0d9edd1b1f0d7167896280d0548d8c90fe7f56fa423f47021ecae6b18621c14b7645dede0e2bf3570c3b602096c95fba5074470aa37f63248
|
7
|
+
data.tar.gz: 3ffc168ac491220823ac6e6ca8a5266ab512add61d6d5578e905115b722fa7d9ac7517da7722bebd837370ad02f27fd9397b52472f2f4bd83b3e60712c7f42fe
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
before_script:
|
2
|
+
- ruby -v
|
3
|
+
- which ruby
|
4
|
+
- gem install bundler --no-ri --no-rdoc
|
5
|
+
- bundle install --jobs $(nproc) --path vendor/bundle
|
6
|
+
|
7
|
+
test:Ruby 2.3:
|
8
|
+
image: ruby:2.3
|
9
|
+
cache:
|
10
|
+
paths:
|
11
|
+
- .bundle
|
12
|
+
- vendor/bundle
|
13
|
+
script:
|
14
|
+
- bundle exec rubocop
|
15
|
+
tags:
|
16
|
+
- ruby
|
17
|
+
except:
|
18
|
+
- tags
|
19
|
+
|
20
|
+
release:Ruby 2.3:
|
21
|
+
image: ruby:2.3
|
22
|
+
cache:
|
23
|
+
paths:
|
24
|
+
- .bundle
|
25
|
+
- vendor/bundle
|
26
|
+
script:
|
27
|
+
- bundle exec rubocop
|
28
|
+
- bundle exec rake build
|
29
|
+
artifacts:
|
30
|
+
name: "newrelic-rmq-plugin-$CI_BUILD_REF_NAME"
|
31
|
+
paths:
|
32
|
+
- pkg/*.gem
|
33
|
+
tags:
|
34
|
+
- ruby
|
35
|
+
only:
|
36
|
+
- tags
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Brian Dwyer - Intelligent Digital Services
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# newrelic-rmq-plugin
|
2
|
+
* NewRelic RabbitMQ Plugin Agent
|
3
|
+
* Polls RabbitMQ for Metrics & Ships to NewRelic
|
4
|
+
|
5
|
+
## Background
|
6
|
+
This is based primarily off of the [RedBubble NewRelic RabbitMQ Agent](https://github.com/redbubble/newrelic-rabbitmq-agent)
|
7
|
+
The idea was to package this is a gem for simplified deployment, and add/adjust some functionality.
|
8
|
+
|
9
|
+
## Running as a Service
|
10
|
+
You'll likely want to run this as a service, `SystemD` or `Upstart` will likely be your friend in this regard.
|
11
|
+
|
12
|
+
## Security
|
13
|
+
You should lock down permissions on all configuration files in this project to only the user which this runs as...
|
14
|
+
|
15
|
+
To run this project securely, **DON'T** run it as the RabbitMQ or root user.
|
16
|
+
|
17
|
+
For Global Metrics, the RabbitMQ user should have the `monitoring` tag. For Per-Queue Metrics, the RabbitMQ user should exist on the vHost. It does not need read/write/config.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'newrelic-rmq-plugin'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install newrelic-rmq-plugin
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
$ newrelic-rmq-plugin --nr-cfg-file /etc/newrelic/rabbitmq.yml
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bdwyertech/newrelic-rmq-plugin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'github-rundeck'
|
8
|
+
|
9
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
10
|
+
# with your gem easier. You can also use a different console, if you like.
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
require 'irb'
|
17
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Please make sure to update the license_key information with the license key for your New Relic
|
2
|
+
# account.
|
3
|
+
#
|
4
|
+
#
|
5
|
+
newrelic:
|
6
|
+
#
|
7
|
+
# Update with your New Relic account license key:
|
8
|
+
#
|
9
|
+
license_key: 'YOUR_LICENSE_KEY_HERE'
|
10
|
+
#
|
11
|
+
# Set to '1' for verbose output, remove for normal output.
|
12
|
+
# All output goes to stdout/stderr.
|
13
|
+
#
|
14
|
+
verbose: 1
|
15
|
+
#
|
16
|
+
# Agent Configuration:
|
17
|
+
#
|
18
|
+
agents:
|
19
|
+
rabbitmq:
|
20
|
+
management_api_url: http://guest:guest@localhost:15672/api/
|
21
|
+
server_name: SERVER_NAME_HERE
|
22
|
+
verify_ssl: false
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# NewRelic - RabbitMQ Plugin
|
4
|
+
# Brian Dwyer - Intelligent Digital Services - 11/10/16
|
5
|
+
|
6
|
+
lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
8
|
+
|
9
|
+
# => Catch Ctrl+C's to avoid stack traces
|
10
|
+
Signal.trap('INT') { abort }
|
11
|
+
|
12
|
+
require 'newrelic-rmq-plugin'
|
13
|
+
|
14
|
+
# => Launch the Plugin
|
15
|
+
NewRelicRMQPlugin::CLI.run(ARGV)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# NewRelic - RabbitMQ Plugin
|
3
|
+
# Brian Dwyer - Intelligent Digital Services - 11/10/16
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'newrelic-rmq-plugin/cli'
|
8
|
+
|
9
|
+
# => NewRelic Plugin
|
10
|
+
module NewRelicRMQPlugin
|
11
|
+
# => Placeholder
|
12
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: newrelic-rmq-plugin
|
5
|
+
# NewRelicRMQPlugin:: Agent
|
6
|
+
#
|
7
|
+
# Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'bundler/setup'
|
14
|
+
require 'newrelic_plugin'
|
15
|
+
require 'rabbitmq_manager'
|
16
|
+
require 'uri'
|
17
|
+
require 'newrelic-rmq-plugin/version'
|
18
|
+
|
19
|
+
module NewRelicRMQPlugin
|
20
|
+
# => NewRelic RabbitMQ Collector Agent
|
21
|
+
module Agent
|
22
|
+
# => Import the NewRelic Agent Base
|
23
|
+
class Agent < NewRelic::Plugin::Agent::Base
|
24
|
+
agent_guid 'com.bdwyertech.newrelic.plugin.rabbitmq'
|
25
|
+
agent_version NewRelicRMQPlugin::VERSION
|
26
|
+
agent_config_options :management_api_url, :server_name, :verify_ssl
|
27
|
+
agent_human_labels('RabbitMQ') { server_name }
|
28
|
+
|
29
|
+
def poll_cycle
|
30
|
+
# => Collect Per-Queue Metrics
|
31
|
+
per_queue
|
32
|
+
|
33
|
+
# => Collect Global Metrics
|
34
|
+
global_metrics
|
35
|
+
|
36
|
+
# => Grab Environment Information
|
37
|
+
env_status
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
#
|
43
|
+
# => Collectors
|
44
|
+
#
|
45
|
+
|
46
|
+
# => Global Metrics
|
47
|
+
def global_metrics # rubocop: disable AbcSize
|
48
|
+
report_metric 'Global Queue Size/Total', 'Queued Messages', rmq_manager.overview['queue_totals']['messages'] || 0
|
49
|
+
report_metric 'Global Queue Size/Ready', 'Queued Messages', rmq_manager.overview['queue_totals']['messages_ready'] || 0
|
50
|
+
report_metric 'Global Queue Size/Unacked', 'Queued Messages', rmq_manager.overview['queue_totals']['messages_unacknowledged'] || 0
|
51
|
+
|
52
|
+
report_metric 'Global Message Rate/Deliver', 'messages/sec', rate_for('deliver')
|
53
|
+
report_metric 'Global Message Rate/Acknowledge', 'messages/sec', rate_for('ack')
|
54
|
+
report_metric 'Global Message Rate/Return', 'messages/sec', rate_for('return_unroutable')
|
55
|
+
|
56
|
+
rmq_manager.overview['object_totals'].each do |obj|
|
57
|
+
report_metric "Global Object Totals/#{obj[0].capitalize}", nil, obj[1]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# => Per-Queue Metrics
|
62
|
+
def per_queue # rubocop: disable AbcSize
|
63
|
+
rmq_manager.queues.each do |queue|
|
64
|
+
queue_name = queue['name'].split('queue.').last
|
65
|
+
|
66
|
+
report_metric "Queue Size/#{queue_name}/Total", 'Queued Messages', queue['messages']
|
67
|
+
report_metric "Queue Size/#{queue_name}/Ready", 'Queued Messages', queue['messages_ready']
|
68
|
+
report_metric "Queue Size/#{queue_name}/Unacked", 'Queued Messages', queue['messages_unacknowledged']
|
69
|
+
|
70
|
+
report_metric "Message Rate/#{queue_name}/Deliver", 'messages/sec', per_queue_rate_for('deliver', queue)
|
71
|
+
report_metric "Message Rate/#{queue_name}/Acknowledge", 'messages/sec', per_queue_rate_for('ack', queue)
|
72
|
+
report_metric "Message Rate/#{queue_name}/Return", 'messages/sec', per_queue_rate_for('return_unroutable', queue)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# => RabbitMQ Configuration Status
|
77
|
+
def env_status
|
78
|
+
report_metric 'Status/Version', nil, rmq_manager.overview['rabbitmq_version']
|
79
|
+
report_metric 'Status/Cluster Name', nil, rmq_manager.overview['cluster_name']
|
80
|
+
report_metric 'Status/Erlang Version', nil, rmq_manager.overview['erlang_version']
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# => Helper Methods
|
85
|
+
#
|
86
|
+
def per_queue_rate_for(type, queue)
|
87
|
+
msg_stats = queue['message_stats']
|
88
|
+
|
89
|
+
if msg_stats.is_a?(Hash)
|
90
|
+
details = msg_stats["#{type}_details"]
|
91
|
+
details ? details['rate'] : 0
|
92
|
+
else
|
93
|
+
0
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def rate_for(type)
|
98
|
+
msg_stats = rmq_manager.overview['message_stats']
|
99
|
+
|
100
|
+
if msg_stats.is_a?(Hash)
|
101
|
+
details = msg_stats["#{type}_details"]
|
102
|
+
details ? details['rate'] : 0
|
103
|
+
else
|
104
|
+
0
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# => Define the RabbitMQ Connection
|
109
|
+
def rmq_manager
|
110
|
+
@rmq_manager ||= ::RabbitMQManager.new(management_api_url, verify: verify_ssl)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# => Register the Agent
|
115
|
+
NewRelic::Plugin::Setup.install_agent :rabbitmq, self
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength, AbcSize
|
3
|
+
#
|
4
|
+
# Gem Name:: newrelic-rmq-plugin
|
5
|
+
# NewRelicRMQPlugin:: CLI
|
6
|
+
#
|
7
|
+
# Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'mixlib/cli'
|
13
|
+
require 'newrelic-rmq-plugin/agent'
|
14
|
+
require 'newrelic-rmq-plugin/config'
|
15
|
+
require 'newrelic-rmq-plugin/util'
|
16
|
+
|
17
|
+
module NewRelicRMQPlugin
|
18
|
+
#
|
19
|
+
# => NewRelic Launcher
|
20
|
+
#
|
21
|
+
module CLI
|
22
|
+
module_function
|
23
|
+
|
24
|
+
#
|
25
|
+
# => Options Parser
|
26
|
+
#
|
27
|
+
class Options
|
28
|
+
# => Mix-In the CLI Option Parser
|
29
|
+
include Mixlib::CLI
|
30
|
+
|
31
|
+
option :nr_config_file,
|
32
|
+
short: '-nr CONFIG',
|
33
|
+
long: '--nr-cfg-file CONFIG',
|
34
|
+
description: "NewRelic Configuration File (Default: #{Config.nr_config_file})"
|
35
|
+
end
|
36
|
+
|
37
|
+
# => Launch the Application
|
38
|
+
def run(argv = ARGV)
|
39
|
+
# => Parse CLI Configuration
|
40
|
+
cli = Options.new
|
41
|
+
cli.parse_options(argv)
|
42
|
+
|
43
|
+
# => Parse JSON Config File (If Specified and Exists)
|
44
|
+
json_config = Util.parse_json_config(cli.config[:config_file] || Config.config_file)
|
45
|
+
|
46
|
+
# => Grab the Default Values
|
47
|
+
default = Config.options
|
48
|
+
|
49
|
+
# => Merge Configuration (CLI Wins)
|
50
|
+
config = [default, json_config, cli.config].compact.reduce(:merge)
|
51
|
+
|
52
|
+
# => Apply Configuration
|
53
|
+
Config.setup do |cfg|
|
54
|
+
cfg.nr_config_file = config[:nr_config_file]
|
55
|
+
end
|
56
|
+
|
57
|
+
# => Load up the NewRelic Configuration
|
58
|
+
NewRelic::Plugin::Config.config_file = Config.nr_config_file
|
59
|
+
|
60
|
+
# => Launch the Plugin
|
61
|
+
NewRelic::Plugin::Run.setup_and_run
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: newrelic-rmq-plugin
|
5
|
+
# NewRelicRMQPlugin:: Config
|
6
|
+
#
|
7
|
+
# Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'newrelic-rmq-plugin/helpers/configuration'
|
13
|
+
require 'pathname'
|
14
|
+
|
15
|
+
module NewRelicRMQPlugin
|
16
|
+
# => This is the Configuration module.
|
17
|
+
module Config
|
18
|
+
module_function
|
19
|
+
|
20
|
+
extend Configuration
|
21
|
+
|
22
|
+
# => Gem Root Directory
|
23
|
+
define_setting :root, Pathname.new(File.expand_path('../../../', __FILE__))
|
24
|
+
|
25
|
+
# => My Name
|
26
|
+
define_setting :author, 'Brian Dwyer - Intelligent Digital Services'
|
27
|
+
|
28
|
+
# => Application Environment
|
29
|
+
define_setting :environment, :production
|
30
|
+
|
31
|
+
# => Config File
|
32
|
+
define_setting :config_file, File.join(root, 'config', 'config.json')
|
33
|
+
|
34
|
+
# => NewRelic Config File
|
35
|
+
define_setting :nr_config_file, File.join(root, 'config', 'newrelic_plugin.yml')
|
36
|
+
|
37
|
+
#
|
38
|
+
# => Facilitate Dynamic Addition of Configuration Values
|
39
|
+
#
|
40
|
+
# => @return [class_variable]
|
41
|
+
#
|
42
|
+
def add(config = {})
|
43
|
+
config.each do |key, value|
|
44
|
+
define_setting key.to_sym, value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# => Facilitate Dynamic Removal of Configuration Values
|
50
|
+
#
|
51
|
+
# => @return nil
|
52
|
+
#
|
53
|
+
def clear(config)
|
54
|
+
Array(config).each do |setting|
|
55
|
+
delete_setting setting
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# => List the Configurable Keys as a Hash
|
61
|
+
#
|
62
|
+
# @return [Hash]
|
63
|
+
#
|
64
|
+
def options
|
65
|
+
map = Config.class_variables.map do |key|
|
66
|
+
[key.to_s.tr('@', '').to_sym, class_variable_get(:"#{key}")]
|
67
|
+
end
|
68
|
+
Hash[map]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Gem Name:: cloudimages-rundeck
|
4
|
+
# Helper:: Configuration
|
5
|
+
#
|
6
|
+
# Author: Eli Fatsi - https://www.viget.com/articles/easy-gem-configuration-variables-with-defaults
|
7
|
+
# Contributor: Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
|
10
|
+
# => Configuration Helper Module
|
11
|
+
module Configuration
|
12
|
+
#
|
13
|
+
# => Provides a method to configure an Application
|
14
|
+
# => Example:
|
15
|
+
# DeployInfo::Config.setup do |cfg|
|
16
|
+
# cfg.config_file = 'abc.json'
|
17
|
+
# cfg.app_name = 'GemBase'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
def setup
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
|
24
|
+
def define_setting(name, default = nil)
|
25
|
+
class_variable_set("@@#{name}", default)
|
26
|
+
|
27
|
+
define_class_method "#{name}=" do |value|
|
28
|
+
class_variable_set("@@#{name}", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
define_class_method name do
|
32
|
+
class_variable_get("@@#{name}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_setting(name)
|
37
|
+
remove_class_variable("@@#{name}")
|
38
|
+
|
39
|
+
delete_class_method(name)
|
40
|
+
rescue NameError # => Handle Non-Existent Settings
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def define_class_method(name, &block)
|
47
|
+
(class << self; self; end).instance_eval do
|
48
|
+
define_method name, &block
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_class_method(name)
|
53
|
+
(class << self; self; end).instance_eval do
|
54
|
+
undef_method name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: newrelic-rmq-plugin
|
5
|
+
# NewRelicRMQPlugin:: Util
|
6
|
+
#
|
7
|
+
# Copyright (C) 2016 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
module NewRelicRMQPlugin
|
15
|
+
# => Utility Methods
|
16
|
+
module Util
|
17
|
+
module_function
|
18
|
+
|
19
|
+
########################
|
20
|
+
# => File I/O <= #
|
21
|
+
########################
|
22
|
+
|
23
|
+
# => Define JSON Parser
|
24
|
+
def parse_json_config(file = nil, symbolize = true)
|
25
|
+
return unless file && ::File.exist?(file.to_s)
|
26
|
+
begin
|
27
|
+
::JSON.parse(::File.read(file.to_s), symbolize_names: symbolize)
|
28
|
+
rescue JSON::ParserError
|
29
|
+
return
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# => Define JSON Writer
|
34
|
+
def write_json_config(file, object)
|
35
|
+
return unless file && object
|
36
|
+
begin
|
37
|
+
File.open(file, 'w') { |f| f.write(JSON.pretty_generate(object)) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# => Check if a string is an existing file, and return it's content
|
42
|
+
def filestring(file, size = 8192)
|
43
|
+
return unless file
|
44
|
+
return file unless file.is_a?(String) && File.file?(file) && File.size(file) <= size
|
45
|
+
File.read(file)
|
46
|
+
end
|
47
|
+
|
48
|
+
#############################
|
49
|
+
# => Serialization <= #
|
50
|
+
#############################
|
51
|
+
|
52
|
+
def serialize(response)
|
53
|
+
# => Serialize Object into JSON Array
|
54
|
+
JSON.pretty_generate(response.map(&:name).sort_by(&:downcase))
|
55
|
+
end
|
56
|
+
|
57
|
+
def serialize_csv(csv)
|
58
|
+
# => Serialize a CSV String into an Array
|
59
|
+
return unless csv && csv.is_a?(String)
|
60
|
+
csv.split(',')
|
61
|
+
end
|
62
|
+
|
63
|
+
def serialize_revisions(branches, tags)
|
64
|
+
# => Serialize Branches/Tags into JSON Array
|
65
|
+
# => Branches = String, Tags = Key/Value
|
66
|
+
branches = branches.map(&:name).sort_by(&:downcase)
|
67
|
+
tags = tags.map(&:name).sort_by(&:downcase).reverse.map { |tag| { name: "Tag: #{tag}", value: tag } }
|
68
|
+
JSON.pretty_generate(branches + tags)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'newrelic-rmq-plugin/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'newrelic-rmq-plugin'
|
10
|
+
spec.version = NewRelicRMQPlugin::VERSION
|
11
|
+
spec.authors = ['Brian Dwyer']
|
12
|
+
spec.email = ['bdwyer@IEEE.org']
|
13
|
+
|
14
|
+
spec.summary = %(NewRelic RabbitMQ Plugin)
|
15
|
+
spec.homepage = 'https://github.com/bdwyertech/newrelic-rabbitmq-plugin'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
# => Dependencies
|
32
|
+
spec.add_runtime_dependency 'newrelic_plugin'
|
33
|
+
spec.add_runtime_dependency 'rabbitmq_manager', '~> 0.3.0'
|
34
|
+
spec.add_runtime_dependency 'mixlib-cli', '~> 1.7'
|
35
|
+
|
36
|
+
# => Development Dependencies
|
37
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
38
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
+
spec.add_development_dependency 'rubocop'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic-rmq-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Dwyer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: newrelic_plugin
|
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: rabbitmq_manager
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mixlib-cli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- bdwyer@IEEE.org
|
114
|
+
executables:
|
115
|
+
- newrelic-rmq-plugin
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".gitlab-ci.yml"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- CHANGELOG.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- config/template_newrelic_plugin.yml
|
130
|
+
- exe/newrelic-rmq-plugin
|
131
|
+
- lib/newrelic-rmq-plugin.rb
|
132
|
+
- lib/newrelic-rmq-plugin/agent.rb
|
133
|
+
- lib/newrelic-rmq-plugin/cli.rb
|
134
|
+
- lib/newrelic-rmq-plugin/config.rb
|
135
|
+
- lib/newrelic-rmq-plugin/helpers/configuration.rb
|
136
|
+
- lib/newrelic-rmq-plugin/util.rb
|
137
|
+
- lib/newrelic-rmq-plugin/version.rb
|
138
|
+
- newrelic-rmq-plugin.gemspec
|
139
|
+
homepage: https://github.com/bdwyertech/newrelic-rabbitmq-plugin
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata:
|
143
|
+
allowed_push_host: https://rubygems.org
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.5.1
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: NewRelic RabbitMQ Plugin
|
164
|
+
test_files: []
|