orinokko / state-monitor
State Monitor
Requires
- php: >= 7.1
- google/cloud-bigquery: ^1.6
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0|~5.8.0
Requires (Dev)
- orchestra/testbench: ~3.4.2|~3.5.0|~3.6.0|~3.7.0
- phpunit/phpunit: ^5.7|6.2|^7.0|^8.0
README
Collects data about exceptions, manual events and some logs. Supports writing to BigQuery. For further data analysis, you can use Google Data Studio or your own application.
Installation
1. Require the Package
composer require orinokko/state-monitor
2. Add to .env
The service identifier of your application
STATE_MONITOR_APP=AppName
Whether or not to use mailing for errors
STATE_MONITOR_LOCAL_EMAIL=true
STATE_MONITOR_ALERT_EMAIL=mail@example.com
Whether or not to use BigQuery
STATE_MONITOR_BIGQUERY=true
Settings for BigQuery, more details
STATE_MONITOR_GOOGLE_CLOUD_PROJECT=[monitor-123456]
STATE_MONITOR_GOOGLE_APPLICATION_CREDENTIALS=[storage/monitor.json]
Whether or not to log queries
STATE_MONITOR_LOG_QUERIES=false
Enable or disable kernel middleware (default "true"-enabled)
STATE_MONITOR_MIDDLEWARE_WEB=false
STATE_MONITOR_MIDDLEWARE_API=false
3. Run config test and installation
php artisan monitor:install
You must get one of or both lines
Local email channel activated and recipient address provided. BigQuery channel activated and connection settings provided.
In the process, additional actions will be performed:
- If sending by email is activated, a test letter will be sent to the specified address (using application mail settings).
- If saving in BigQuery is activated, the existence of the “monitor” data set will be checked. And it will be created if there is no such data set yet. Also the existence of tables "errors", "events", "checks", "queries" will be checked. If they are not there they will be created.
Example output after installation:
public_html$ php artisan monitor:install Current settings: STATE_MONITOR_APP=TestAppName STATE_MONITOR_LOCAL_EMAIL= STATE_MONITOR_ALERT_EMAIL=mail@example.com STATE_MONITOR_BIGQUERY=1 STATE_MONITOR_GOOGLE_CLOUD_PROJECT=monitor STATE_MONITOR_GOOGLE_APPLICATION_CREDENTIALS=/storage/monitor.json STATE_MONITOR_LOG_QUERIES=1 STATE_MONITOR_MIDDLEWARE_WEB= STATE_MONITOR_MIDDLEWARE_API= Local email channel disabled. BigQuery channel activated and connection settings provided. Try configure the database... Dataset already exist. Table for errors already exist. Table for checks already exist. Table for events already exist. Table for queries already exist.
4. Publish assets
php artisan vendor:publish --provider='Orinoko\StateMonitor\MonitorServiceProvider' --tag='public' --force
Advices
If the site package is used in different applications
Ensure that real data is listed in APP_NAME and APP_URL. They are can be used to find the sender.
Usage
Exceptions monitoring
Exceptions automatically will be caught on web and api middleware groups. You can disable this middleware in .env file.
Also exist middleware for custom routes and other:
->middleware('state-monitor-errors')
Checks monitoring
Called manually
Monitor::validateRequest($type,$url,$method,$params=[],$user='',$domain='')
Events monitoring
Called manually
Monitor::storeEvent($message,$priority=0,$url='',$method='',$params=[],$user='',$domain='')
Database monitoring
If STATE_MONITOR_LOG_QUERIES is enabled, it will automatically log all queries to the appropriate table.
Front
After publishing assets add to html
<script src="/vendor/state-monitor/js/monitor.js"></script>
Calling
<script> if (typeof monitorAddEvent === "function") monitorAddEvent('Page http://phplaravel-135581-835906.cloudwaysapps.com loaded'); </script>