Class: MuninManager::Plugins::FbProxyLatency
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(options = {}) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 54
def self.help_text(options = {})
%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 rails log file is not at /var/log/rails.log
[#{options[:symlink] || plugin_name}]
env.log_file /var/log/custom/rails.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
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 40
def self.run
log_file = ENV['log_file'] || "/var/log/rails.log"
allowed_commands = ['config']
rails = new(log_file)
if cmd = ARGV[0] and allowed_commands.include? cmd then
puts rails.send(cmd.to_sym)
else
rails.collect!
puts rails.values
end
end
|
Instance Method Details
#config ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 26
def config
<<-LABEL
graph_title Facebook Proxy Latency
graph_vlabel latency
graph_category Facebook Proxy
queue.label queue_latency
fb_api.label fb_api_latency
LABEL
end
|
#data ⇒ Object
5
6
7
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 5
def data
@data ||= Hash.new {|h, k| h[k] = Array.new}
end
|
#process! ⇒ Object
20
21
22
23
24
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 20
def process!
data.each_pair do |component, response_times|
data[component] = response_times.inject(0.0) {|sum, i| sum + i} / data[component].length rescue 0
end
end
|
#scan(log_file) ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 9
def scan(log_file)
loop do
line = log_file.readline
next unless line.match(/^Benchmark /)
chunks = line.split(/-/).map{ |x| x.strip }
data_type = chunks[1] =~ /Queue/ ? 'queue' : 'fb_api'
next if chunks[2].nil?
data[data_type] << chunks[2].match('\((.*)\)')[1].to_f
end
end
|
#values ⇒ Object
36
37
38
|
# File 'lib/munin_manager/plugins/fbproxy_latency.rb', line 36
def values
data.map {|k, v| "#{format_for_munin(k)}.value #{"%.10f" % v}"}.join("\n")
end
|