Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alcy committed Aug 10, 2012
0 parents commit 5c98ee4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2011 Mohit Chawla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
32 changes: 32 additions & 0 deletions Rakefile.rb
@@ -0,0 +1,32 @@
require 'rubygems'
require 'rubygems/package_task'
require 'find'

# Don't include resource forks in tarballs on Mac OS X.
ENV['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
ENV['COPYFILE_DISABLE'] = 'true'

# Gemspec
gemspec = Gem::Specification.new do |s|
s.rubyforge_project = 'riemann-hbase'

s.name = 'riemann-hbase'
s.version = '0.0.2'
s.author = 'Mohit Chawla'
s.email = 'mohit.chawla.binary@gmail.com'
s.homepage = 'https://github.com/alcy/riemann-hbase'
s.platform = Gem::Platform::RUBY
s.summary = 'Utility to submit hbase metrics to Riemann'

s.add_dependency 'jmx4r'
s.add_dependency 'riemann-tools'

s.files = FileList['bin/*', 'LICENSE'].to_a
s.executables |= Dir.entries('bin/')

s.required_ruby_version = '>= 1.8.7'
end

Gem::PackageTask.new gemspec do |p|
end

53 changes: 53 additions & 0 deletions bin/riemann-hbase
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby

require 'riemann/tools'
require 'jmx4r'

# Works under JRuby
# Riemann Client to gather Hbase stats from JMX - currently can talk to localhost, without auth

class Riemann::Tools::Hbase
include Riemann::Tools

opt :server_type, "Hbase Server Type", :default => "regionserver"
opt :jmx_port, "JMX Port to connect to", :default => "10101"

def alert(service, state, metric, description, tags)
report(
:service => service,
:state => state.to_s,
:metric => metric.to_f,
:description => description,
:tags => tags
)
end

def all_stats

if opts[:server_type] == "master"
bean_object_name = "hadoop:service=Master,name=MasterStatistics"
else
bean_object_name = "hadoop:service=RegionServer,name=RegionServerStatistics"
end

begin
JMX::MBean.establish_connection :host => "localhost", :port => "#{opts[:jmx_port]}"
rescue Exception => e
alert "hbase-#{opts[:server_type]}", :critical, "", "Could not connect to JMX, #{e.message}", ""
return
end

stats = JMX::MBean.find_by_name "#{bean_object_name}"
stats.attributes.keys.each { |attr|
alert "#{attr}", :ok, "#{stats.send attr}", "#{attr}", "hbase-#{opts[:server_type]}"
}

end

def tick
all_stats
end

end

Riemann::Tools::Hbase.run

0 comments on commit 5c98ee4

Please sign in to comment.