HAYASHI Kentaro
null+****@clear*****
Wed Dec 25 10:27:46 JST 2013
HAYASHI Kentaro 2013-12-25 10:27:46 +0900 (Wed, 25 Dec 2013) New Revision: 8cd9f34baf1b977d7bba2b53f9de40d810b8af15 https://github.com/groonga/groonga/commit/8cd9f34baf1b977d7bba2b53f9de40d810b8af15 Message: Revert "minin: fix port number configuration" This reverts commit 5c8f9018a6004b222255776384e5aacb24485180. Revert "munin: support not only GQTP but also HTTP" This reverts commit 8df51f8f3941628609f4b0dfc7abcb1e528844e2. It should be unified duplicated code for maintainability. I'll fix this issue again. Removed files: data/munin/groonga_http_cpu_load data/munin/groonga_http_cpu_time data/munin/groonga_http_disk data/munin/groonga_http_memory data/munin/groonga_http_n_records data/munin/groonga_http_query_performance data/munin/groonga_http_status data/munin/groonga_http_throughput Modified files: data/munin/Makefile.am packages/debian/groonga-munin-plugin.conf Renamed files: data/munin/groonga_cpu_load (from data/munin/groonga_gqtp_cpu_load) data/munin/groonga_cpu_time (from data/munin/groonga_gqtp_cpu_time) data/munin/groonga_disk (from data/munin/groonga_gqtp_disk) data/munin/groonga_memory (from data/munin/groonga_gqtp_memory) data/munin/groonga_n_records (from data/munin/groonga_gqtp_n_records) data/munin/groonga_query_performance (from data/munin/groonga_gqtp_query_performance) data/munin/groonga_status (from data/munin/groonga_gqtp_status) data/munin/groonga_throughput (from data/munin/groonga_gqtp_throughput) Modified: data/munin/Makefile.am (+8 -16) =================================================================== --- data/munin/Makefile.am 2013-12-24 23:39:18 +0900 (3ca9c3f) +++ data/munin/Makefile.am 2013-12-25 10:27:46 +0900 (8fb5382) @@ -1,20 +1,12 @@ if INSTALL_MUNIN_PLUGINS munin_pluginsdir = $(datarootdir)/$(PACKAGE)/munin/plugins dist_munin_plugins_SCRIPTS = \ - groonga_gqtp_cpu_load \ - groonga_gqtp_cpu_time \ - groonga_gqtp_status \ - groonga_gqtp_memory \ - groonga_gqtp_n_records \ - groonga_gqtp_query_performance \ - groonga_gqtp_disk \ - groonga_gqtp_throughput \ - groonga_http_cpu_load \ - groonga_http_cpu_time \ - groonga_http_status \ - groonga_http_memory \ - groonga_http_n_records \ - groonga_http_query_performance \ - groonga_http_disk \ - groonga_http_throughput + groonga_cpu_load \ + groonga_cpu_time \ + groonga_status \ + groonga_memory \ + groonga_n_records \ + groonga_query_performance \ + groonga_disk \ + groonga_throughput endif Renamed: data/munin/groonga_cpu_load (+0 -0) 100% =================================================================== Renamed: data/munin/groonga_cpu_time (+0 -0) 100% =================================================================== Renamed: data/munin/groonga_disk (+0 -0) 100% =================================================================== Deleted: data/munin/groonga_http_cpu_load (+0 -47) 100755 =================================================================== --- data/munin/groonga_http_cpu_load 2013-12-24 23:39:18 +0900 (7e8a017) +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh - -#%# family=auto -#%# capabilities=autoconf - -case "$1" in - autoconf|detect) - if [ -z "${pid_file}" ]; then - echo "no (PID file isn't specified by env.pid_file)" - exit 1 - elif [ -f "${pid_file}" ]; then - echo "yes" - exit 0 - else - echo "no (PID file doesn't exist: ${pid_file})" - exit 1 - fi - ;; - config) - if [ -z "${label}" ]; then - title="groonga: CPU load" - else - title="groonga: ${label}: CPU load" - fi - cat <<EOF -graph_title ${title} -graph_vlabel CPU load (%) -graph_category groonga -graph_info groonga CPU load - -cpu_load.label CPU load -cpu_load.type GAUGE -EOF - exit 0 - ;; - *) -esac - -if [ -z "${pid_file}" ]; then - echo "PID file isn't specified by env.pid_file" - exit 1 -fi - -groonga_pid=$(cat ${pid_file}) -top_for_groonga=$(top -b -n 1 -p ${groonga_pid} | grep ${groonga_pid}) -load_in_percent=$(echo ${top_for_groonga} | sed -r -e 's/ +/ /g' | cut -d' ' -f 9) -echo "cpu_load.value ${load_in_percent}" Deleted: data/munin/groonga_http_cpu_time (+0 -57) 100755 =================================================================== --- data/munin/groonga_http_cpu_time 2013-12-24 23:39:18 +0900 (f6d68ee) +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env ruby - -#%# family=auto -#%# capabilities=autoconf - -label = ENV["label"] -pid_file = ENV["pid_file"] - -command = ARGV.shift - -case command -when "autoconf", "detect" - if pid_file.nil? - puts "no (PID file isn't specified by env.pid_file)" - exit(false) - elsif File.exist?(pid_file) - puts "yes" - exit(true) - else - puts "no (PID file doesn't exist: #{pid_file})" - exit(false) - end -when "config" - if label - title = "groonga: #{label}: CPU time" - else - title = "groonga: CPU time" - end - puts <<EOF -graph_title #{title} -graph_vlabel CPU time (days) -graph_category groonga -graph_info groonga CPU time - -cpu_time.label CPU time -cpu_time.type GAUGE -EOF - exit(true) -end - -groonga_pid = File.read(pid_file).strip -time = `ps h -o time -p #{groonga_pid}`.chomp -if /\A(?:(\d+)-)?(\d+):(\d+):(\d+)\z/ =~ time - day, hours, minutes, seconds, = $1, $2, $3, $4 - day = (day || 0).to_i - hours = hours.to_i - minutes = minutes.to_i - seconds = seconds.to_i - time_in_seconds = seconds + minutes * 60 + hours * 60 * 60 - day_in_seconds = 60 * 60 * 24 - fraction_in_day = time_in_seconds.to_f / day_in_seconds.to_f - cpu_time_in_day = day + fraction_in_day - puts "cpu_time.value #{cpu_time_in_day}" -else - puts "invalid time format: <#{time}>" - exit(false) -end Deleted: data/munin/groonga_http_disk (+0 -176) 100755 =================================================================== --- data/munin/groonga_http_disk 2013-12-24 23:39:18 +0900 (8fec0be) +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/env ruby - -#%# family=auto -#%# capabilities=autoconf - -require 'shellwords' -begin - require 'json' -rescue LoadError - require 'rubygems' - require 'json' -end -require 'English' - -label = ENV["label"] - �� groonga = ENV["groonga"] || "groonga" - �� du = ENV["du"] || "du" - �� path = ENV["path"] - -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) - path = Shellwords.shellescape(@path) - result = `#{@groonga} #{path} #{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 - -def schema - tables = [] - success, table_list_body = run("table_list") - unless success - puts "error: #{table_list_body}" - exit(false) - end - parse_list(table_list_body[0], table_list_body[1..-1]).each do |table| - table_name = table["name"] - table["key"] = "table_#{table_name}" - success, column_list_body = run("column_list", table_name) - unless success - puts "error: #{column_list_body}" - exit(false) - end - table["columns"] = parse_list(column_list_body[0], column_list_body[1..-1]) - table["columns"].each do |column| - column["key"] = "column_#{table_name}_#{column['name']}" - column["full_name"] = "#{table_name}.#{column['name']}" - end - tables << table - end - tables -end - -def parse_du_result(result) - usages = {} - result.each_line do |line| - if /\A(\d+)\s+/ =~ line - usage = $1 - path = $POSTMATCH.strip - usages[path] = usage.to_i - end - end - usages -end - -def compute_size(usages, base_path) - usage = 0 - return usage if base_path.empty? - - usages.each do |path, size| - usage += size if path.start_with?(base_path) - end - usage -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: disk usage" - else - title = "groonga: #{label}: disk usage" - end - puts <<EOF -graph_title #{title} -graph_vlabel Bytes -graph_category groonga -graph_info disk usage in groonga tables and columns -graph_args --base 1024 -graph_total Total - -database.label Database -database.draw AREA -EOF - schema.each do |table| - table_key = table["key"] - table_name = table["name"] - puts <<EOF - -#{table_key}.label #{table_name} -#{table_key}.draw STACK -EOF - table["columns"].each do |column| - column_key = column["key"] - column_name = column["full_name"] - puts <<EOF - -#{column_key}.label #{column_name} -#{column_key}.draw STACK -EOF - end - end - exit(true) -end - -path = Shellwords.shellescape(@path) -du_result = `#{@du} -B1 #{path}*` -unless $?.success? - puts("error: #{du_result}") - exit(false) -end -usages = parse_du_result(du_result) -usage = compute_size(usages, @path) -puts <<EOF -database.value #{usage} -EOF -schema.each do |table| - table_key = table["key"] - table_name = table["name"] - usage = compute_size(usages, table["path"]) - puts <<EOF -#{table_key}.value #{usage} -EOF - table["columns"].each do |column| - column_key = column["key"] - usage = compute_size(usages, column["path"]) - puts <<EOF -#{column_key}.value #{usage} -EOF - end -end Deleted: data/munin/groonga_http_memory (+0 -51) 100755 =================================================================== --- data/munin/groonga_http_memory 2013-12-24 23:39:18 +0900 (30928ce) +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -#%# family=auto -#%# capabilities=autoconf - -case "$1" in - autoconf|detect) - if [ -z "${pid_file}" ]; then - echo "no (PID file isn't specified by env.pid_file)" - exit 1 - elif [ -f "${pid_file}" ]; then - echo "yes" - exit 0 - else - echo "no (PID file doesn't exist: ${pid_file})" - exit 1 - fi - ;; - config) - if [ -z "${label}" ]; then - title="groonga: memory usage" - else - title="groonga: ${label}: memory usage" - fi - cat <<EOF -graph_title ${title} -graph_vlabel memory usage -graph_category groonga -graph_info groonga memory usage - -rss.label resident set size -rss.type GAUGE -vsz.label virtual memory size -vsz.type GAUGE -EOF - exit 0 - ;; - *) -esac - -if [ -z "${pid_file}" ]; then - echo "PID file isn't specified by env.pid_file" - exit 1 -fi - -groonga_pid=$(cat ${pid_file}) -read rss_in_kb vsz_in_kb <<EOC -$(ps h -o rss,vsz -p ${groonga_pid}) -EOC -echo "rss.value ${rss_in_kb}000" -echo "vsz.value ${vsz_in_kb}000" Deleted: data/munin/groonga_http_n_records (+0 -113) 100755 =================================================================== --- data/munin/groonga_http_n_records 2013-12-24 23:39:18 +0900 (d4a6aea) +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env ruby - -#%# family=auto -#%# capabilities=autoconf - -require 'shellwords' -begin - require 'json' -rescue LoadError - require 'rubygems' - require 'json' -end - -label = ENV["label"] - �� groonga = ENV["groonga"] || "groonga" - �� host = ENV["host"] || "localhost" - �� port = ENV["port"] || 10041 - �� path = ENV["path"] - �� exclude_tables = (ENV["exclude_tables"] || "").split(/\s*,\s*/) - -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) - result = `curl -s "http://#{@host}:#{@port}/d/#{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 - -def table_list - success, body = run("table_list") - unless success - puts "error: #{body}" - exit(false) - end - tables = parse_list(body[0], body[1..-1]) - tables.reject do |table| - name = table["name"] - @exclude_tables.include?(name) - 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: number of records" - else - title = "groonga: #{label}: number of records" - end - puts <<EOF -graph_title #{title} -graph_vlabel records -graph_category groonga -graph_info number of records in groonga table -EOF - table_list.each do |table| - name = table["name"] - puts <<EOF - -#{name}.label #{name} -#{name}.type GAUGE -EOF - end - exit(true) -end - -table_list.each do |table| - name = table["name"] - success, body = run("select", "table=#{name}", "limit=0") - unless success - puts("error: #{body}") - exit(false) - end - n_records = body[0][0][0] - puts <<EOF -#{name}.value #{n_records} -EOF -end Deleted: data/munin/groonga_http_query_performance (+0 -133) 100755 =================================================================== --- data/munin/groonga_http_query_performance 2013-12-24 23:39:18 +0900 (8081d02) +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env ruby - -#%# family=auto -#%# capabilities=autoconf - -require 'English' -require 'strscan' - -label = ENV["label"] - - �� log_path = ENV["log_path"] - -command = ARGV.shift - -case command -when "autoconf", "detect" - if @log_path.nil? - puts "no (query log file path isn't specified by env.log_path)" - exit(false) - end - unless File.readable?(@log_path) - puts "no (query log file isn't readable: <#{@log_path}>)" - exit(false) - end - puts "yes" - exit(true) -when "config" - if label.nil? - title = "groonga: query performance" - else - title = "groonga: #{label}: query performance" - end - puts <<EOF -graph_title #{title} -graph_vlabel seconds -graph_category groonga -graph_info groonga query performance - -longest.label Longest -average.label Average -median.label Median -EOF - exit(true) -end - -class ReverseLineReader - def initialize(io) - @io = io - @io.seek(0, IO::SEEK_END) - @buffer = "" - @data = "" - end - - def each - separator = $/ - separator_length = separator.length - while read_to_buffer - loop do - index =****@buffe*****(separator, @buffer.length - 1 - separator_length) - break if index.nil? or index.zero? - last_line =****@buffe*****!((index + separator_length)..-1) - yield(last_line) - end - end - yield(@buffer) unles****@buffe*****? - end - - private - BYTES_PER_READ = 4096 - def read - position =****@io***** - if position < BYTES_PER_READ - bytes_per_read = position - else - bytes_per_read = BYTES_PER_READ - end - - if bytes_per_read.zero? - @data.replace("") - else - @io.seek(-bytes_per_read, IO::SEEK_CUR) - @io.read(bytes_per_read, @data) - @io.seek(-bytes_per_read, IO::SEEK_CUR) - end - - @data - end - - def read_to_buffer - data = read - if data.empty? - false - else - @buffer.insert(0, data) - true - end - end -end - -span = 60 * 5 # 5min -mega = 1_000_000.0 -now = Time.now -elapsed_times = [] -File.open(@log_path) do |log_file| - ReverseLineReader.new(log_file).each do |line| - case line - when /\A(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)\.(\d+)\|([\da-f])+\|<(\d+) rc=0$/ - _, year, month, day, hour, minutes, seconds, milliseconds, - context, elapsed = $LAST_MATCH_INFO.to_a - time_stamp = Time.local(year, month, day, - hour, minutes, seconds, milliseconds) - difference = now - time_stamp - break if difference > span - elapsed_in_micro_seconds = elapsed.to_i / mega - elapsed_times << elapsed_in_micro_seconds - end - end -end - -sorted_elapsed_times = elapsed_times.sort -if sorted_elapsed_times.empty? - longest = 0 - average = 0 - median = 0 -else - longest = sorted_elapsed_times.last - average = sorted_elapsed_times.inject(&:+) / sorted_elapsed_times.size.to_f - median = sorted_elapsed_times[sorted_elapsed_times.size / 2] -end - -puts "longest.value #{longest}" -puts "average.value #{average}" -puts "median.value #{median}" Deleted: data/munin/groonga_http_status (+0 -88) 100755 =================================================================== --- data/munin/groonga_http_status 2013-12-24 23:39:18 +0900 (7c0eee4) +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env ruby - -#%# family=auto -#%# capabilities=autoconf - -begin - require 'json' -rescue LoadError - require 'rubygems' - require 'json' -end - -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) - result = `curl -s "http://#{@host}:#{@port}/d/#{command}" 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 Deleted: data/munin/groonga_http_throughput (+0 -108) 100755 =================================================================== --- data/munin/groonga_http_throughput 2013-12-24 23:39:18 +0900 (6353c16) +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env ruby - -#%# family=auto -#%# capabilities=autoconf - -begin - require 'json' -rescue LoadError - require 'rubygems' - require 'json' -end - -label = ENV["label"] - �� groonga = ENV["groonga"] || "groonga" - �� host = ENV["host"] || "localhost" - �� port = ENV["port"] || 10041 - �� protocol = ENV["protocol"] || "http" - -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) - if @protocol == "http" - require "net/http" - begin - response = Net::HTTP.start(@host, @port) do |http| - http.get("/d/status.json") - end - if response.is_a?(Net::HTTPSuccess) - parse(true, response.body) - else - parse(false, "#{response.code}: #{response.body}") - end - rescue Exception - message = "#{$!.class}: #{$!.message}\n" - message << $@.join("\n") - parse(false, message) - end - else - groonga = "#{@groonga} -p #{@port} -c #{@host}" - result = `#{groonga} #{command} #{args.join(' ')} 2>&1` - parse($?.success?, result) - end -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: throughput" - else - title = "groonga: #{label}: throughput" - end - puts <<EOF -graph_title #{title} -graph_vlabel queries per ${graph_period} -graph_category groonga -graph_info groonga throughput - -n_queries.label N queries -n_queries.type COUNTER -EOF - exit(true) -end - -success, body = run("status") -unless success - puts("error: #{body}") - exit(false) -end -puts <<EOF -n_queries.value #{body["n_queries"]} -EOF Renamed: data/munin/groonga_memory (+0 -0) 100% =================================================================== Renamed: data/munin/groonga_n_records (+1 -1) 98% =================================================================== --- data/munin/groonga_gqtp_n_records 2013-12-24 23:39:18 +0900 (bd8ce79) +++ data/munin/groonga_n_records 2013-12-25 10:27:46 +0900 (eb64f54) @@ -14,7 +14,7 @@ end label = ENV["label"] @groonga = ENV["groonga"] || "groonga" @host = ENV["host"] || "localhost" - �� port = ENV["port"] || 10043 + �� port = ENV["port"] || 10041 @path = ENV["path"] @exclude_tables = (ENV["exclude_tables"] || "").split(/\s*,\s*/) Renamed: data/munin/groonga_query_performance (+0 -0) 100% =================================================================== Renamed: data/munin/groonga_status (+1 -1) 98% =================================================================== --- data/munin/groonga_gqtp_status 2013-12-24 23:39:18 +0900 (c520822) +++ data/munin/groonga_status 2013-12-25 10:27:46 +0900 (1a7bb11) @@ -13,7 +13,7 @@ end label = ENV["label"] @groonga = ENV["groonga"] || "groonga" @host = ENV["host"] || "localhost" - �� port = ENV["port"] || 10043 + �� port = ENV["port"] || 10041 command = ARGV.shift Renamed: data/munin/groonga_throughput (+1 -1) 98% =================================================================== --- data/munin/groonga_gqtp_throughput 2013-12-24 23:39:18 +0900 (f75b066) +++ data/munin/groonga_throughput 2013-12-25 10:27:46 +0900 (5efb8ad) @@ -13,7 +13,7 @@ end label = ENV["label"] @groonga = ENV["groonga"] || "groonga" @host = ENV["host"] || "localhost" - �� port = ENV["port"] || 10043 + �� port = ENV["port"] || 10041 @protocol = ENV["protocol"] || "gqtp" command = ARGV.shift Modified: packages/debian/groonga-munin-plugin.conf (+2 -10) =================================================================== --- packages/debian/groonga-munin-plugin.conf 2013-12-24 23:39:18 +0900 (a477f81) +++ packages/debian/groonga-munin-plugin.conf 2013-12-25 10:27:46 +0900 (f71b8a1) @@ -2,16 +2,8 @@ user groonga group groonga env.PATH /usr/bin:/bin:/usr/local/bin + env.pid_file /var/run/groonga/groonga.pid env.path /var/lib/groonga/db/db env.host 127.0.0.1 - -[groonga_http_*] - env.port 10041 - env.pid_file /var/run/groonga/groonga-http.pid - env.log_path /var/log/groonga/query-http.log - -[groonga_gqtp_*] env.port 10043 - env.pid_file /var/run/groonga/groonga-gqtp.pid - env.log_path /var/log/groonga/query-gqtp.log - + env.log_path /var/log/groonga/query.log -------------- next part -------------- HTML����������������������������...ダウンロード