Skip to content

Latest commit

 

History

History
130 lines (119 loc) · 3.73 KB

README.md

File metadata and controls

130 lines (119 loc) · 3.73 KB

Chef monit cookbook

Installs and configures monit.

Also exposes an LWRP for adding and managing additional monit control files.

Attributes

  • node['monit']['config']['daemon'] - controls polling frequency
  • node['monit']['config']['mailservers'] - specify mail servers to use
  • node['monit']['config']['subscribers'] - controls alert recipients
  • node['monit']['config']['mail_from'] - controls alert email from address
  • node['monit']['config']['mail_subject'] - controls alert email subject
  • node['monit']['config']['mail_message'] - controls alert email message
  • node['monit']['config']['mmonit_host'] - controls the M/Monit server
  • and more! check attributes/default.rb for the full list

Usage

Attributes

{
  "monit" => {
    "config" => {
      "daemon" => 90,
      "subscribers" => ["root@localhost", "[email protected]"],
      "mmonit_host" => "http://user:[email protected]:8080/collector",
      "listen_allow" => ["localhost","mmonit.foo.net", "@users read-only"],
      }
    }
  }
}

Defaults

LWRP

Examples of the LWRP resource:

monit_d 'nginx' do
  service_type "process"
  service_id "/var/run/nginx.pid"
  service_group "app"
  start_command "/etc/init.d/nginx start"
  stop_command "/etc/init.d/nginx stop"
  service_tests [
    {'condition' => "if failed port 80 proto http", 'action' => "restart"},
    {'condition' => "if 3 restarts within 5 cycles", 'action' => "alert"}
  ]
end
monit_d 'unicorn' do
  service_type "process"
  service_id "#{node.site.docroot}/shared/pids/unicorn.pid"
  service_group "app"
  start_command "/usr/bin/sudo -u #{node.site.app_user} /bin/bash -l -c '#{node.site.docroot}/current/bin/unicorn -c #{node.site.docroot}/current/config/unicorn.rb -E #{node.site.environment} -D'"
  stop_command "/usr/bin/pkill -f unicorn"
  service_tests [
    {'condition' => "if failed port 80 type tcp proto http",
     'action' => "restart"},
    {'condition' => "if totalmem > 1200 MB for 2 cycles",
     'action' => "alert"},
    {'condition' => "if totalmem > 1500 MB for 2 cycles",
     'action' => "restart"},
    {'condition' => "if failed unixsocket #{node.unicorn.socket} for 2 cycles",
     'action' => "restart"},
    {'condition' => "if 5 restarts within 5 cycles",
     'action' => "timeout"},
  ]
end
LWRP Attributes
Attribute Description Example Default
name name of the `/etc/monit.d` file nginx current resource name
service_type type of monitoring process, host, file
service_group group related checks (e.g. nginx, unicorn are in the "app" group below) app, db
start_command command to start a process if performing a process check "/etc/init.d/nginx start"
stop_command command to stop a process if performing a process check "/etc/init.d/nginx stop"
service_tests free-form hash composed of a condition and an action, allows performing of monitoring tests on a wide variety of attributes [{'condition' => "if failed port 80 type tcp proto http", 'action' => "restart"}, {'condition' => "if totalmem > 80% for 2 cycles", 'action' => "alert"}]