Class: MuninManager::Plugins::RailsRendering
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 58
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
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 44
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
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 28
def config
<<-LABEL
graph_title Rails Response Breakdown
graph_vlabel response time
graph_category Rails
total.label total
rendering.label rendering
db.label db
memcache.label memcache
LABEL
end
|
#data ⇒ Object
5
6
7
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 5
def data
@data ||= Hash.new {|h, k| h[k] = Array.new}
end
|
#process! ⇒ Object
22
23
24
25
26
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 22
def process!
data.each_pair do |component, response_times|
data[component] = response_times.inject(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
19
20
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 9
def scan(log_file)
loop do
line = log_file.readline
next unless line.match(/^Completed in/)
chunks = line.split(/\s/)
data[:total] << chunks[2].to_f
data[:rendering] << chunks[7].to_f
data[:memcache] << chunks[11].to_f
data[:db] << chunks[14].to_f
end
end
|
#values ⇒ Object
40
41
42
|
# File 'lib/munin_manager/plugins/rails_rendering.rb', line 40
def values
data.map {|k, v| "#{format_for_munin(k)}.value #{"%.10f" % v}"}.join("\n")
end
|