<commit_before>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
```ruby
default_attributes(
  'monit' => {
    'config' => {
      'poll_freq' => 30,
      'subscribers' => ["root@localhost", "<EMAIL>"],
      'mmonit_host' => "http://user:pass@mmonit.foo.net:8080/collector",
      'listen_allow' => ["localhost","mmonit.foo.net", "@users read-only"],
      }
    }
  }
)
```

#### Defaults


#### LWRP

Examples of the LWRP resource:

##### SSHD

```ruby
monit_d 'sshd' do
  service_type "process"
  service_id "/var/run/sshd.pid"
  service_group "sshd"
  start_command "/etc/init.d/ssh start"
  stop_command "/etc/init.d/ssh stop"
  service_tests [
    {'condition' => "if failed port 22 proto ssh for 3 cycles",
     'action' => "restart"},
    {'condition' => "if 3 restarts within 5 cycles",
     'action' => "alert"},
  ]
end
```

##### Postfix

```ruby
monit_d 'postfix' do
  service_type "process"
  service_id "/var/spool/postfix/pid/master.pid"
  service_group "mail"
  start_command "/etc/init.d/postfix start"
  stop_command "/etc/init.d/postfix stop"
  service_tests [
    {'condition' => "if failed host 127.0.0.1 port 25 type tcp protocol smtp with timeout 15 seconds",
     'action' => "restart"},
    {'condition' => "if 3 restarts within 5 cycles",
     'action' => "alert"},
  ]
end
```

##### Nginx

```ruby
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
```

##### Unicorn 

```ruby
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
```

##### Memcache

```ruby
monit_d 'memcache' do
  service_type "process"
  service_id "/var/run/memcached.pid"
  service_group "memcache"
  start_command "/etc/init.d/memcached start"
  stop_command "/etc/init.d/memcached stop"
  service_tests [
    {'condition' => "if failed port 11211 proto memcache 4 times within 5 cycles",
     'action' => "restart"},
    {'condition' => "if 3 restarts within 15 cycles",
     'action' => "alert"},
  ]
end
```

##### Redis

```ruby
monit_d 'redis' do
  service_type "process"
  service_id "/var/run/redis/redis-server.pid"
  service_group "database"
  start_command "/etc/init.d/redis-server start"
  stop_command "/etc/init.d/redis-server stop"
  service_tests [
    {'condition' => 'if failed host 127.0.0.1 port 6379 
                     send "SET MONIT-TEST value\r\n" expect "OK" 
                     send "EXISTS MONIT-TEST\r\n" expect ":1"',
     'action' => 'restart'},
    {'condition' => 'if 3 restarts within 5 cycles',
     'action' => 'alert'},
  ]
end
```

##### MongoDB

```ruby
monit_d 'mongo' do
  service_type "process"
  service_id "#{node.mongodb.dbpath}/mongod.lock"
  service_group "mongo"
  start_command "/etc/init.d/mongodb start"
  stop_command "/etc/init.d/mongodb stop"
  service_tests [
    {
     'condition' => "if failed port #{node.mongodb.port} proto http for 2 cycles",
     'action' => "restart"
    },
    {
     'condition' => "if 3 restarts within 10 cycles",
     'action' => "timeout"
    }
  ]
end
```

##### External Service Check

```ruby
monit_d 'facebook_api' do
  service_type "host"
  service_id "api.facebook.com"
  service_group "external"
  service_tests [
    {'condition' => "if failed port 80 proto http",
     'action' => "alert"},
    {'condition' => "if failed port 443 type tcpSSL proto http",
     'action' => "alert"}
  ]
end
```

#### LWRP Attributes
<table>
  <thead>
    <tr>
      <th>Attribute</th>
      <th>Description</th>
      <th>Example</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>name</td>
      <td>name of the `/etc/monit.d` file</td>
      <td><tt>nginx</tt></td>
      <td>current resource name</td>
    </tr>
    <tr>
      <td>service_type</td>
      <td>type of monitoring</td>
      <td><tt>process, host, file</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>service_group</td>
      <td>group related checks (e.g. nginx, unicorn are in the "app" group below)</td>
      <td><tt>app, db</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>start_command</td>
      <td>command to start a process if performing a process check</td>
      <td><tt>"/etc/init.d/nginx start"</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>stop_command</td>
      <td>command to stop a process if performing a process check</td>
      <td><tt>"/etc/init.d/nginx stop"</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>service_tests</td>
      <td>allows performing of monitoring tests on a wide variety of attributes</td>
      <td><tt>
             [{'condition' => "if failed port 80 type tcp proto http", 'action' => "restart"},
              {'condition' => "if totalmem > 80% for 2 cycles", 'action' => "alert"}]
          </tt>
      </td>
      <td></td>
    </tr>
  </tbody>
</table>

TODO
----
- finish source_install method
    - init script
    - install path
- allow more periodic checks (every)
- add subscriber opt-in/opt-outs
<commit_msg>add solr monit_d<commit_after>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
```ruby
default_attributes(
  'monit' => {
    'config' => {
      'poll_freq' => 30,
      'subscribers' => ["root@localhost", "<EMAIL>"],
      'mmonit_host' => "http://user:pass@mmonit.foo.net:8080/collector",
      'listen_allow' => ["localhost","mmonit.foo.net", "@users read-only"],
      }
    }
  }
)
```

#### Defaults


#### LWRP

Examples of the LWRP resource:

##### SSHD

```ruby
monit_d 'sshd' do
  service_type "process"
  service_id "/var/run/sshd.pid"
  service_group "sshd"
  start_command "/etc/init.d/ssh start"
  stop_command "/etc/init.d/ssh stop"
  service_tests [
    {'condition' => "if failed port 22 proto ssh for 3 cycles",
     'action' => "restart"},
    {'condition' => "if 3 restarts within 5 cycles",
     'action' => "alert"},
  ]
end
```

##### Postfix

```ruby
monit_d 'postfix' do
  service_type "process"
  service_id "/var/spool/postfix/pid/master.pid"
  service_group "mail"
  start_command "/etc/init.d/postfix start"
  stop_command "/etc/init.d/postfix stop"
  service_tests [
    {'condition' => "if failed host 127.0.0.1 port 25 type tcp protocol smtp with timeout 15 seconds",
     'action' => "restart"},
    {'condition' => "if 3 restarts within 5 cycles",
     'action' => "alert"},
  ]
end
```

##### Nginx

```ruby
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
```

##### Unicorn 

```ruby
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
```

##### Memcache

```ruby
monit_d 'memcache' do
  service_type "process"
  service_id "/var/run/memcached.pid"
  service_group "memcache"
  start_command "/etc/init.d/memcached start"
  stop_command "/etc/init.d/memcached stop"
  service_tests [
    {'condition' => "if failed port 11211 proto memcache 4 times within 5 cycles",
     'action' => "restart"},
    {'condition' => "if 3 restarts within 15 cycles",
     'action' => "alert"},
  ]
end
```

##### Redis

```ruby
monit_d 'redis' do
  service_type "process"
  service_id "/var/run/redis/redis-server.pid"
  service_group "database"
  start_command "/etc/init.d/redis-server start"
  stop_command "/etc/init.d/redis-server stop"
  service_tests [
    {'condition' => 'if failed host 127.0.0.1 port 6379 
                     send "SET MONIT-TEST value\r\n" expect "OK" 
                     send "EXISTS MONIT-TEST\r\n" expect ":1"',
     'action' => 'restart'},
    {'condition' => 'if 3 restarts within 5 cycles',
     'action' => 'alert'},
  ]
end
```
##### Solr

```ruby
monit_d 'solr' do
  service_type "process"
  service_id "/var/run/tomcat6.pid"
  service_group "app"
  start_command "/etc/init.d/tomcat6 start"
  stop_command "/etc/init.d/tomcat6 stop"
  service_tests [
    {
     'condition' => 'if failed port 8080 proto http and request "/solr/admin/ping" for 2 cycles',
     'action' => "restart"
    },
    {
     'condition' => "if 3 restarts within 5 cycles",
     'action' => "timeout"
    }
  ]
end
```

##### MongoDB

```ruby
monit_d 'mongo' do
  service_type "process"
  service_id "#{node.mongodb.dbpath}/mongod.lock"
  service_group "mongo"
  start_command "/etc/init.d/mongodb start"
  stop_command "/etc/init.d/mongodb stop"
  service_tests [
    {
     'condition' => "if failed port #{node.mongodb.port} proto http for 2 cycles",
     'action' => "restart"
    },
    {
     'condition' => "if 3 restarts within 10 cycles",
     'action' => "timeout"
    }
  ]
end
```

##### External Service Check

```ruby
monit_d 'facebook_api' do
  service_type "host"
  service_id "api.facebook.com"
  service_group "external"
  service_tests [
    {'condition' => "if failed port 80 proto http",
     'action' => "alert"},
    {'condition' => "if failed port 443 type tcpSSL proto http",
     'action' => "alert"}
  ]
end
```

#### LWRP Attributes
<table>
  <thead>
    <tr>
      <th>Attribute</th>
      <th>Description</th>
      <th>Example</th>
      <th>Default</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>name</td>
      <td>name of the `/etc/monit.d` file</td>
      <td><tt>nginx</tt></td>
      <td>current resource name</td>
    </tr>
    <tr>
      <td>service_type</td>
      <td>type of monitoring</td>
      <td><tt>process, host, file</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>service_group</td>
      <td>group related checks (e.g. nginx, unicorn are in the "app" group below)</td>
      <td><tt>app, db</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>start_command</td>
      <td>command to start a process if performing a process check</td>
      <td><tt>"/etc/init.d/nginx start"</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>stop_command</td>
      <td>command to stop a process if performing a process check</td>
      <td><tt>"/etc/init.d/nginx stop"</tt></td>
      <td></td>
    </tr>
    <tr>
      <td>service_tests</td>
      <td>allows performing of monitoring tests on a wide variety of attributes</td>
      <td><tt>
             [{'condition' => "if failed port 80 type tcp proto http", 'action' => "restart"},
              {'condition' => "if totalmem > 80% for 2 cycles", 'action' => "alert"}]
          </tt>
      </td>
      <td></td>
    </tr>
  </tbody>
</table>

TODO
----
- finish source_install method
    - init script
    - install path
- allow more periodic checks (every)
- add subscriber opt-in/opt-outs

{'fraction_non_alphanumeric': 0.18000288350634372, 'fraction_numerical': 0.012110726643598616, 'mean_word_length': 3.063561804335091, 'pattern_counts': {'":': 2, '<': 181, '<?xml version=': 0, '>': 287, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5944898', 'n_tokens_mistral': 5086, 'n_tokens_neox': 4787, 'n_words': 1233}