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

thcerbla.netsrot at googlemail.com thcerbla.netsrot at googlemail.com
Mon Aug 5 18:24:04 EDT 2013


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



More information about the Python-list mailing list