Class: MuninManager::Plugins::HaproxyAppResponseTime
Instance Attribute Summary
Attributes inherited from LogReader
#file_name, #me, #state_dir, #state_file
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods inherited from LogReader
#collect!, #initialize, #load_saved_state, #save_state
Class Method Details
.help_text ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 80
def self.help_text
%Q{
#{plugin_name.capitalize} Munin Plugin
===========================
Please remember to add something like the lines below to /etc/munin/plugin-conf.d/munin-node
if the haproxy log file is not at /var/log/haproxy.log
[#{plugin_name}]
env.log_file /var/log/custom/haproxy.log
Also, make sure that the '/var/lib/munin/plugin-state' is writable by munin.
$ sudo chmod 777 /var/lib/munin/plugin-state
}
end
|
.run ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 66
def self.run
log_file = ENV['log_file'] || "/var/log/haproxy.log"
allowed_commands = ['config']
haproxy = new(log_file)
if cmd = ARGV[0] and allowed_commands.include? cmd then
puts haproxy.send(cmd.to_sym)
else
haproxy.collect!
puts haproxy.values
end
end
|
Instance Method Details
#config ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 35
def config
log_file = ENV['log_file'] || "/var/log/haproxy.log"
f = File.open(log_file)
count = 0
server_hash = {}
while(!f.eof? && count < 100)
count += 1
line = f.readline
chunks = line.split(/\s+/)
server, port = chunks[8].split(":") rescue []
server_name = server.split("/")[1] rescue nil
server_hash[server_name] = '' unless server_name.nil?
end
default = [:client_connect,:waiting_in_queue, :server_connect, :server_response, :rails_action, :total]
config_text = "graph_title HAProxy Response Breakdown\ngraph_vlabel time (secs)\ngraph_category Haproxy\n LABEL\n server_hash.keys.sort.each do |server|\n config_text << default.map{|k| \"\#{server}_\#{k}.label \#{server}_\#{k}\"}.join(\"\\n\")\n config_text << \"\\n\"\n end\n config_text\nend\n"
|
#data ⇒ Object
5
6
7
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 5
def data
@data ||= Hash.new {|h, k| h[k] = Hash.new{|d,v| d[v] = Array.new}}
end
|
#process! ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 26
def process!
data.each do |server, values|
values.each do |k, v|
values[k] = values[k].inject(0) {|sum, i| sum + i} / values[k].length rescue 0
values[k] = formatted(values[k] / 1000)
end
end
end
|
#scan(log_file) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 9
def scan(log_file)
loop do
line = log_file.readline
chunks = line.split(/\s+/)
server, port = chunks[8].split(":") rescue []
server_name = server.split("/")[1] rescue nil
next if server_name.nil?
timers = chunks[9].split("/") rescue []
data[server_name][:client_connect] << timers[0].to_f
data[server_name][:waiting_in_queue] << timers[1].to_f
data[server_name][:server_connect] << timers[2].to_f
data[server_name][:server_response] << timers[3].to_f
data[server_name][:rails_action] << line.match(/\{([0-9.]+)\}/).captures[0].to_f rescue 0
data[server_name][:total] << timers[4].to_f
end
end
|
#values ⇒ Object
62
63
64
|
# File 'lib/munin_manager/plugins/haproxy_app_response_time.rb', line 62
def values
data.inject([]){|datas, (server, values)| (datas + values.map{|k,v| "#{server}_#{k}.value #{v}"})}.join("\n")
end
|