定制 gladehq/laravel-query-lens 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gladehq/laravel-query-lens

Composer 安装命令:

composer require gladehq/laravel-query-lens

包简介

A Laravel package for analyzing and optimizing database queries with performance insights

README 文档

README

The self-hosted query performance platform for Laravel -- with AI-powered optimization, automated index recommendations, and CI pipeline regression detection.

PHP Version Laravel Version Tests Latest Version on Packagist License

Why QueryLens

  • Self-hosted. Your query data never leaves your servers. No external SaaS dependency, no data privacy concerns.
  • Query-focused. Not another broad monitoring tool. QueryLens is purpose-built for database query performance -- EXPLAIN analysis, index recommendations, regression detection, and AI optimization.
  • Production-ready. Configurable sampling rate, Octane-safe architecture, Laravel Gate authentication, and per-request isolation. Designed for high-traffic applications.
  • Actionable. Every feature produces a concrete next step -- an index to create, a query to rewrite, a regression to investigate. Not just dashboards.
  • 100% free and open-source. Every feature is available to everyone.

How QueryLens Compares

All features included. No paid tiers. MIT licensed. Community-driven.

Feature QueryLens Debugbar Telescope Pulse Nightwatch
Deployment Self-hosted Self-hosted Self-hosted Self-hosted Cloud
Price Free Free Free Free Subscription
EXPLAIN Analysis Deep + human-readable No No No No
Index Recommendations Automated No No No No
Regression Detection CI-integrated No No No Limited
AI Query Optimization OpenAI-compatible No No No No
Transaction Tracking Full lifecycle No Yes No No
Filament Plugin Native panel integration No No No No
Request Sampling Configurable rate No Yes Yes N/A
Alerting Log, Mail, Slack No No No Yes
N+1 Detection Automatic Yes Yes No No
Code Origin Tracing File + line number Yes Yes No No
Request Waterfall Visual timeline Yes No No No

Features

Dashboard Overview

Real-time query monitoring dashboard with stats overview, query list, and performance ratings. Supports live polling, search, and filtering by query type, duration, and slow status.

Dashboard Overview

EXPLAIN Analysis with Human-Readable Output

Run EXPLAIN on any captured query directly from the dashboard. Results are parsed into human-readable descriptions explaining what the database engine is doing -- table scans, index usage, join strategies, and row estimates.

EXPLAIN Analysis

Index Recommendation Engine

Analyzes query patterns over configurable time windows and recommends specific indexes to create. Outputs ready-to-run CREATE INDEX statements with impact estimates based on actual query frequency and duration.

Query Regression Detection and CI Integration

Compare query performance between time periods to detect regressions. Integrates with CI/CD pipelines via the query-lens:check-regression command. Supports webhook notifications for automated alerting when performance degrades.

Regression Detection

AI-Powered Query Optimization

Submit slow queries to any OpenAI-compatible API for optimization suggestions. Returns rewritten SQL, explanation of changes, and estimated performance improvement. Results are cached to avoid redundant API calls.

Transaction Tracking

Track database transaction lifecycle -- begin, commit, rollback events with duration, nesting depth, and query count. Associates queries with their enclosing transaction for debugging deadlocks and long-running transactions.

Filament Panel Integration

Native Filament v3 plugin with real pages, Table Builder, Chart Widgets, and Stats Overview. Register with a single line in your panel configuration. Works alongside the standalone dashboard.

use GladeHQ\QueryLens\Filament\QueryLensPlugin;

$panel->plugin(QueryLensPlugin::make());

Request Waterfall Visualization

Visual timeline of all queries within a single HTTP request, showing execution order, duration bars, and overlap detection. Identifies sequential queries that could be parallelized.

Request Waterfall

Performance Trend Tracking

Track P50, P95, and P99 latency over time with configurable granularity (hourly or daily). Identify slow degradation patterns before they become incidents. Top queries ranked by total impact (frequency multiplied by duration).

Performance Trends

Quick Start

1. Install the package

composer require gladehq/laravel-query-lens

2. Publish configuration and migrations

php artisan vendor:publish --tag=query-lens-config
php artisan vendor:publish --tag=query-lens-migrations

3. Run migrations

php artisan migrate

4. Enable in your environment

QUERY_LENS_ENABLED=true

5. Visit the dashboard

Open /query-lens in your browser.

Configuration

The configuration file is published to config/query-lens.php. Key options:

Storage Driver

'storage' => [
    'driver' => env('QUERY_LENS_STORAGE', 'database'), // 'cache' or 'database'
    'connection' => env('QUERY_LENS_DB_CONNECTION', null),
    'table_prefix' => 'query_lens_',
    'retention_days' => env('QUERY_LENS_RETENTION_DAYS', 365),
],
  • cache -- Ephemeral storage using Laravel's cache. No persistence across restarts. Good for development.
  • database -- Persistent storage with full query history, aggregation, and trend tracking. Required for production features like regression detection and index recommendations.

Sampling Rate

'sampling_rate' => env('QUERY_LENS_SAMPLING_RATE', 1.0),

Controls what fraction of requests have their queries recorded. 1.0 records every request. 0.1 records 10%. The decision is made once per request so all queries within a sampled request are captured together.

Authentication

'web_ui' => [
    'allowed_ips' => ['127.0.0.1', '::1'],
    'auth_gate' => env('QUERY_LENS_AUTH_GATE', null),
],

By default, the dashboard is restricted to localhost. For production, configure a Laravel Gate:

// In AuthServiceProvider
Gate::define('viewQueryLens', function ($user) {
    return $user->isAdmin();
});
QUERY_LENS_AUTH_GATE=viewQueryLens

AI Provider Setup

'ai' => [
    'enabled' => env('QUERY_LENS_AI_ENABLED', false),
    'provider' => env('QUERY_LENS_AI_PROVIDER', 'openai'),
    'api_key' => env('QUERY_LENS_AI_KEY'),
    'model' => env('QUERY_LENS_AI_MODEL', 'gpt-4o-mini'),
    'endpoint' => env('QUERY_LENS_AI_ENDPOINT', 'https://api.openai.com/v1/chat/completions'),
    'cache_ttl' => 3600,
    'rate_limit' => 10,
],

Works with any OpenAI-compatible API endpoint. AI features are entirely optional -- the package is fully functional without them.

Transaction Tracking

QUERY_LENS_TRACK_TRANSACTIONS=true

Alert Channels

'alerts' => [
    'enabled' => env('QUERY_LENS_ALERTS', false),
    'channels' => ['log', 'mail', 'slack'],
    'slack_webhook' => env('QUERY_LENS_SLACK_WEBHOOK'),
    'mail_to' => env('QUERY_LENS_MAIL_TO'),
    'cooldown_minutes' => 5,
],

Artisan Commands

query-lens:aggregate

Pre-calculates hourly and daily performance aggregates for trend charts and top query rankings. Schedule this to run hourly in your app/Console/Kernel.php:

$schedule->command('query-lens:aggregate')->hourly();

query-lens:prune

Cleans up old query data based on the configured retention period. Schedule daily:

$schedule->command('query-lens:prune')->daily();

query-lens:suggest-indexes

Analyzes recorded query patterns and recommends database indexes:

php artisan query-lens:suggest-indexes --days=7
php artisan query-lens:suggest-indexes --sql="SELECT * FROM orders WHERE user_id = ? AND status = ?"
php artisan query-lens:suggest-indexes --format=json

query-lens:check-regression

Detects query performance regressions by comparing current period against the previous period. Designed for CI/CD pipelines:

php artisan query-lens:check-regression --period=daily --threshold=0.2
php artisan query-lens:check-regression --webhook --format=json

Returns exit code 1 when regressions are detected, making it suitable for CI pipeline gates.

Filament Integration

QueryLens includes a native Filament v3 plugin. Filament is optional -- the package works without it.

Register the plugin

use GladeHQ\QueryLens\Filament\QueryLensPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QueryLensPlugin::make()
                ->dashboard()    // Query Dashboard page
                ->alerts()       // Alert Management page
                ->trends(),      // Performance Trends page
        ]);
}

Customize

QueryLensPlugin::make()
    ->dashboard(true)
    ->alerts(false)          // Disable alerts page
    ->trends(true)
    ->navigationGroup('Monitoring');

The plugin provides:

  • Dashboard -- Stats overview widget, query table with search/filter/sort, View and Explain actions
  • Alerts -- CRUD management for alert rules with modal forms
  • Trends -- Performance and volume chart widgets, top queries table with period selector

Requirements

  • PHP 8.1+
  • Laravel 10.x, 11.x, or 12.x
  • Filament 3.x (optional, for panel integration)

Documentation

Read complete documentation at Documentation.

Contributing

Contributions are welcome. Please submit pull requests against the master branch. Run the test suite before submitting:

./vendor/bin/phpunit

License

The MIT License (MIT). See LICENSE for details.

Credits

Developed by Dulitha Rajapaksha for GladeHQ.

gladehq/laravel-query-lens 适用场景与选型建议

gladehq/laravel-query-lens 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「performance」 「sql」 「query」 「profiler」 「optimization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gladehq/laravel-query-lens 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gladehq/laravel-query-lens 我们能提供哪些服务?
定制开发 / 二次开发

基于 gladehq/laravel-query-lens 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 19
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08