Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
set :monit_daemon_interval, "120"
set :monit_alert_email, "root"

desc "Setup monit daemon monitoring"
task :setup_monit do
  
  monit_configuration = <<-EOF
# This monit configuration was generated dynamically
set daemon #{monit_daemon_interval}
set mailserver localhost
set alert #{monit_alert_email}

check system #{domain}
  if loadavg (1min) > 4 then alert
  if loadavg (5min) > 2 then alert
  if memory usage > 75% then alert
  if cpu usage (user) > 70% then alert
  if cpu usage (system) > 30% then alert
  if cpu usage (wait) > 20% then alert

EOF
  put monit_configuration, "#{shared_path}/main.conf"
  sudo "cp #{shared_path}/main.conf /etc/monit.d/"
  sudo "rm -f #{shared_path}/main.conf"
  
  monit_mongrel_configuration = <<-EOF
# This monit configuration was generated dynamically
#
EOF

  (0..mongrel_servers-1).each do |server|
    monit_mongrel_configuration +=<<-EOF
check process mongrel-#{mongrel_port + server} with pidfile /var/run/mongrel_cluster/#{application}.#{mongrel_port + server}.pid
  group mongrel
  start program = "/usr/bin/mongrel_rails cluster::start -C /etc/mongrel_cluster/#{application}.conf --only #{mongrel_port + server} --clean"
  stop program  = "/usr/bin/mongrel_rails cluster::stop -C /etc/mongrel_cluster/#{application}.conf --only #{mongrel_port + server} --force --clean"
  if totalmem > 100.0 MB for 5 cycles then restart
  if failed port #{mongrel_port + server} protocol http with timeout 10 seconds then restart

EOF
  end

  put monit_mongrel_configuration, "#{shared_path}/rails.conf"
  sudo "cp #{shared_path}/rails.conf /etc/monit.d/"
  sudo "rm -f #{shared_path}/rails.conf"
end