38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/newrelic_haproxy_agent.rb', line 38
def poll_cycle
if uri.nil?
raise("URI to HAProxy Stats Required It looks like the URI to the HAProxy stats page (in csv format) hasn't been provided. Please enter this URI in the plugin settings.")
end
if proxy_type
if proxy_type =~ /frontend|backend/i
@proxy_type = proxy_type.upcase
end
end
found_proxies = []
possible_proxies = []
begin
FasterCSV.parse(open(uri, :http_basic_authentication => [user, password]), :headers => true) do |row|
next if proxy_type and proxy_type != row["svname"] possible_proxies << row["# pxname"] next unless proxy.to_s.strip.downcase == row["# pxname"].downcase if found_proxies.include?(row["# pxname"])
raise("Multiple proxies have the name '#{proxy}'. Please specify the proxy type (ex: BACKEND or FRONTEND) in the plugin's settings.")
end
found_proxies << row["# pxname"]
report_metric "Requests", "Requests/Minute", (@requests.process(row['stot'].to_i) || 0) * 60
report_metric "Errors/Request", "Errors/Minute", (@errors_req.process(row['ereq'].to_i) || 0) * 60
report_metric "Errors/Connection", "Errors/Minute", (@errors_conn.process(row['econ'].to_i) || 0) * 60
report_metric "Errors/Response", "Errors/Minute", (@errors_resp.process(row['eresp'].to_i) || 0) * 60
report_metric "Bytes/Received", "Bytes/Seconds", @bytes_in.process(row['bin'].to_i)
report_metric "Bytes/Sent", "Bytes/Seconds", @bytes_out.process(row['bout'].to_i)
report_metric "Sessions/Active", "Sessions", row['scur']
report_metric "Sessions/Queued", "Sessions", row['qcur']
report_metric "Servers/Active", "Servers", row['act']
report_metric "Servers/Backup", "Servers", row['bck']
report_metric "ProxyUp", "Status", %w(UP OPEN).find {|s| s == row['status']} ? 1 : 0
end rescue OpenURI::HTTPError
if $!.message == '401 Unauthorized'
raise("Authentication Failed. Unable to access the stats page at #{uri} with the username '#{user}' and provided password. Please ensure the username, password, and URI are correct.")
elsif $!.message != '404 Not Found'
raise("Unable to find the stats page. The stats page could not be found at: #{uri}.")
else
raise
end
rescue FasterCSV::MalformedCSVError
raise("Unable to access stats page. The plugin encountered an error attempting to access the stats page (in CSV format) at: #{uri}. The exception: #{$!.message}\n#{$!.backtrace}")
end
if proxy.nil?
raise("Proxy name required. The name of the proxy to monitor must be provided in the plugin settings. The possible proxies to monitor: #{possible_proxies.join(', ')}")
elsif found_proxies.empty?
raise("Proxy not found. The proxy '#{proxy}' #{proxy_type ? "w/proxy type [#{proxy_type}]" : nil} was not found. The possible proxies #{proxy_type ? "for this proxy type" : nil} to monitor: #{possible_proxies.join(', ')}")
end
end
|