50
Monitoring web application behaviour with cucumber-nagios Lindsay Holmwood <[email protected]>

Monitoring web application behaviour with cucumber-nagios

Embed Size (px)

DESCRIPTION

Setting up monitoring for web applications can be complicated - tests tend to lack expressiveness, or and quite often they don't even test the right problem in the first place. cucumber-nagios lets a sysadmin write behavioural tests for their web apps in plain English, and outputs the test results in the Nagios plugin format, allowing a sysadmin to be notified by Nagios when their production apps aren't behaving.

Citation preview

Page 1: Monitoring web application behaviour with cucumber-nagios

Monitoring web applicationbehaviour with

cucumber-nagiosLindsay Holmwood <[email protected]>

Page 2: Monitoring web application behaviour with cucumber-nagios
Page 3: Monitoring web application behaviour with cucumber-nagios
Page 4: Monitoring web application behaviour with cucumber-nagios

http://flickr.com/photos/therefromhere/510612621/

Page 5: Monitoring web application behaviour with cucumber-nagios

Feature: google.com.au It should be up And I should be able to search for things

Scenario: Searching for things When I visit "http://www.google.com" And I fill in "q" with "wikipedia" And I press "Google Search" Then I should see "www.wikipedia.org"

# features/google.com.au/search.feature

Page 6: Monitoring web application behaviour with cucumber-nagios
Page 7: Monitoring web application behaviour with cucumber-nagios

--format pretty

Page 8: Monitoring web application behaviour with cucumber-nagios

$ bin/cucumber --require bin/common.rb \ --require features/ \ features/google.com.au/search.feature

--format pretty

Page 9: Monitoring web application behaviour with cucumber-nagios

Feature: google.com.au It should be up And I should be able to search for things Scenario: Searching for things When I visit "http://www.google.com" And I fill in "q" with "wikipedia" And I press "Google Search" Then I should see "www.wikipedia.org"

1 scenario4 steps passed

$ bin/cucumber --require bin/common.rb \ --require features/ \ features/google.com.au/search.feature

--format pretty

Page 10: Monitoring web application behaviour with cucumber-nagios
Page 11: Monitoring web application behaviour with cucumber-nagios

cucumber

Page 12: Monitoring web application behaviour with cucumber-nagios

cucumberwebrat

Page 13: Monitoring web application behaviour with cucumber-nagios

cucumberwebratmechanize

Page 14: Monitoring web application behaviour with cucumber-nagios

cucumberwebratmechanizenagios =>

Page 15: Monitoring web application behaviour with cucumber-nagios

cucumber-nagios

Page 16: Monitoring web application behaviour with cucumber-nagios

cucumber-nagios

$ bin/cucumber-nagios features/google.com.au/search.feature

Critical: 0, Warning: 0, 4 okay | passed=4, failed=0, total=4

Page 17: Monitoring web application behaviour with cucumber-nagios

how it workshttp://flickr.com/photos/sunbeer/931205335/

Page 18: Monitoring web application behaviour with cucumber-nagios
Page 19: Monitoring web application behaviour with cucumber-nagios

$ bin/cucumber-nagios \ features/google.com.au/search.feature

Page 20: Monitoring web application behaviour with cucumber-nagios

$ bin/cucumber --require bin/common.rb \ --require features/ \ --format Nagios::NagiosFormatter \ features/google.com.au/search.feature

$ bin/cucumber-nagios \ features/google.com.au/search.feature

Page 21: Monitoring web application behaviour with cucumber-nagios

$ bin/cucumber --require bin/common.rb \ --require features/ \ --format Nagios::NagiosFormatter \ features/google.com.au/search.feature

$ bin/cucumber-nagios \ features/google.com.au/search.feature

Page 22: Monitoring web application behaviour with cucumber-nagios

module Nagios class NagiosFormatter def initialize(*args) @failed = []; @passed = [] end

def step_passed(step, name, params) @passed << step end

def step_failed(step, name, params) @failed << step end

def scenario_executed(scenario) @total = @failed.size + @passed.size message = "" message += "Critical: #{@failed.size}, " message += "Warning: 0, " message += "#{@passed.size} okay" message += " | passed=#{@passed.size))}" message += ", failed=#{@failed.size))}, total=#{@total}"" puts message end endend

Page 23: Monitoring web application behaviour with cucumber-nagios

#!/bin/sh

dirname=$(dirname $0) feature=$1 $dirname/cucumber --require $dirname/common.rb \ --require features/ \ --format Nagios::NagiosFormatter \ $featureretval=$? if [ "$retval" -eq "1" ]; then exit 2else exit $retval fi

Page 24: Monitoring web application behaviour with cucumber-nagios

#!/bin/sh

dirname=$(dirname $0) feature=$1 $dirname/cucumber --require $dirname/common.rb \ --require features/ \ --format Nagios::NagiosFormatter \ $featureretval=$? if [ "$retval" -eq "1" ]; then exit 2else exit $retval fi

0 good1 bad2 ugly

Page 25: Monitoring web application behaviour with cucumber-nagios

http://flickr.com/photos/chrisindarwin/3082606450/

Page 26: Monitoring web application behaviour with cucumber-nagios

Setting up

Page 27: Monitoring web application behaviour with cucumber-nagios
Page 28: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

Page 29: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

# gem install auxesis-cucumber-nagios

Page 30: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

# gem install auxesis-cucumber-nagios

$ cucumber-nagios-gen project mysite.com

Page 31: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

# gem install auxesis-cucumber-nagios

$ cucumber-nagios-gen project mysite.com

woosh!

Page 32: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

# gem install auxesis-cucumber-nagios

$ cucumber-nagios-gen project mysite.com

$ cd mysite.com

woosh!

Page 33: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

# gem install auxesis-cucumber-nagios

$ cucumber-nagios-gen project mysite.com

$ cd mysite.com

$ rake deps

woosh!

Page 34: Monitoring web application behaviour with cucumber-nagios

$ gem sources -a http://gems.github.com/

# gem install auxesis-cucumber-nagios

$ cucumber-nagios-gen project mysite.com

$ cd mysite.com

$ rake deps

brr!

woosh!

Page 35: Monitoring web application behaviour with cucumber-nagios
Page 36: Monitoring web application behaviour with cucumber-nagios

$ bin/cucumber-nagios-gen feature search

Page 37: Monitoring web application behaviour with cucumber-nagios

$ bin/cucumber-nagios-gen feature search

$ bin/cucumber-nagios features/search.feature

Page 38: Monitoring web application behaviour with cucumber-nagios

Quirks

Page 39: Monitoring web application behaviour with cucumber-nagios

Failure*IS* an option

Page 40: Monitoring web application behaviour with cucumber-nagios
Page 41: Monitoring web application behaviour with cucumber-nagios

begin

# foo

rescue

# bar

end

Page 42: Monitoring web application behaviour with cucumber-nagios

Multiple Scenariosper File

Page 43: Monitoring web application behaviour with cucumber-nagios

Critical: 1, Warning: 0, 2 okay | passed=2, failed=1, total=3Critical: 1, Warning: 0, 4 okay | passed=4, failed=1, total=5

Page 44: Monitoring web application behaviour with cucumber-nagios
Page 45: Monitoring web application behaviour with cucumber-nagios

Page 46: Monitoring web application behaviour with cucumber-nagios

Instead of writing boring monitoring plugins from scratch, you can now do behavior driven ops!

Page 47: Monitoring web application behaviour with cucumber-nagios

Instead of writing boring monitoring plugins from scratch, you can now do behavior driven ops!

Transform from a grumpy, misanthropic sysadmin to a hipster, agile developer instantly.

— Bradley Taylor (http://bit.ly/lWWfE)

Page 48: Monitoring web application behaviour with cucumber-nagios

developers sysadmins

http://flickr.com/photos/jshappell/1313699764/

Page 49: Monitoring web application behaviour with cucumber-nagios

building bridges

http://flickr.com/photos/douaireg/2313764485/

Page 50: Monitoring web application behaviour with cucumber-nagios

http://github.com/auxesis/cucumber-nagios

http://dryicons.com/free-icons/preview/coquette-part-3-icons-set/