Class: Munin::RequestLogAnalyzerPlugin
- Inherits:
-
Object
- Object
- Munin::RequestLogAnalyzerPlugin
show all
- Defined in:
- lib/munin/request_log_analyzer_plugin.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RequestLogAnalyzerPlugin.
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 11
def initialize(args, environment)
handle_arguments(args, environment)
ensure_configuration
if args[0] == "config"
config
elsif args[0] == "autoconf"
autoconf
end
end
|
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
8
9
10
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 8
def debug
@debug
end
|
#environment ⇒ Object
Returns the value of attribute environment.
9
10
11
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 9
def environment
@environment
end
|
#graph_category ⇒ Object
Returns the value of attribute graph_category.
5
6
7
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 5
def graph_category
@graph_category
end
|
#passenger_memory_stats ⇒ Object
Returns the value of attribute passenger_memory_stats.
6
7
8
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 6
def passenger_memory_stats
@passenger_memory_stats
end
|
#passenger_status ⇒ Object
Returns the value of attribute passenger_status.
7
8
9
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 7
def passenger_status
@passenger_status
end
|
Instance Method Details
#autoconf ⇒ Object
111
112
113
114
115
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 111
def autoconf
ensure_configuration
puts "yes"
exit 0
end
|
#ensure_configuration ⇒ Object
107
108
109
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 107
def ensure_configuration
end
|
#handle_arguments(args, environment) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 22
def handle_arguments(args, environment)
self.environment = environment
self.graph_category = environment['graph_category'] || 'App'
if args[0] == "debug"
args.shift
self.debug = true
end
end
|
#require_command(command_name) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 62
def require_command(command_name)
status = `#{command_name}`
unless $?.success?
puts "no (error when excuting #{command_name})"
exit 1
end
end
|
#require_gem(gemname, version = nil) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 93
def require_gem(gemname, version = nil)
begin
require 'rubygems'
if version
gem gemname, version
else
gem gemname
end
rescue Exception => e
puts "no (Gem not found: #{e})"
exit 1
end
end
|
#require_passenger_gem ⇒ Object
32
33
34
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 32
def require_passenger_gem
require_gem("passenger", ">=2.0")
end
|
#require_passenger_memory_stats ⇒ Object
87
88
89
90
91
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 87
def require_passenger_memory_stats
self.passenger_memory_stats = environment['passenger_memory_stats'] || '/usr/local/bin/passenger-memory-stats'
require_command(passenger_memory_stats)
end
|
#require_passenger_status ⇒ Object
77
78
79
80
81
82
83
84
85
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 77
def require_passenger_status
self.passenger_status = environment['passenger_status'] || '/usr/local/bin/passenger-status'
if environment['apache_pid_file']
self.passenger_status = "cat #{environment['apache_pid_file']} | xargs -0 #{passenger_status}"
end
require_command(passenger_status)
end
|
#require_request_log_analyzer_gem ⇒ Object
49
50
51
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 49
def require_request_log_analyzer_gem
require_gem("request-log-analyzer", ">=1.1.6")
end
|
#require_tail_command ⇒ Object
70
71
72
73
74
75
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 70
def require_tail_command
unless `echo "test" | tail 2>/dev/null`.include?("test")
puts "no (tail command not found)"
exit 1
end
end
|
#require_yaml_gem ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 53
def require_yaml_gem
begin
require 'yaml'
rescue Exception => e
puts "no (yaml not found)"
exit 1
end
end
|
#run_command(command, debug = false) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 36
def run_command(command, debug = false)
result = `#{command}`
unless $?.success?
$stderr.puts "failed executing #{command}"
exit 1
end
puts result if debug
result
end
|