bin/metrics-solr-graphite.rb in sensu-plugins-solr-0.0.3 vs bin/metrics-solr-graphite.rb in sensu-plugins-solr-1.0.0
- old
+ new
@@ -40,11 +40,11 @@
description: 'Metric naming scheme, text to prepend to metric',
short: '-s SCHEME',
long: '--scheme SCHEME',
default: "#{Socket.gethostname}.solr"
- def run # rubocop:disable all
+ def run # rubocop:disable Metrics/AbcSize
cores = []
if config[:core]
cores = [config[:core]]
else
# If no core is specified, provide statistics for all cores
@@ -53,27 +53,27 @@
status = JSON.parse(status_resp.body)
cores = status['status'].keys
end
cores.each do |core|
- if config[:core]
- # Don't include core name in scheme to match previous functionality
- graphitepath = config[:scheme]
- else
- graphitepath = "#{config[:scheme]}.#{core}"
- end
+ graphitepath = if config[:core]
+ # Don't include core name in scheme to match previous functionality
+ config[:scheme]
+ else
+ "#{config[:scheme]}.#{core}"
+ end
ping_url = "http://#{config[:host]}:#{config[:port]}/solr/#{core}/admin/ping?wt=json"
resp = Net::HTTP.get_response(URI.parse(ping_url))
ping = JSON.parse(resp.body)
output "#{graphitepath}.solr.QueryTime", ping['responseHeader']['QTime']
output "#{graphitepath}.solr.Status", ping['responseHeader']['status']
stats_url = "http://#{config[:host]}:#{config[:port]}/solr/#{core}/admin/stats.jsp"
- xml_data = Net::HTTP.get_response(URI.parse(stats_url)).body.gsub("\n", '')
- stats = Crack::XML.parse(xml_data)
+ xml_data = Net::HTTP.get_response(URI.parse(stats_url)).body.delete("\n")
+ stats = Crack::XML.parse(xml_data)
# this xml is an ugly beast.
core_searcher = stats['solr']['solr_info']['CORE']['entry'].find { |v| v['name'].strip! == 'searcher' }['stats']['stat']
standard = stats['solr']['solr_info']['QUERYHANDLER']['entry'].find { |v| v['name'].strip! == 'standard' }['stats']['stat']
update = stats['solr']['solr_info']['QUERYHANDLER']['entry'].find { |v| v['name'] == '/update' }['stats']['stat']