DBMon
DBMon is a simple database monitoring daemon that watches a given table for writes. If it doesn't detect a certain amount of writes within a specific period of time, it triggers an alert.
Installation
Add this line to your application's Gemfile:
gem 'dbmon'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dbmon
Usage
The gem comes with a command-line utility, dbmon
, that starts and stops the monitor in addition to other daemon tasks. To start the monitor, simply invoke the dbmon start
command and point to your configuration file:
dbmon start -- -C /path/to_your/config.yml
This will invoke the script as a daemon, putting it in the background.
You can stop the monitor at any time by invoking dbmon stop
Configuration
The configuration file for DBMon is a YAML file that allows you to specify many of the aspects of DBmon's behavior. An example config is below:
interval: 10
threshold: 1
adapter: 'pg'
database: 'is_development'
table: 'users'
username: 'stlewis'
password: 'dbpass'
notify: '[email protected]'
delivery_method: 'smtp'
The purpose of these options is described below:
interval
How often (in seconds) to check the table for new writes. DBMon will query the table in question for writes that occurred between NOW() and interval
ago.
threshold
This is the minimum number of records that must have been added to the database within the interval specified to avoid triggering an alert.
adapter
The database adapter to use for making connections. Currently supported options are mysql2 and pg. Note that you must have either the mysql2 gem or the pg gem in order to use it as an adapter.
database
The name of the database to connect to.
table
The name of the table you want to monitor.
username
The database username
password
The database password
notify
The email address you would like to receive a notification when an alert is triggered.
delivery_method
This option is passed directly to the Mail gem, and determines how you would like messages delivered. The default is 'smtp', but if you would like to test email delivery, you can use 'test' as a value.
TODO
- Make more options available for Mail configuration
- Monitoring for multiple tables