[#409331] Capture HTML table data, pass to Ruby, pass back and display result in HTML text field — Hubert Wagner <lists@...>

Hello :

11 messages 2013/08/04

[#409336] Rakefile Error - Please Help — "Jennifer T." <lists@...>

Hi,

13 messages 2013/08/04
[#409341] Re: Rakefile Error - Please Help — Hassan Schroeder <hassan.schroeder@...> 2013/08/04

On Sun, Aug 4, 2013 at 7:41 AM, Jennifer T. <lists@ruby-forum.com> wrote:

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

From: Torsten Albrecht <lists@...>
Date: 2013-08-06 06:10:53 UTC
List: ruby-talk #404592
Hi,

I have this script to monitor solr4 with munin.

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

Hope some one here 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

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
ruby-talk mailing list
ruby-talk@ruby-lang.org
http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-talk

In This Thread

Prev Next