undefined method []' for nil:NilClass (NoMethodError)

  • Thread starter thcerbla.netsrot
  • Start date
T

thcerbla.netsrot

Hi,

I have this script to monitor solr4 with munin.

But I get an error and I hove no idea what's the problem.

Hope someone can help me...


Thanks,

Torsten

Error:
/etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:60: undefined method []' for nil:NilClass (NoMethodError)
from /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:50:in each'
from /etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:50

Script:
#%# family=auto
#%# capabilities=autoconf

require 'open-uri'

SOLR_PORT = 8983
SOLR_HOST = "localhost"

target = __FILE__.split("_")[-1]

cores_url = "http://#{SOLR_HOST}:#{SOLR_PORT}/solr/admin/cores?action=STATUS&wt=ruby"

error = false
begin
cores = eval(open(cores_url).read)['status'].keys.sort
rescue
error = true
end

case ARGV[0]
when 'autoconf'
puts error ? "no" : "yes"
when 'config'
if target.end_with?("Cache")
puts "graph_title #{target} hitratio"
puts "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100"
puts "graph_vlabel %"
else
puts "graph_title #{target}"
puts "graph_args --base 1000"
puts "graph_vlabel Size #{target}"
end

puts "graph_category Solr"
puts "graph_info Info for cores: #{cores.join(",")}"

cores.each do |core|
puts "#{core}.label #{core}"
puts "#{core}.type GAUGE"
puts "#{core}.min 0"
end
else
cores.each do |core|
url = "http://#{SOLR_HOST}:#{SOLR_PORT}/solr/#{core}/admin/mbeans?stats=true&wt=ruby"
res = eval(open(url).read)

if target.end_with?('Cache')
cache = Hash[*res['solr-mbeans']]['CACHE']
hitratio = cache[target]['stats']['hitratio']
stat = (hitratio.to_f * 100).round
else
handler = Hash[*res['solr-mbeans']]["QUERYHANDLER"]
stat = handler['/select']['stats'][target]
end

puts "#{core}.value #{stat}"
end
end
 
C

Chris Angelico

I have this script to monitor solr4 with munin.

But I get an error and I hove no idea what's the problem.

Error:
/etc/munin/plugins/solr4_multicore_avgRequestsPerSecond:60: undefined method []' for nil:NilClass (NoMethodError)

cores_url = "http://#{SOLR_HOST}:#{SOLR_PORT}/solr/admin/cores?action=STATUS&wt=ruby"


Your first problem, I think, is that that's not Python code. My
crystal ball suggests it's probably Ruby.

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top