-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added VertX health check && metrics #30
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ mkmf.log | |
.DS_Store | ||
.idea/* | ||
*.gem | ||
.ruby-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
bin_dir = File.expand_path(File.dirname(__FILE__)) | ||
shell_script_path = File.join(bin_dir, File.basename($PROGRAM_NAME, '.rb') + '.sh') | ||
shell_script_path = File.join(__dir__, File.basename($PROGRAM_NAME, '.rb') + '.sh') | ||
|
||
exec shell_script_path, *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#! /usr/bin/env ruby | ||
# | ||
# check-vertx-health | ||
# | ||
# DESCRIPTION: | ||
# check-vertx-health simple way to expose health checks for VertX | ||
# | ||
# OUTPUT: | ||
# plain text | ||
# | ||
# PLATFORMS: | ||
# Linux | ||
# | ||
# DEPENDENCIES: | ||
# gem: rest-client | ||
# | ||
# | ||
# USAGE: | ||
# | ||
# | ||
# NOTES: | ||
# | ||
# LICENSE: | ||
# Zubov Yuri <[email protected]> sponsored by Actility, https://www.actility.com | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
# | ||
require 'sensu-plugin/check/cli' | ||
require 'rest-client' | ||
require 'json' | ||
|
||
class CheckVertXHealth < Sensu::Plugin::Check::CLI | ||
include CommonVertX | ||
|
||
option :endpoint, | ||
short: '-p ENDPOINT', | ||
long: '--endpointn ENDPOINT', | ||
description: 'VertX Endpoint', | ||
default: 'http://localhost:8080/rest/health' | ||
|
||
def check_health | ||
response = request | ||
|
||
result = JSON.parse(response) | ||
result['outcome'] | ||
end | ||
|
||
def run | ||
result = check_health | ||
|
||
if result == 'UP' | ||
ok 'VertX is UP' | ||
elsif result == 'DOWN' | ||
warning 'VertX is DOWN' | ||
end | ||
rescue StandardError => e | ||
critical e.message | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
bin_dir = File.expand_path(File.dirname(__FILE__)) | ||
shell_script_path = File.join(bin_dir, File.basename($PROGRAM_NAME, '.rb') + '.sh') | ||
shell_script_path = File.join(__dir__, File.basename($PROGRAM_NAME, '.rb') + '.sh') | ||
|
||
exec shell_script_path, *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
bin_dir = File.expand_path(File.dirname(__FILE__)) | ||
shell_script_path = File.join(bin_dir, File.basename($PROGRAM_NAME, '.rb') + '.py') | ||
shell_script_path = File.join(__dir__, File.basename($PROGRAM_NAME, '.rb') + '.py') | ||
|
||
exec shell_script_path, *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#! /usr/bin/env ruby | ||
# | ||
# metrics-vertx | ||
# | ||
# DESCRIPTION: | ||
# metrics-vertx get metrics from VertX | ||
# | ||
# OUTPUT: | ||
# metric-data | ||
# | ||
# PLATFORMS: | ||
# Linux | ||
# | ||
# DEPENDENCIES: | ||
# gem: rest-clien | ||
# | ||
# USAGE: | ||
# | ||
# | ||
# NOTES: | ||
# | ||
# LICENSE: | ||
# Zubov Yuri <[email protected]> sponsored by Actility, https://www.actility.com | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
# | ||
|
||
require 'sensu-plugin/metric/cli' | ||
require 'rest-client' | ||
require 'json' | ||
|
||
class MetricsVertX < Sensu::Plugin::Metric::CLI::Graphite | ||
include CommonVertX | ||
|
||
option :endpoint, | ||
short: '-p ENDPOINT', | ||
long: '--endpointn ENDPOINT', | ||
description: 'VertX Endpoint', | ||
default: 'http://localhost:8080/rest/metrics' | ||
|
||
option :scheme, | ||
description: 'Metric naming scheme, text to prepend to metric', | ||
short: '-S SCHEME', | ||
long: '--scheme SCHEME', | ||
default: "#{Socket.gethostname}.vertx" | ||
|
||
def metrics | ||
response = request | ||
JSON.parse(response) | ||
end | ||
|
||
def run | ||
metrics.each do |key, metrics| | ||
type_of_metric = metrics.delete('type') | ||
metrics.each do |metric_name, value| | ||
output("#{config[:scheme]}.#{key}.#{type_of_metric}.#{metric_name}", value) | ||
end | ||
end | ||
ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require 'sensu-plugins-java/common_vertx' | ||
require 'sensu-plugins-java/version' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module CommonVertX | ||
def request | ||
RestClient::Request.execute( | ||
method: :get, | ||
url: config[:endpoint] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s| | |
s.description = 'Sensu plugins for Java' | ||
s.email = '<[email protected]>' | ||
s.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) } | ||
s.files = Dir.glob('{bin,lib}/**/*') + %w(LICENSE README.md CHANGELOG.md) | ||
s.files = Dir.glob('{bin,lib}/**/*') + %w[LICENSE README.md CHANGELOG.md] | ||
s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-java' | ||
s.license = 'MIT' | ||
s.metadata = { 'maintainer' => 'sensu-plugin', | ||
|
@@ -22,21 +22,23 @@ Gem::Specification.new do |s| | |
s.platform = Gem::Platform::RUBY | ||
s.post_install_message = 'You can use the embedded Ruby by setting EMBEDDED_RUBY=true in /etc/default/sensu' | ||
s.require_paths = ['lib'] | ||
s.required_ruby_version = '>= 2.0.0' | ||
s.required_ruby_version = '>= 2.1.0' | ||
s.summary = 'Sensu plugins for Java' | ||
s.test_files = s.files.grep(%r{^(test|spec|features)/}) | ||
s.version = SensuPluginsJava::Version::VER_STRING | ||
|
||
s.add_runtime_dependency 'sensu-plugin', '~> 1.2' | ||
s.add_runtime_dependency 'english', '0.6.3' | ||
s.add_runtime_dependency 'rest-client', '~> 2.0' | ||
s.add_runtime_dependency 'sensu-plugin', '~> 1.2' | ||
|
||
s.add_development_dependency 'bundler', '~> 1.7' | ||
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4' | ||
s.add_development_dependency 'github-markup', '~> 1.3' | ||
s.add_development_dependency 'pry', '~> 0.10' | ||
s.add_development_dependency 'rake', '~> 10.5' | ||
s.add_development_dependency 'redcarpet', '~> 3.2' | ||
s.add_development_dependency 'rubocop', '~> 0.40.0' | ||
s.add_development_dependency 'rspec', '~> 3.4' | ||
s.add_development_dependency 'yard', '~> 0.8' | ||
s.add_development_dependency 'rspec', '~> 3.7' | ||
s.add_development_dependency 'rspec-mocks', '~> 3.7' | ||
s.add_development_dependency 'rubocop', '~> 0.51.0' | ||
s.add_development_dependency 'yard', '~> 0.9.11' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require_relative './spec_helper.rb' | ||
require_relative '../bin/check-vertx-health' | ||
require_relative './fixtures.rb' | ||
|
||
describe 'CheckVertXHealth' do | ||
before do | ||
CheckVertXHealth.class_variable_set(:@@autorun, false) | ||
end | ||
|
||
describe 'with positive answer' do | ||
before do | ||
@check = CheckVertXHealth.new | ||
allow(@check).to receive(:request).and_return(vertx_health_good_response) | ||
end | ||
|
||
describe '#run' do | ||
it 'tests that a check are ok' do | ||
expect(@check).to receive(:ok).with('VertX is UP') | ||
|
||
@check.run | ||
end | ||
end | ||
end | ||
|
||
describe 'with negative answer' do | ||
before do | ||
@check = CheckVertXHealth.new | ||
allow(@check).to receive(:request).and_return(vertx_health_bad_response) | ||
end | ||
|
||
describe '#run' do | ||
it 'tests that a check are ok' do | ||
expect(@check).to receive(:warning).with('VertX is DOWN') | ||
|
||
@check.run | ||
end | ||
end | ||
end | ||
|
||
describe 'can not receive answer' do | ||
before do | ||
@check = CheckVertXHealth.new | ||
allow(@check).to receive(:request).and_raise(StandardError, 'error') | ||
end | ||
|
||
describe '#run' do | ||
it 'tests that a check are ok' do | ||
expect(@check).to receive(:critical).with('error') | ||
|
||
@check.run | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this earlier but if we are now requiring
rest-client
it requires a c compiler to install this plugin this constitutes a breaking change and need to be called out like this:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done