yorcreative/laravel-query-watcher
Composer 安装命令:
composer require yorcreative/laravel-query-watcher
包简介
A Laravel package that provides configurable application query capturing & monitoring.
关键字:
README 文档
README
Laravel Query Watcher
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.
[
// Do you want to capture queries?
'enabled' => env('QUERY_WATCH_ENABLED', true),
// Token used for Authenticating Private Broadcast Channel
'token' => env('QUERY_WATCH_TOKEN', 'change_me'),
'scope' => [
'time_exceeds_ms' => [
// Do you want to capture everything or only slow queries?
'enabled' => env('QUERY_WATCH_SCOPE_TIME_ENABLED', true),
// The number of milliseconds it took to execute the query.
'threshold' => env('QUERY_WATCH_SCOPE_TIME_THRESHOLD', 500),
],
'context' => [
'auth_user' => [
// Do you want to know context of the authenticated user when query is captured?
'enabled' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_ENABLED', true),
// 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.
'ttl' => env('QUERY_WATCH_SCOPE_CONTEXT_AUTH_TTL', 300),
],
'trigger' => [
// Do you want to know what triggered the query?
// i.e Console command or Request
'enabled' => env('QUERY_WATCH_SCOPE_TRIGGER_ENABLED', true),
],
],
'ignorable_tables' => [
// 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 potentially get infinite capture loops.
'jobs',
'failed_jobs'
],
'ignorable_statements' => [
// Do you want to ignore specific SQL statements?
'create'
]
],
'listener' => [
// Channel notifications are queued
// Define what connection to use.
'connection' => 'sync',
// Define what queue to use
'queue' => 'default',
// Do you want to delay the notifications at all?
'delay' => null,
],
'channels' => [ // Where to send notifications?
'discord' => [
// Do you want discord webhook notifications?
'enabled' => env('QUERY_WATCH_CHANNEL_DISCORD_ENABLED', false),
// Discord Web-hook URL
'hook' => env('DISCORD_HOOK', 'please_fill_me_in'),
],
'slack' => [
// Do you want Slack webhook notifications?
'enabled' => env('QUERY_WATCH_CHANNEL_SLACK_ENABLED', false),
// Slack Web-hook URL
'hook' => env('SLACK_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'; }
Slack Notification Channel
To utilize Slack Notifications, you will need to create a webhook for one of your Slack Channels. Once you have your webhook url, add the following variable to your .env file.
SLACK_HOOK=<hook>
Once you have done this, you can enable Slack Notifications in the configuration file.
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=<hook>
Once you have done this, you can enable Discord Notifications in the configuration file.
Wiki Documentation
Testing
composer test
Credits
yorcreative/laravel-query-watcher 适用场景与选型建议
yorcreative/laravel-query-watcher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 36, 最近一次更新时间为 2022 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「laravel」 「queries」 「sql monitoring」 「capture queries」 「query capture」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yorcreative/laravel-query-watcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yorcreative/laravel-query-watcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yorcreative/laravel-query-watcher 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
PDO+ extends PDO in order to log all your queries. It also includes a Bar Panel for Tracy
Easily apply search criteria on Laravel 5+ queries
Log SQL queries in Laravel/Lumen framework
Bundle extension that installs and loads Semantic MediaWiki and associated extensions
Laravel package to monitor SELECT queries and offer best possible INDEX fields.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-20