Repository URL to install this package:
|
Version:
2.2.0 ▾
|
#! /usr/bin/env ruby
#
# check-cassandra-throughput
#
# 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-throughput --operation <read|write> --measurement <latency|throughtput>
#
# 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 Throughput
#
class CheckCassandraThroughput < 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'
option :operation,
short: '-O OPERATION',
long: '--operation OPERATION',
description: 'read or write op',
default: 'read'
option :measurement,
short: '-M MEASUREMENT',
long: '--measurement MEASUREMENT',
description: 'latency or throughput',
default: 'latency'
option :threshold,
short:'-T THRESHHOLD',
long: '--threshold THRESHOLD',
description: 'Value at which the system will warm',
default: '1000000'
# 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_cfstats
def get_metric(string) # rubocop:disable NestedMethodDefinition
string.strip!
(metric, value) = string.split(': ')
if metric.nil? || value.nil? # rubocop:disable Style/GuardClause
return [nil, nil]
else
# sanitize metric names for graphite
metric.gsub!(/[^a-zA-Z0-9]/, '_') # convert all other chars to _
metric.gsub!(/[_]*$/, '') # remove any _'s at end of the string
metric.gsub!(/[_]{2,}/, '_') # convert sequence of multiple _'s to single _
metric.downcase!
# sanitize metric values for graphite. Numbers only, please.
# some versions of nodetool omit the '.' following the 'ms' unit.
value = value.chomp(' ms.').chomp(' ms')
end
[metric, value]
end
cfstats = nodetool_cmd('cfstats')
metric = [config[:operation],config[:measurement]].join("_")
cfstats[0].each_line do |line|
result = get_metric(line)
if result[0] == metric and result[1].to_f >= config[:threshold].to_f
m = result.join(" ")
warning(m)
end
end
end
def run
parse_cfstats
ok
end
end