forked from jamesgolick/fetlife-nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cassandra
executable file
·37 lines (32 loc) · 916 Bytes
/
check_cassandra
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
require "rubygems"
require "cassandra"
require "optparse"
require "benchmark"
options = {}
required = [:host, :keyspace]
parser = OptionParser.new do |opts|
opts.banner = "Usage: check_cassandra [options]"
opts.on("-h", "--host cassandrahost:port", "The hostname and port of the cassandra server.") do |h|
options[:host] = h
end
opts.on("-k", "--keyspace keyspace", "The keyspace to connect to.") do |k|
options[:keyspace] = k
end
opts.on("-cf", "--columnfamily cf", "The column family to query.") do |cf|
options[:cf] = cf
end
end
parser.parse!
if !required.all? { |k| options.has_key?(k) }
abort parser.to_s
else
begin
cassandra = Cassandra.new(options[:keyspace], options[:host])
b = Benchmark.measure { cassandra.get(options[:cf], "a") }
puts "OK - #{b.real}"
rescue StandardError => e
puts "CRITICAL - #{e.to_s}"
exit(2)
end
end