A working example of website synthetic monitoring using the synthetic_monitor gem.
This example application is:
- deployable on Heroku (see below) which makes it very quick to get production monitoring up and running
- specified using plain old RSpec tests, which means that it is much more easily customised to your needs than most monitoring solutions.
It runs all the specs in the 'spec' directory every 5 minutes, and notifies any failures on Slack (with SMS notifications coming soon):
SyntheticMonitor.new.monitor ENV['SLACK_WEBHOOK']
Alternatively you can specify individual Slack notification channels or groups for individual spec files:
spec_slack_pairs = {
'spec/a_spec.rb' => ENV['A_SlACK_WEBHOOK'],
'spec/another_spec.rb' => ENV['A_DIFFERENT_SLACK_WEBHOOK'],
'spec/a_third_spec.rb' => ENV['A_THIRD_SLACK_WEBHOOK'],
}
SyntheticMonitor.new.monitor_on_varying_slack_channels spec_slack_pairs
The monitoring frequency is customisable:
SyntheticMonitor.new(frequency_in_minutes: 10).monitor
There are two monitoring specs in this example repository:
scenario "example of a test which will pass, meaning no notification is sent to Slack" do
@session.visit 'https://www.example.com'
expect(@session).to have_content("This domain is established to be used for illustrative examples in documents.")
expect(@session.status_code).to eq(200)
end
and
scenario "example of a test which will fail, triggering a notification on Slack" do
@session.visit 'https://www.example.com'
expect(@session.status_code).to eq(500)
end
-
You must have setup at least one Slack webhook to send notifications to.
(If you are not on Slack you can signup for free at https://slack.com/)
Make sure you have Ruby, Bundler and the Heroku Toolbelt installed.
clone your own fork of this repository
cd name-of-your-fork
bundle
foreman start
heroku create --region eu
heroku buildpacks:set heroku/ruby
heroku buildpacks:add --index 2 https://github.com/stomita/heroku-buildpack-phantomjs
heroku config:set SLACK_WEBHOOK=put_your_slack_webhook_url_here
git push heroku master
heroku ps:scale worker=1
Alternatively, you can deploy your own copy of the app using the web-based flow:
You will need to scale your worker process to 1 dyno, and then the monitoring will automatically start running.
For more information about using Ruby on Heroku, see these Dev Center articles:
Running the functional tests
bundle exec rake test