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.
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 9
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.
6
7
8
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 6
def debug
@debug
end
|
#environment ⇒ Object
Returns the value of attribute environment.
7
8
9
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 7
def environment
@environment
end
|
#graph_category ⇒ Object
Returns the value of attribute graph_category.
3
4
5
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 3
def graph_category
@graph_category
end
|
#passenger_memory_stats ⇒ Object
Returns the value of attribute passenger_memory_stats.
4
5
6
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 4
def passenger_memory_stats
@passenger_memory_stats
end
|
#passenger_status ⇒ Object
Returns the value of attribute passenger_status.
5
6
7
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 5
def passenger_status
@passenger_status
end
|
Instance Method Details
#autoconf ⇒ Object
109
110
111
112
113
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 109
def autoconf
ensure_configuration
puts "yes"
exit 0
end
|
#ensure_configuration ⇒ Object
105
106
107
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 105
def ensure_configuration
end
|
#handle_arguments(args, environment) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 20
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
60
61
62
63
64
65
66
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 60
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
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 91
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
30
31
32
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 30
def require_passenger_gem
require_gem("passenger", ">=2.0")
end
|
#require_passenger_memory_stats ⇒ Object
85
86
87
88
89
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 85
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
75
76
77
78
79
80
81
82
83
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 75
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
47
48
49
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 47
def require_request_log_analyzer_gem
require_gem("request-log-analyzer", ">=1.1.6")
end
|
#require_tail_command ⇒ Object
68
69
70
71
72
73
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 68
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
51
52
53
54
55
56
57
58
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 51
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
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/munin/request_log_analyzer_plugin.rb', line 34
def run_command(command, debug = false)
result = `#{command}`
unless $?.success?
$stderr.puts "failed executing #{command}"
exit 1
end
puts result if debug
result
end
|