Monitor Your Business V2
-
Upload
lars-jankowfsky -
Category
Technology
-
view
2.645 -
download
1
description
Transcript of Monitor Your Business V2
Monitor your BusinessLars Jankowfsky, swoodoo.com
Freitag, 20. März 2009
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
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your BusinessWhat can you expect?
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your BusinessWhat can you expect?
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your BusinessWhat can you expect?
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businessnagios
nagios
Freitag, 20. März 2009
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
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
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
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businessnagios
Freitag, 20. März 2009
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
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businessnagios
../etc/objects/commands.cfg
Freitag, 20. März 2009
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businessnagios
../etc/objects/localhost.cfg
Freitag, 20. März 2009
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businessnagios
Freitag, 20. März 2009
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
cacti
Freitag, 20. März 2009
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
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
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
/usr/local/share/cacti/scripts/test.php
Freitag, 20. März 2009
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
is the script ok ?
• amount of data...
• RRD advantages
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#1 - create data input method
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#2 - add data input method fields
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#3 - create data template
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#3 - create data template
Freitag, 20. März 2009
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
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#6 - create graph template items
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#7 - create graph
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
#7 - add into tree
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your Businesscacti
et voila....
Freitag, 20. März 2009
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
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your BusinessTDD!
Talking about the php....
Freitag, 20. März 2009
PHPCon Italia 2009
Lars Jankowfsky, swoodoo.com
Monitor your BusinessThat‘s it...
Questions ?
Freitag, 20. März 2009
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