A Laravel package that provides configurable application query capturing & monitoring

Overview


Laravel Query Watcher

GitHub stars GitHub issues GitHub forks PHPUnit

A Laravel package that provides configurable application query capturing & monitoring.

Installation

install the package via composer:

composer require YorCreative/Laravel-Query-Watcher

Publish the packages assets.

php artisan vendor:publish --provider="YorCreative\QueryWatcher\QueryWatcherServiceProvider"

Usage

Configuration

Adjust the configuration file to suite your application.

[
    'enabled' => true, // Do you want to capture queries?
    'token' => env('QUERY_WATCH_TOKEN', 'change_me'), // Token used for Authenticating Private Broadcast Channel
    'scope' => [
        'time_exceeds_ms' => [
            'enabled' => true, // Do you want to capture everything or only slow queries?
            'threshold' => 500, // The number of milliseconds it took to execute the query.
        ],
        'context' => [
            'auth_user' => [
                'enabled' => true, // Do you want to know context of the authenticated user when query is captured?
                'ttl' => 300, // How long do you want the session_id/authenticated user cached for? 
                              // without this cache, your application will infinite loop because it will capture
                              // the user query and loop.
                              // See closed Issue #1 for context.
            ],
            'trigger' => [
                'enabled' => true, // Do you want to know what triggered the query?
                                   // i.e Console command or Request
            ],
        ],
        'ignorable_tables' => [
            'jobs' // Do you want to capture queries on specific tables?
                   // If you are utilizing the database queue driver, you need to
                   // ignore the jobs table or you'll get infinite capture loops.
        ],
        'ignorable_statements' => [
            'create' // Do you want to ignore specific SQL statements?
        ]
    ],
    'listener' => [ // Channel notifications are queued
        'connection' => 'sync', // Define what connection to use.
        'queue' => 'default', //  Define what queue to use
        'delay' => null, // Do you want to delay the notifications at all?
    ],
    'channels' => [ // Where to send notifications?
        'discord' => [ 
            'enabled' => false, // Do you want discord webhook notifications?
            'hook' => env('DISCORD_HOOK', 'please_fill_me_in'), 
        ],
    ]
]

Broadcasting

All captured queries will broadcast on a private channel as the primary monitoring method. The QueryEvent that is broadcasting is using your applications broadcast configuration.

    /**
     * Get the channels the event should broadcast on.
     *
     * @return PrivateChannel
     */
    public function broadcastOn(): PrivateChannel
    {
        return new PrivateChannel('query.event.'. config('querywatcher.token'));
    }

    /**
     * @return string
     */
    public function broadcastAs(): string
    {
        return 'query.event';
    }

Discord Notification Channel

Get a webhook URL from discord in the channel you want to receive your notifications in by reading Discords Introduction to Webhook Article . Once you have your webhook url, add the following variable to your .env file.

DISCORD_HOOK=

Once you have done this, you can enable Discord Notifications in the configuration file.

Screenshots


Testing

composer test

Credits

You might also like...
This package provides extended support for our spatie/enum package in Laravel.
This package provides extended support for our spatie/enum package in Laravel.

Laravel support for spatie/enum This package provides extended support for our spatie/enum package in Laravel. Installation You can install the packag

A Laravel wrapper for spatie/dns. Allows to query and validate DNS records.

A Laravel wrapper for spatie/dns. Allows to query and validate DNS records.

Update multiple Laravel Model records, each with it's own set of values, sending a single query to your database!

Laravel Mass Update Update multiple Laravel Model records, each with its own set of values, sending a single query to your database! Installation You

Use Laravel's built-in ORM classes to query cloud resources with Steampipe.
Use Laravel's built-in ORM classes to query cloud resources with Steampipe.

Laravel Steampipe Use Laravel's built-in ORM classes to query cloud resources with Steampipe, an open source CLI to instantly query cloud APIs using S

Laravel basic Functions, eloquent cruds, query filters, constants

Emmanuelpcg laravel-basics Description Package with basic starter features for Laravel. Install If Builder Constants Install composer require emmanuel

A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.

QueryBuilderParser Status Label Status Value Build Insights Code Climate Test Coverage QueryBuilderParser is designed mainly to be used inside Laravel

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

Enable/disable query logger in Laravel/Lumen

Enable/disable query logger in Laravel/Lumen

A DynamoDB based Eloquent model and Query builder for Laravel.

Laravel DynamoDB A DynamoDB based Eloquent model and Query builder for Laravel. You can find an example implementation in kitar/simplechat. Motivation

Comments
  • Ignorables

    Ignorables

    • Added ability to ignore specific tables and SQL statements.
    • Updated readme information for configuration file.
    • Fixes infinite loop when database queue driver is used.
    bug documentation enhancement 
    opened by yordadev 0
  • Infinite Loop

    Infinite Loop

    Problem:

    When user is authenticated, infinite query loop is happening from Auth::user()->id on line 16

    Expectation:

    When user is authenticated and a query is captured, AuthTransformer is able to retrieve the user once preventing an infinite loop.

    bug 
    opened by yordadev 0
  • Auth Transformer Patch

    Auth Transformer Patch

    • Added cache to auth transformer to fix infinte loop when auth user available.
    • Added test coverage to confirm fix.
    • Updated configuration file.
    • Added ability to enable context on query model.
    bug enhancement 
    opened by yordadev 0
Releases(v1.4.1)
Owner
YorCreative
YorCreative focuses on package development for the Laravel community.
YorCreative
Laravel application performance monitoring

Gauge - Laravel Application Performance Monitoring Gauge is an easy to use package to monitor the performance of your Laravel applications. Gauge in b

Tobias Dierich 132 Dec 11, 2022
A laravel Livewire Dynamic Selects with multiple selects depending on each other values, with infinite levels and totally configurable.

Livewire Combobox: A dynamic selects for Laravel Livewire A Laravel Livewire multiple selects depending on each other values, with infinite levels of

Damián Aguilar 25 Oct 30, 2022
A nice GUI for Laravel Artisan, ready out of the box, configurable and handy for non-CLI experienced developers.

Artisan UI A nice GUI for Laravel Artisan, ready out of the box, configurable and handy for non-CLI experienced developers. Supported commands must be

Pablo Leone 1 Dec 3, 2021
Intranet Home Page is a highly-configurable self-hosted browser homepage with integrations for public and local data feeds.

Intranet-Home-Page Created in response to personal "dashboards" that are little more than pages with a list of frequently accessed links, Intranet Hom

null 56 Aug 27, 2022
Configurable products switcher

Easylife Switcher Configurable products switcher v2.3.2 Discontinued This extension is no longer supported by the developer (that's me). There will be

Marius Strajeru 172 Sep 13, 2022
Configurable activity logger for filament.

Activity logger for filament Configurable activity logger for filament. Powered by spatie/laravel-activitylog Features You can choose what you want to

Ziyaan 58 Dec 30, 2022
Provides a Eloquent query builder for Laravel or Lumen

This package provides an advanced filter for Laravel or Lumen model based on incoming requets.

M.Fouladgar 484 Jan 4, 2023
A package to filter laravel model based on query params or retrieved model collection

Laravel Filterable A package to filter laravel model based on query params or retrived model collection. Installation Require/Install the package usin

Touhidur Rahman 17 Jan 20, 2022
Laravel router extension to easily use Laravel's paginator without the query string

?? THIS PACKAGE HAS BEEN ABANDONED ?? We don't use this package anymore in our own projects and cannot justify the time needed to maintain it anymore.

Spatie 307 Sep 23, 2022
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Syrian Open Source 15 Nov 20, 2022