PHPackages                             eta/laravel-query-watcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. eta/laravel-query-watcher

ActiveLibrary[Database &amp; ORM](/categories/database)

eta/laravel-query-watcher
=========================

A Laravel package to monitor and log database queries with configurable thresholds

v1.4.0(4mo ago)283MITPHPPHP ^7.2|^8.0|^8.1|^8.2|^8.3CI passing

Since Nov 26Pushed 4mo agoCompare

[ Source](https://github.com/ethantechnology/laravel-query-watcher)[ Packagist](https://packagist.org/packages/eta/laravel-query-watcher)[ RSS](/packages/eta-laravel-query-watcher/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (7)Used By (0)

Laravel Query Watcher
=====================

[](#laravel-query-watcher)

A Laravel package to monitor and log database queries with configurable thresholds and detailed performance metrics.

Features
--------

[](#features)

- 🔍 **Query Count Monitoring**: Track the number of queries executed per request/command
- ⚡ **Slow Query Detection**: Identify queries that exceed execution time thresholds
- 🎯 **Flexible Configuration**: Customize thresholds, log levels, and channels
- 🚫 **Path/Command Exclusions**: Exclude specific routes or artisan commands
- 🌍 **Environment-Specific**: Enable only in desired environments
- 📊 **Detailed Logging**: Optional query SQL and bindings in logs

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require eta/laravel-query-watcher
```

### Laravel Auto-Discovery

[](#laravel-auto-discovery)

The package will automatically register its service provider in Laravel 5.5+.

### Manual Registration (Laravel 5.4 and below)

[](#manual-registration-laravel-54-and-below)

Add the service provider to `config/app.php`:

```
'providers' => [
    // ...
    ETA\LaravelQueryWatcher\QueryWatcherServiceProvider::class,
],
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=query-watcher-config
```

This will create `config/query-watcher.php` with the following options:

### Main Configuration Options

[](#main-configuration-options)

```
return [
    // Enable/disable the watcher
    'enabled' => env('QUERY_WATCHER_ENABLED', true),

    // Query count threshold
    'threshold' => env('QUERY_WATCHER_THRESHOLD', 50),

    // Log level (emergency, alert, critical, error, warning, notice, info, debug)
    'log_level' => env('QUERY_WATCHER_LOG_LEVEL', 'warning'),

    // Log channel (null for default)
    'log_channel' => env('QUERY_WATCHER_LOG_CHANNEL', null),

    // Slow query threshold in milliseconds (null to disable)
    'slow_query_threshold' => env('QUERY_WATCHER_SLOW_QUERY_THRESHOLD', 1000),

    // Log query SQL and bindings (be careful with sensitive data)
    'log_query_details' => env('QUERY_WATCHER_LOG_DETAILS', false),

    // Excluded paths (supports wildcards)
    'excluded_paths' => [
        // 'admin/*',
        // '_debugbar/*',
    ],

    // Excluded artisan commands
    'excluded_commands' => [
        // 'migrate',
        // 'db:seed',
    ],
];
```

QUERY\_WATCHER\_SLOW\_QUERY\_ENABLED=false

Slow query threshold (milliseconds)
===================================

[](#slow-query-threshold-milliseconds)

QUERY\_WATCHER\_SLOW\_QUERY\_THRESHOLD=1000

Log query details (SQL and bindings)
====================================

[](#log-query-details-sql-and-bindings)

QUERY\_WATCHER\_LOG\_DETAILS=false

Custom log channel
==================

[](#custom-log-channel)

QUERY\_WATCHER\_LOG\_CHANNEL=stack

```

## Usage

Once installed and configured, the package works automatically. It will:

1. **Monitor all database queries** on each request or artisan command
2. **Log warnings** when query count exceeds the threshold
3. **Detect slow queries** that exceed the execution time threshold
4. **Respect exclusions** for specific paths or commands

### Example Log Output

**High Query Count Warning:**

```

\[2024-01-15 10:30:45\] local.WARNING: \[QueryWatcher\] High number of DB queries detected on `api/users`: 75 queries (threshold: 50) { "path": "api/users", "query\_count": 75, "threshold": 50, "slow\_queries\_count": 3 }

```

**Slow Query Warning:**

```

\[2024-01-15 10:30:45\] local.WARNING: \[QueryWatcher\] Slow query detected on `api/users`: 1250.50ms { "path": "api/users", "execution\_time\_ms": 1250.50 }

```

## Advanced Usage

### Using a Custom Log Channel

Create a custom log channel in `config/logging.php`:

```php
'channels' => [
    'query-watcher' => [
        'driver' => 'single',
        'path' => storage_path('logs/query-watcher.log'),
        'level' => 'warning',
    ],
],

```

Then update your `.env`:

```
QUERY_WATCHER_LOG_CHANNEL=query-watcher
```

### Excluding Specific Paths

[](#excluding-specific-paths)

In `config/query-watcher.php`:

```
'excluded_paths' => [
    'admin/*',
    '_debugbar/*',
    'api/webhooks/*',
],
```

### Excluding Artisan Commands

[](#excluding-artisan-commands)

In `config/query-watcher.php`:

```
'excluded_commands' => [
    'migrate',
    'migrate:*',
    'db:seed',
    'queue:work',
],
```

Best Practices
--------------

[](#best-practices)

1. **Sensitive Data**: Be cautious when enabling `log_query_details` as it may expose sensitive data in logs
2. **Production**: Consider disabling in production by setting `QUERY_WATCHER_ENABLED=false` or using a separate log channel
3. **Thresholds**: Adjust thresholds based on your application's normal query patterns
4. **Exclusions**: Exclude admin panels, debug tools, and high-traffic endpoints that you're aware of

Requirements
------------

[](#requirements)

- PHP 7.2 or higher
- Laravel 5.8, 6.x, 7.x, 8.x, 9.x, 10.x, or 11.x

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Credits
-------

[](#credits)

- [HaiHV](https://github.com/ethantechnology)

Support
-------

[](#support)

If you discover any security-related issues, please email  instead of using the issue tracker.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance74

Regular maintenance activity

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

6

Last Release

147d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/185058892?v=4)[eta-h](/maintainers/eta-h)[@eta-h](https://github.com/eta-h)

---

Top Contributors

[![eta-h](https://avatars.githubusercontent.com/u/185058892?v=4)](https://github.com/eta-h "eta-h (2 commits)")

---

Tags

laravelmonitoringdatabaseperformancequery

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eta-laravel-query-watcher/health.svg)

```
[![Health](https://phpackages.com/badges/eta-laravel-query-watcher/health.svg)](https://phpackages.com/packages/eta-laravel-query-watcher)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

492.8k](/packages/itpathsolutions-dbstan)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
