bin/metrics-nginx.rb in sensu-plugins-nginx-1.0.0 vs bin/metrics-nginx.rb in sensu-plugins-nginx-2.0.0
- old
+ new
@@ -56,10 +56,14 @@
short: '-q STATUSPATH',
long: '--statspath STATUSPATH',
description: 'Path to your stub status module',
default: 'nginx_status'
+ option :hostheader,
+ long: '--hostheader HOSTHEADER',
+ description: 'Set the Host header to this string'
+
option :scheme,
description: 'Metric naming scheme, text to prepend to metric',
short: '-s SCHEME',
long: '--scheme SCHEME',
default: "#{Socket.gethostname}.nginx"
@@ -77,10 +81,13 @@
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Get.new(uri.request_uri)
+ if config[:hostheader]
+ request['Host'] = config[:hostheader]
+ end
response = http.request(request)
if response.code == '200'
found = true
elsif !response.header['location'].nil?
config[:url] = response.header['location']
@@ -93,20 +100,20 @@
end
end
# #YELLOW
response.body.split(/\r?\n/).each do |line|
- if line.match(/^Active connections:\s+(\d+)/)
+ if line =~ /^Active connections:\s+(\d+)/
connections = line.match(/^Active connections:\s+(\d+)/).to_a
output "#{config[:scheme]}.active_connections", connections[1]
end
- if line.match(/^\s+(\d+)\s+(\d+)\s+(\d+)/)
+ if line =~ /^\s+(\d+)\s+(\d+)\s+(\d+)/
requests = line.match(/^\s+(\d+)\s+(\d+)\s+(\d+)/).to_a
output "#{config[:scheme]}.accepts", requests[1]
output "#{config[:scheme]}.handled", requests[2]
output "#{config[:scheme]}.requests", requests[3]
end
- if line.match(/^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/)
+ if line =~ /^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/
queue = line.match(/^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/).to_a
output "#{config[:scheme]}.reading", queue[1]
output "#{config[:scheme]}.writing", queue[2]
output "#{config[:scheme]}.waiting", queue[3]
end