Skip to content
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 1 commit into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ mkmf.log
.DS_Store
.idea/*
*.gem
.ruby-version
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ RegexpLiteral:

Style/Documentation:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'test/**/*.rb'
- 'sensu-plugins-java.gemspec'
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cache:
install:
- bundle install
rvm:
- 2.0
- 2.1
- 2.2
- 2.3.0
Expand All @@ -27,7 +26,6 @@ deploy:
on:
tags: true
all_branches: true
rvm: 2.0
rvm: 2.1
rvm: 2.2
rvm: 2.3.0
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]
### Breaking Changes
- dropped ruby 2.1 support (@yuri-zubov sponsored by Actility, https://www.actility.com)
- added `rest-client` as a dependency which requires you to have a local c compiler present to install this plugin (@yuri-zubov sponsored by Actility, https://www.actility.com)

### Security
- updated yard dependency to `~> 0.9.11` per: https://nvd.nist.gov/vuln/detail/CVE-2017-17042 (@yuri-zubov sponsored by Actility, https://www.actility.com)
- updated rubocop dependency to `~> 0.51.0` per: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8418. (@yuri-zubov sponsored by Actility, https://www.actility.com)

### Added
- Added ability to get metrics from VertX (@yuri-zubov sponsored by Actility, https://www.actility.com)
- Added health-check VertX (@yuri-zubov sponsored by Actility, https://www.actility.com)

## [1.3.0] - 2017-09-05
### Added
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require 'yard'
require 'yard/rake/yardoc_task'

YARD::Rake::YardocTask.new do |t|
OTHER_PATHS = %w().freeze
OTHER_PATHS = %w[].freeze
t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS]
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md)
t.options = %w[--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md]
end

RuboCop::RakeTask.new
Expand All @@ -35,4 +35,4 @@ task :check_binstubs do
end
end

task default: [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs]
task default: %i[spec make_bin_executable yard rubocop check_binstubs]
3 changes: 1 addition & 2 deletions bin/check-java-heap-pcnt.rb
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
59 changes: 59 additions & 0 deletions bin/check-vertx-health.rb
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
3 changes: 1 addition & 2 deletions bin/metrics-java-heap-graphite.rb
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
3 changes: 1 addition & 2 deletions bin/metrics-jstat.rb
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
61 changes: 61 additions & 0 deletions bin/metrics-vertx.rb
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
1 change: 1 addition & 0 deletions lib/sensu-plugins-java.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'sensu-plugins-java/common_vertx'
require 'sensu-plugins-java/version'
8 changes: 8 additions & 0 deletions lib/sensu-plugins-java/common_vertx.rb
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
14 changes: 8 additions & 6 deletions sensu-plugins-java.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
Copy link
Member

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:

### Breaking Changes
- dropped ruby 2.1 support (@yuri-zubov sponsored by Actility, https://www.actility.com)
- added `rest-client` as a dependency which requires you to have a local c compiler present to install this plugin (@yuri-zubov sponsored by Actility, https://www.actility.com)

``` 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
54 changes: 54 additions & 0 deletions test/check-vertx-health_spec.rb
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
Loading