2017 © Pedro Peláez
 

library sysmonitor

image

staabm/sysmonitor

  • Monday, October 16, 2017
  • by staabm
  • Repository
  • 1 Watchers
  • 1 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

SysMonitor

Monitors a php app and sends notifications on certain error/exception/resource-exhausting/custom/etc. events., (*1)

The monitor checks the data you provide and decides with a naive default implementation (see SystemMonitor#rateAndStore) when things get urgent/severe. SystemEvents are compared using a hash so times of occurence can also be based on similarity. Notifications are beeing send in such cases, depending on your used Notifier., (*2)

The default implementation of SystemEventStorage stores your data in a mix of APC and Memcached. Therefore it requires both php extensions., (*3)

Usage

init all the things. All classes prefixed with My need to be provided by the application/framework beeing monitored., (*4)

// sends notificaitons on urgent events
$notifier = new SeverityNotifier(new MyCustomNotifier(), SystemEvent::SEVERITY_URGENT);
// main class which collects all the data
$monitor = new SystemMonitor(new SystemEventStorage(), new MyRequestEnvImpl(), $notifier);

report performance-data from somewhere in your app (e.g. on request shutdown), (*5)

register_shutdown_function(function() {
    $requestStats = new RequestStatsEvent();
    // data from your db class
    $requestStats->usedQueries = DB::$num_of_queries;
    $requestStats->usedConnections = DB::$num_of_connections;
    // data from your runtime
    $requestStats->peakMemory = number_format(memory_get_peak_usage(true) / 1024 / 1024);

    // retrieve the monitor instance, e.g. via a DIC/a registry/singleton/whatever
    // $monitor = .. 
    $monitor->collectStats($requestStats);
});

let the Monitor collect data about exceptions occured, (*6)

set_exception_handler(function() {
    $event = new RequestExceptionEvent();
    $event->exception = $exception;

    // retrieve the monitor instance, e.g. via a DIC/a registry/singleton/whatever
    // $monitor = .. 
    $monitor->collectException($event);
});

you could do the same for errors. To collect data of fatal errors there are some known workarounds which can be used (checking for error_get_last() in a shutdown function), (*7)

Sidenote

This library was extracted out of a framework and contains some "strange" things which are kept for BC reasons. This will be changed in version 2.0., (*8)

The Versions

16/10 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by Markus Staab

16/10 2017

v0.4.1

0.4.1.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

14/06 2017

v0.4

0.4.0.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

12/12 2016

v0.3.2

0.3.2.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

01/12 2016

v0.3.1

0.3.1.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

30/09 2016

v0.3

0.3.0.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

20/03 2015

v0.2

0.2.0.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

04/03 2015

v0.1.5

0.1.5.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

19/02 2015

v0.1.4

0.1.4.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

06/02 2015

v0.1.3

0.1.3.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

06/11 2014

v0.1.2

0.1.2.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

06/11 2014

v0.1.1

0.1.1.0

  Sources   Download

MIT

The Requires

 

by Markus Staab

06/11 2014

v0.1

0.1.0.0

  Sources   Download

MIT

The Requires

 

by Markus Staab