Skip to content

Instantly share code, notes, and snippets.

@mikeda
Last active December 20, 2015 06:29
Show Gist options
  • Select an option

  • Save mikeda/6086578 to your computer and use it in GitHub Desktop.

Select an option

Save mikeda/6086578 to your computer and use it in GitHub Desktop.
マルチコアのSolrの各種グラフを作成するmuninプラグインのとりあえず版
#!/usr/local/bin/ruby
# とりあえずこのへんをグラフ化
# ●インデックス
# numDocs
# サイズ
#
# ●検索クエリ
# 総リクエスト(QPS)
# エラー(QPS)
# タイムアウト(QPS)
# 総実行時間(5分間の合計ms)
#
# ●キャッシュ(filterCache、fieldValueCache、queryResultCache、documentCacheのそれぞれについて)
# lookup数(count/sec)
# ヒット数(count/sec)
# キャッシュあふれ(count/sec)
require 'net/http'
require 'json'
require 'pp'
HOST='127.0.0.1'
PORT=8080
PATH_PREFIX='/solr'
STANDARDS = %w(requests errors timeouts totalTime)
CACHES = %w(filterCache fieldValueCache queryResultCache documentCache)
GRAPH_CONFIG = {
'index' => {
'numDocs' => {
graph_title: 'numDocs',
graph_vlabel: 'docs',
type: 'GAUGE'
},
'sizeInBytes' => {
graph_title: 'Index Size',
graph_vlabel: 'byte',
type: 'GAUGE'
}
},
'standard' => {
'requests' => {
graph_title: 'Search Queries',
graph_vlabel: 'qps',
type: 'COUNTER'
},
'errors' => {
graph_title: 'Search Queriy Errors',
graph_vlabel: 'qps',
type: 'COUNTER'
},
'timeouts' => {
graph_title: 'Search Queriy TimeOuts',
graph_vlabel: 'qps',
type: 'COUNTER'
},
'totalTime' => {
graph_title: 'Search Query totalTime',
graph_vlabel: 'msec / 5min',
type: 'COUNTER'
}
},
'cache' => {
'lookups' => {
graph_vlabel: 'count / sec',
type: 'COUNTER'
},
'hits' => {
graph_vlabel: 'count / sec',
type: 'COUNTER'
},
'evictions' => {
graph_vlabel: 'count / sec',
type: 'COUNTER'
}
}
}
def http_get(host, port, path)
json = ''
Net::HTTP.start(host, port) do |http|
res = http.get(path)
json = res.body
end
JSON.parse(json)
end
cores = http_get(HOST, PORT, "#{PATH_PREFIX}/admin/cores?action=STATUS&wt=json")
CORE_NAMES = cores['status'].keys.sort
def print_config
GRAPH_CONFIG['index'].each do |key, config|
puts "multigraph solr_index_#{key}"
puts "graph_title #{config[:graph_title]}"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel #{config[:graph_vlabel]}"
puts "graph_category solr"
CORE_NAMES.each do |core|
puts "#{core}.label #{core}"
puts "#{core}.type #{config[:type]}"
end
puts ""
end
GRAPH_CONFIG['standard'].each do |key, config|
puts "multigraph solr_standard_#{key}"
puts "graph_title #{config[:graph_title]}"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel #{config[:graph_vlabel]}"
puts "graph_category solr"
CORE_NAMES.each do |core|
puts "#{core}.label #{core}"
puts "#{core}.type #{config[:type]}"
end
puts ""
end
CACHES.each do |cache|
GRAPH_CONFIG['cache'].each do |key, config|
puts "multigraph solr_cache_#{cache}_#{key}"
puts "graph_title #{cache} #{key}"
puts "graph_args --base 1000 -l 0"
puts "graph_vlabel #{config[:graph_vlabel]}"
puts "graph_category solr"
CORE_NAMES.each do |core|
puts "#{core}.label #{core}"
puts "#{core}.type #{config[:type]}"
end
puts ""
end
end
end
if ARGV.shift == 'config'
print_config
exit 0
end
results = {
'index' => {},
'standard' => {},
'cache' => {},
}
CORE_NAMES.each do |core_name|
GRAPH_CONFIG['index'].keys.each do |key|
results['index'][key] ||= {}
results['index'][key][core_name] = cores['status'][core_name]['index'][key]
end
res = http_get(HOST, PORT, "#{PATH_PREFIX}/#{core_name}/admin/mbeans?stats=true&wt=json")
hash = Hash[*res['solr-mbeans']]
standard = hash['QUERYHANDLER']['standard']
GRAPH_CONFIG['standard'].keys.each do |key|
results['standard'][key] ||= {}
results['standard'][key][core_name] = standard['stats'][key]
end
results['standard']['totalTime'][core_name] = results['standard']['totalTime'][core_name].to_i
cache_result = hash['CACHE']
CACHES.each do |cache|
results['cache'][cache] ||= {}
GRAPH_CONFIG['cache'].keys.each do |key|
results['cache'][cache][key] ||= {}
results['cache'][cache][key][core_name] = cache_result[cache]['stats']["cumulative_#{key}"]
end
end
end
#pp results
results['index'].each do |key, result|
puts "multigraph solr_index_#{key}"
result.each do |core, val|
puts "#{core}.value #{val}"
end
puts ""
end
results['standard'].each do |key, result|
puts "multigraph solr_standard_#{key}"
result.each do |core, val|
puts "#{core}.value #{val}"
end
puts ""
end
results['cache'].each do |cache, cache_results|
cache_results.each do |key, result|
puts "multigraph solr_cache_#{cache}_#{key}"
result.each do |core, val|
puts "#{core}.value #{val}"
end
puts ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment