Monitor your laravel application performance by logging requests in your database then analyze it. The log includes request parameters, actions, SQL queries and errors beside that you can know the requests with raw SQL queries.
asamir/laravel-in-db-performance-monitor is a Laravel package for monitor your laravel application performance by logging requests in your database then analyze it. the log includes request parameters, actions, sql queries and errors beside that you can know the requests with raw sql queries..
It currently has 21 GitHub stars and 7.057 downloads on Packagist (latest version V2.0.3).
Install it with composer require asamir/laravel-in-db-performance-monitor.
Discover more Laravel packages by asamir
or browse all Laravel packages to compare alternatives.
Last updated
Monitor your laravel application performance by logging requests in your database then analyze it. The log includes request parameters, actions, SQL queries and errors beside that you can know the requests with raw SQL queries. Demo
Laravel >=5.1
1- Run composer require asamir/laravel-in-db-performance-monitor
2- For laravel < 5.5 add this provider in config/app.php
'providers' => [
\\...
ASamir\InDbPerformanceMonitor\InDbPerformanceMonitorProvider::class,
]
3- Run php artisan in-db-performance-monitor:init
4- Add and configure the inDbMonitorConn connection in config/database.php file => Hint: the package .env variables is created for you by the previous command:
'connections' => [
//...
'inDbMonitorConn' => [
'driver' => 'mysql',
'host' => env('IN_DB_MONITOR_DB_HOST', ''),
'port' => env('IN_DB_MONITOR_DB_PORT', '3306'),
'database' => env('IN_DB_MONITOR_DB_DB', ''),
'username' => env('IN_DB_MONITOR_DB_USERNAME', ''),
'password' => env('IN_DB_MONITOR_DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'asamir_',
'strict' => false,
'engine' => null,
],
]
5- Add the this middleware in app/Http/Kernel.php file
protected $middleware = [
//...
\ASamir\InDbPerformanceMonitor\InDbPerformanceMonitorMiddleware::class
];
6- Add this line in app/Exceptions/Handler.php => public function report(Exception $exception)
public function report(Exception $exception) {
//...
\ASamir\InDbPerformanceMonitor\LogErrors::inDbLogError($exception);
parent::report($exception);
}
//..Hint For laravel < 5.3 => instead of $exception it will be $e
7- Run php artisan migrate
Now you can make requests and monitor it at /admin-monitor
Remember to open config/inDbPerformanceMonitor.php to set your custom configurations
The inDbMonitorConn connection is where the requests logs will be set, so it can be isolated in another database away from the application database or you can set it in the same database no problem.
The package creates inDbPerformanceMonitor.php file in your config folder which has options
IN_DB_MONITOR_WORK => If true the package will work and log the comming requests (default = true)
IN_DB_MONITOR_PANEL => If false the admin panel will not be accessible and any link to '/admin-monitor/*' with throw 404 (default = true)
IN_DB_MONITOR_TOKEN => Holds the admin-monitor passowrd token (default password = monitor)
IN_DB_MONITOR_NEGLICT_START_WITH => Array of routes to neglict from log (e.x. /test so any request start with /test will not be logged in the DB)
IN_DB_MONITOR_NEGLICT_REQUEST_DATA => If true request data will not be logged and will be replaced with ['%__ALL_HIDDEN__%'] (default = false)
IN_DB_MONITOR_NEGLICT_PARAMS_CONTAIN => Fields in the request which contain any of these names will not be logged and it will be replaced with %_HIDDEN_%
IN_DB_MONITOR_NEGLICT_SESSION_DATA => If true session data will not be logged and will be replaced with ['%__ALL_HIDDEN__%'] and will log the session id only (default = false)
IN_DB_MONITOR_LOG_PACKAGE_QUERIES => If true log queries made by the package in your laravel log (default = false)
IN_DB_MONITOR_GET_IP_INFO => If true get IP location data (default = true)
IN_DB_MONITOR_GET_IP_CLASS => You can change it and use your own class with new third party web services to get the IP location.
Hint: You will find the package env variables created in your .env file
Hint: in the search boxes you can use the like wildcards like %%
The login page (default password = monitor)

Dashboard with requests counts grouped by type and archive tag.

List all logged requests
Search box: search in (Action, Route, URL, Session ID, Type[POST,GET,...], Archive Tag) and in (Error Message, Error File) in case of checked Has errors check box
Not Elequent: I mean free queries like \DB::select(\DB::raw('select * from applicants where id = 10')); this queries are vulnerable to SQL injection attacks. The number in red color represents the number of free queries in the request.
Archive button: Give tag => date('YmdHis') to requests with archive tag = 0
In the table you will find number of queries, queries total time, and request execution time.
You can filter by creation date from => to
If you hovered the Error label, it will display the error message, file, and line number.
The scenario of the requests in the image below

The scenario of the requests in the image below
\DB::select(\DB::raw('select * from applicants')); to retreive applicants, also notice that the request session id changed because it is not under the web middleware.

Shows the request details, queries, and error beside that it allows you to re-run the queries.
Hint => You can quickly get your last request by Latest By Session ID Or IP
By Session ID => Get last request made by your session id
By IP => Get last request made by your ip (requests made by api or routes
which don't use the web middleware will generate different session id at
every request, so you can get them by your IP).
Request of create applicant
...

Request of search applicants
...

Request of error add/4/5+

Statistics report about the requests performance group by request route uri and type.

Statistics report of requests errors group by page uri, type, and error message.

Statistics report of requests archives.

Statistics report of requests IPs. Also you have the ability to recalculate the uncompleted IPs Info.

To change admin monitor panel password.

I was working on a project and my task was to test the application performance and list the requests with performance issues. The problem was that after migrating the data and the database size became larger the application performance decreased and sometimes crashes. Instead of loop on all the application code and check every line on it, I built a listener to log the requests data (queries) run by the application then I analyzed this data and quickly found the requests with weak points. As a result of this, I built the laravel-in-db-performance-monitor package and published it to be used by anyone.
Here are some tips for best practices:
Hint: If you are using an older version (<v2) please run this command after upgrade
php artisan in-db-performance-monitor:init --ips=true --serialize=true
and add this lines in config/inDbPerformanceMonitor.php
'IN_DB_MONITOR_GET_IP_INFO' => env('IN_DB_MONITOR_GET_IP_INFO', true),
'IN_DB_MONITOR_GET_IP_CLASS' => '\\ASamir\\InDbPerformanceMonitor\\IPInfo',
Ahmed Samir
Contacts: [email protected] | Linkedin