https://github.com/staabm/sysmonitor
Monitors a php app and send notifications on certain error/exception/resource-exhausting/custom events
https://github.com/staabm/sysmonitor
Last synced: about 1 year ago
JSON representation
Monitors a php app and send notifications on certain error/exception/resource-exhausting/custom events
- Host: GitHub
- URL: https://github.com/staabm/sysmonitor
- Owner: staabm
- Created: 2014-11-06T09:15:13.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2025-01-20T15:16:31.000Z (over 1 year ago)
- Last Synced: 2025-04-13T09:17:37.164Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 52.7 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SysMonitor
==========
Monitors a php app and sends notifications on certain error/exception/resource-exhausting/custom/etc. events.
The monitor checks the data you provide and decides with a naive default implementation (see `SystemMonitor#rateAndStore`) when things get urgent/severe. `SystemEvent`s 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.
The default implementation of `SystemEventStorage` stores your data in a mix of APC and Memcached. Therefore it requires both php extensions.
Usage
=====
init all the things. All classes prefixed with `My` need to be provided by the application/framework beeing monitored.
```php
// 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)
```php
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
```php
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)
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.