Sha256: f95027930e141c20cd4235fbbfc143721d261fc0fe6a18030dbaf909e14c2d56

Contents?: true

Size: 1.51 KB

Versions: 6

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby

#%# family=auto
#%# capabilities=autoconf

require 'json'

label = ENV["label"]
@groonga = ENV["groonga"] || "groonga"
@host = ENV["host"] || "localhost"
@port = ENV["port"] || 10041

command = ARGV.shift

def parse(success, result)
  if success
    begin
      status, body = JSON.parse(result)
      return_code, start_time, elapsed, error_message = status
      if return_code.zero?
        [success, body]
      else
        [false, error_message]
      end
    rescue JSON::ParserError
      [false, $!.message]
    end
  else
    [success, result]
  end
end

def run(command, *args)
  groonga = "#{@groonga} -p #{@port} -c #{@host}"
  result = `#{groonga} #{command} #{args.join(' ')} 2>&1`
  parse($?.success?, result)
end

def parse_list(header, list)
  list.collect do |item|
    parsed_item = {}
    header.each_with_index do |(name, type), i|
      parsed_item[name] = item[i]
    end
    parsed_item
  end
end

case command
when "autoconf", "detect"
  success, body = run("status")
  if success
    puts "yes"
    exit(true)
  else
    puts "no (#{body})"
    exit(false)
  end
when "config"
  if label.nil?
    title = "groonga: status"
  else
    title = "groonga: #{label}: status"
  end
  puts <<EOF
graph_title #{title}
graph_vlabel status
graph_category groonga
graph_info groonga status

alloc_count.label alloc count
alloc_count.type GAUGE
EOF
  exit(true)
end

success, body = run("status")
unless success
  puts("error: #{body}")
  exit(false)
end
puts <<EOF
alloc_count.value #{body["alloc_count"]}
EOF

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rroonga-1.2.7-x86-mswin32 vendor/local/share/groonga/munin/plugins/groonga_status
rroonga-1.2.7-x86-mingw32 vendor/local/share/groonga/munin/plugins/groonga_status
rroonga-1.2.5-x86-mingw32 vendor/local/share/groonga/munin/plugins/groonga_status
rroonga-1.1.0-x86-mingw32 vendor/local/share/groonga/munin/plugins/groonga_status
rroonga-1.0.1-x86-mingw32 vendor/local/share/groonga/munin/plugins/groonga_status
rroonga-0.9.5-x86-mingw32 vendor/local/share/groonga/munin/plugins/groonga_status