Class: LogMonitor
Instance Method Summary
collapse
Methods inherited from DeployKit
#backup, #backup_path, #check_conf, #cmd, #create_dirs, #ensure_directory_exists, #final_filename, #initialize, #timestamp
Constructor Details
This class inherits a constructor from DeployKit
Instance Method Details
#allow_time ⇒ Object
15
16
17
|
# File 'lib/deploy_kit/log_monitor.rb', line 15
def allow_time
@fu_conf[:allow_time_ms].to_i
end
|
#check_warning(will_sent = nil) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/deploy_kit/log_monitor.rb', line 2
def check_warning(will_sent = nil)
cmd = "cat #{log_path} | grep \"200 OK\" | awk '{print $3 \" \" $0}' | sort -nr | head -n 10"
puts cmd if @verbose
lines = `#{cmd}`
return if !need_send?(lines)
if !will_sent.blank?
send_mail(lines)
else
puts lines
end
end
|
#log_path ⇒ Object
19
20
21
|
# File 'lib/deploy_kit/log_monitor.rb', line 19
def log_path
File.join(RAILS_ROOT, "log", "production.log")
end
|
#need_send?(lines) ⇒ Boolean
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/deploy_kit/log_monitor.rb', line 23
def need_send?(lines)
result = nil
time = lines.to_s.split(" ").first
return false if time.blank?
if is_ms?(time)
if time.to_f > allow_time
result = true
end
else
if time.to_f > (allow_time / 1000)
result = true
end
end
result
end
|
#send_mail(lines) ⇒ Object
41
42
43
44
45
|
# File 'lib/deploy_kit/log_monitor.rb', line 41
def send_mail(lines)
cmd = "echo \"#{lines}\" | mail #{@fu_conf[:to_mail]} -s \"#{@timestamp} #{@fu_conf[:app_name]} log \" -a \"From: #{@fu_conf[:from_mail]}\""
puts cmd if @verbose
`#{cmd}`
end
|