mpernia/request-query-monitor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mpernia/request-query-monitor

Composer 安装命令:

composer require mpernia/request-query-monitor

包简介

Laravel monitoring package for queries and API requests

README 文档

README

Request Query Monitor for Laravel

RequestQueryMonitor for Laravel is a lightweight package designed to monitor and log API requests and database queries in your Laravel applications. It helps you identify slow endpoints and database queries, providing better visibility into your application's performance.

Installation

Install via Composer:

composer require mpernia/request-query-monitor

Configuration

Publish the configuration files:

php artisan vendor:publish --tag=monitoring-config

This will publish the following files into your config folder: monitoring.php

Note: add this flag --force to overwrite any existing files.

Environment variables

You can also set these values in your .env file:

QUERY_LOGGER_ENABLED=false                 # Enabled the queries logged
QUERY_LOGGER_ENABLED_MEMORY_USAGE=false    # Enabled return the memory usage 
QUERY_LOGGER_SLOW_THRESHOLD=100            # Slow query threshold in milliseconds
QUERY_LOGGER_FILENAME=query                # The name of the log file 
REQUEST_LOGGER_ENABLED=false               # Enabled the requests logged
REQUEST_LOGGER_ENABLED_MEMORY_USAGE=false  # Enabled return the memory usage
REQUEST_LOGGER_SLOW_THRESHOLD=500          # Slow request threshold in milliseconds
REQUEST_LOGGER_FILENAME=request            # The name of the log file 

Usage

Database Query Logging

When QUERY_LOGGER_ENABLED is set to true, all executed database queries are logged, with warnings for queries exceeding the configured threshold.

API Request Logging

Registering the middleware ApiRequestLogger in

Laravel version 11 or higher:

Edit the bootstrap/app.php file and put this code:

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->group('web', [
            \RequestQueryMonitor\Http\Middleware\ApiRequestLogger::class,
        ]);
        $middleware->group('api', [
            \RequestQueryMonitor\Http\Middleware\ApiRequestLogger::class,
        ]);
    })
laravel version 10 or lower:

Edit the app/Http/Kernel.php file and put this code:

    protected $middlewareGroups = [
        'web' => [
            \RequestQueryMonitor\Http\Middleware\ApiRequestLogger::class,
        ],
        'api' => [
            \RequestQueryMonitor\Http\Middleware\ApiRequestLogger::class,
        ],
    ];

All incoming API requests will be logged, including:

  • HTTP method
  • Full URL
  • Response status code
  • Execution time (in milliseconds)
  • IP address
  • User agent
  • Incoming payload (with sensitive data like passwords automatically excluded)

Examples

Request Log Output

The HTTP request information is logged:

{
    "method": "POST",
    "url": "https://example.com/api/v1/orders",
    "status": 201,
    "duration_ms": 245.87,
    "ip": "123.45.67.89",
    "user_agent": "PostmanRuntime/7.36.0",
    "payload": {
        "product_id": 123,
        "quantity": 2
    }
}

Query Log Output

Database queries will log like this:

{
    "query": "select * from users where email = 'john@example.com'",
    "time_ms": 5.24
}

View Log with Artisan Command

Show Requests Log on console

php artisan show:log --requests --file=request-monitor. log

Output

Level Method URL Response Size Duration (ms) RAM Real RAM
WARNING GET https://example.com/api/v1/orders 206.06 KB 937.74 3.03 MB 12.00 MB
INFO POST https://example.com/api/v1/orders 1.37 KB 281.13 2.75 MB 12.00 MB

Show Queries Log on console

php artisan show:log --queries --file=query-monitor.log

Output

Level Class Method Duration (ms) RAM Real RAM
WARNING App\Repositories\Order\OrderRepository search 170.83 2.62 MB 12.00 MB
INFO App\Repositories\Order\OrderRepository create 1.58 2.63 MB 12.00 MB

License

This package is open-sourced software licensed under the MIT license.

Contributing

Please see CONTRIBUTING for details.

mpernia/request-query-monitor 适用场景与选型建议

mpernia/request-query-monitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mpernia/request-query-monitor 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-05