Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
sensu-plugins-cassandra / bin / check-cassandra-messages.rb
Size: Mime:
#! /usr/bin/env ruby
#
# check-cassandra-messages
#
# DESCRIPTION:
#   This plugin uses Apache Cassandra's `nodetool` to check to see
#   if any node in the cluster has run into a schema disagreement problem
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: english
#   Cassandra's nodetool
#
# USAGE:
#   command => check-cassandra-messages.rb
#
# NOTES:
#   See http://www.datastax.com/documentation/cassandra/2.0/cassandra/dml/dml_handle_schema_disagree_t.html
#   for more details
#
# LICENSE:
#   Copyright 2014 Sonian, Inc. and contributors. <support@sensuapp.org>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'
require 'English'

#
# Check Cassandra Messages
#
class CheckCassandraMessages < Sensu::Plugin::Check::CLI
  option :hostname,
         short: '-h HOSTNAME',
         long: '--host HOSTNAME',
         description: 'cassandra hostname',
         default: 'localhost'

  option :port,
         short: '-P PORT',
         long: '--port PORT',
         description: 'cassandra JMX port',
         default: '7199'

  # execute cassandra's nodetool and return output as string
  def nodetool_cmd(cmd)
    out = `nodetool -h #{config[:hostname]} -p #{config[:port]} #{cmd} 2>&1`
    [out, $CHILD_STATUS]
  end

  def parse_tpstats# rubocop:disable all
    tpstats = nodetool_cmd('tpstats')
    tpstats[0].each_line do |line|
      next if line =~ /^Pool Name/
      next if line =~ /^Message type/
      if m = line.match(/MUTATION.*/)# rubocop:disable all
        x = line.match(/^(\w+)\s+(\d+)$/)
        (message_type, dropped) = x.captures
        if dropped.to_i > 0 
           output = "Dropped messages", dropped
           warning(output.join(" "))
        end
      end
    end
  end

  def run
    parse_tpstats
    ok
  end
end