Monitor Your Business V2

41
Monitor your Business Lars Jankowfsky, swoodoo.com Freitag, 20. März 2009

description

The most important thing happening in your website is the business process. So why should you monitor your database and your webserver only when your business is failing? Monitoring is not only about hardware and databases - it's also about the internals of your application. Learn how to monitor your business using PHP and how to create nice, good looking management compatible graphs.

Transcript of Monitor Your Business V2

Page 1: Monitor Your Business V2

Monitor your BusinessLars Jankowfsky, swoodoo.com

Freitag, 20. März 2009

Page 2: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessWho is talking?

Lars Jankowfsky

• CTO swoodoo.com

• php since php/fi

• developing since 15 years

Freitag, 20. März 2009

Page 3: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessPreface

• No rocket science today

• using existing tools for business monitoring

• nagios

• cacti

Freitag, 20. März 2009

Page 4: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessWhat can you expect?

Freitag, 20. März 2009

Page 5: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessWhat can you expect?

Freitag, 20. März 2009

Page 6: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessWhat can you expect?

Freitag, 20. März 2009

Page 7: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

nagios

Freitag, 20. März 2009

Page 8: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

• popular open source network monitoring software

• usually used mostly for networking/service monitoring (load,ping,mysql...)

• http://www.nagios.org

• http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html

Freitag, 20. März 2009

Page 9: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

• orders (eCommerce)

• imported data (webservices)

• customer activity (web 2.0)

•...

Freitag, 20. März 2009

Page 10: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

e.g. Order tracking

• we use OXID CE

• http://www.oxid-esales.com/download

• could be any other shopping cart (osc,magento...)

shop zeigenphpmyadmin zeigen

Freitag, 20. März 2009

Page 11: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

the script

• /usr/local/nagios/libexec

• php-cli

• nagios active mode

diff types - we use active (nagios calls)

passive checks write into nagios command file, and later nagios reads. Asynchronous

Freitag, 20. März 2009

Page 12: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

Freitag, 20. März 2009

Page 13: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

#!/usr/bin/php<?php

$link = mysql_connect('localhost', 'root', 'root');mysql_select_db('oxid', $link);

$result = mysql_query("SELECT count(*) FROM `oxorder` WHERE date(oxorderdate) = curdate()");$row = mysql_fetch_array($result, MYSQL_NUM);

$todayordercount = $row[0];

mysql_close($link);

if ($todayordercount < 1) { echo("VALUE ERROR - we got $todayordercount|v=$todayordercount"); exit(2);} elseif ($todayordercount < 5) { echo("VALUE WARNING - we got $todayordercount|v=$todayordercount"); exit(1);} else { echo("VALUE OK - we got $todayordercount|v=$todayordercount"); exit(0);}

Freitag, 20. März 2009

Page 14: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

Plugin Return Code:

• 0=OK

• 1=WARNING

• 2=CRITICAL

• 3=UNKNOWN

Freitag, 20. März 2009

Page 15: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

../etc/objects/commands.cfg

Freitag, 20. März 2009

Page 16: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

../etc/objects/commands.cfg

#Shop Ordersdefine command{ command_name check-oxid-orders command_line $USER1$/check_oxid_orders }

Freitag, 20. März 2009

Page 17: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

../etc/objects/localhost.cfg

Freitag, 20. März 2009

Page 18: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

../etc/objects/localhost.cfg

define service{ use local-service host_name localhost service_description SHOP_ORDERS check_command check-oxid-orders }

Freitag, 20. März 2009

Page 19: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

Freitag, 20. März 2009

Page 20: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businessnagios

Why nagios ?

• automatic alerts like SMS or eMail

• nearly every provider uses it

• can use SNMP for remote testing

• easy to setup and to configure

Freitag, 20. März 2009

Page 21: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

cacti

Freitag, 20. März 2009

Page 22: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

• popular open source RRD graphing tool

• RRD == Round Robin Database

• http://www.cacti.net

• apt-get install cacti

Freitag, 20. März 2009

Page 23: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

• graphs for management like:

• orders, sales

• conversion rates

• booking/visitor rate

• import/sec. rate

• ...

Freitag, 20. März 2009

Page 24: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

e.g. Page Impression tracking

• again OXID CE

• take source from table ,oxlogs‘

shop zeigenphpmyadmin zeigen

Freitag, 20. März 2009

Page 25: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

/usr/local/share/cacti/scripts/test.php

Freitag, 20. März 2009

Page 26: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

/usr/local/share/cacti/scripts/test.php

#!/usr/bin/php<?php

$link = mysql_connect('localhost', 'root', 'root');mysql_select_db('oxid', $link);

$result = mysql_query("SELECT count(*) FROM `oxlogs` WHERE UNIX_TIMESTAMP(oxtime) > (UNIX_TIMESTAMP() - 300)");$row = mysql_fetch_array($result, MYSQL_NUM);

$hitsPerFiveMinutes = $row[0];

mysql_close($link);

// something else$b = rand(0,10);

echo("OK:$hitsPerFiveMinutes ERR:$b");

Freitag, 20. März 2009

Page 27: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

is the script ok ?

• amount of data...

• RRD advantages

Freitag, 20. März 2009

Page 28: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#1 - create data input method

Freitag, 20. März 2009

Page 29: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#2 - add data input method fields

Freitag, 20. März 2009

Page 30: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#3 - create data template

Freitag, 20. März 2009

Page 31: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#3 - create data template

Freitag, 20. März 2009

Page 32: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#4 - add data template fields

Maximum value 0 has special meaning. It means that threshold for maximum value.

be sure that everything is correct. No changes possible later!

Freitag, 20. März 2009

Page 33: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#5 - create graph template...

#6 - create graph template items

after that add type „legend“

Freitag, 20. März 2009

Page 34: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#6 - create graph template items

Freitag, 20. März 2009

Page 35: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#7 - create graph

Freitag, 20. März 2009

Page 36: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

#7 - add into tree

Freitag, 20. März 2009

Page 37: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your Businesscacti

et voila....

Freitag, 20. März 2009

Page 38: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessTDD!

Talking about the php....

• no reason to hack!

• use same source for cacti and nagios!

• don‘t forget the tests...

Freitag, 20. März 2009

Page 39: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessTDD!

Talking about the php....

Freitag, 20. März 2009

Page 40: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessThat‘s it...

Questions ?

Freitag, 20. März 2009

Page 41: Monitor Your Business V2

PHPCon Italia 2009

Lars Jankowfsky, swoodoo.com

Monitor your BusinessThat‘s it...

Thank you for your interest!

http://joind.in/talk/view/237

Freitag, 20. März 2009