Skip to content

A working example of website synthetic monitoring using the synthetic_monitor gem

License

Notifications You must be signed in to change notification settings

johnboyes/example-synthetic-monitor

Repository files navigation

example-synthetic-monitor

Build Status Test Coverage Code Climate Dependency Status

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']

(jump to this code snippet)

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

(jump to this code snippet)

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

(jump to this code snippet)

Prerequisites

Running Locally

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

More info on foreman

Deploying to Heroku

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:

Deploy

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

Coming soon

About

A working example of website synthetic monitoring using the synthetic_monitor gem

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages