定制 atmos/laravel-db-sentinel 二次开发

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

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

atmos/laravel-db-sentinel

最新稳定版本:v1.0.0-beta.1

Composer 安装命令:

composer require atmos/laravel-db-sentinel

包简介

Smart database query monitoring and optimization tool for Laravel 7+.

README 文档

README

Latest Version on Packagist Total Downloads License

Laravel DB Sentinel is a smart database query monitoring and optimization tool for Laravel 7+. It helps Laravel applications track, analyze and optimize database behavior with insights on slow or inefficient queries and actionable performance feedback.

⚠️ Beta Version
This package is currently in Beta. Expect frequent updates and potential breaking changes until we reach version 1.0.0. Please report any issues or bugs on the GitHub repository.

✨ Features

  • 📊 Quick Dashboard — A clean UI to visualize your database status.
  • 🔍 Query Monitoring — Automatically capture and log all database queries executed by your application.
  • 🐢 Slow Query Detection — Highlight queries that exceed a configurable execution threshold.
  • 📈 Performance Insights — Collect statistics like query counts, total time spent, and slow query summaries.
  • 🧪 Developer-Friendly Output — Easy logs or debug output to help you optimize during development.
  • 🛡️ Built-in Authorization: — Restrict access to specific users via User IDs.
  • ⚙️ Configurable & Lightweight — Enable or disable features via config — no performance impact in production.

📦 Installation

Install Laravel DB Sentinel via Composer:

composer require atmos/laravel-db-sentinel

⚠️ Important: Run Migrations

After installing the package, you must run:

php artisan migrate

Laravel Auto-Discovery

This package supports Laravel's package auto-discovery, so no manual registration is required.

If auto-discovery is disabled, manually register the service provider in config/app.php:

'providers' => [
    Atmos\DbSentinel\DbSentinelServiceProvider::class,
],

🔧 Publishing Package Resources

Laravel DB Sentinel allows you to publish its resources so you can customize them inside your application.

📄 Publish Configuration File

Publish the configuration file to config/db-sentinel.php:

php artisan vendor:publish --tag=db-sentinel-config

🎨 Publish View Files

If the package provides Blade views, publish them with:

php artisan vendor:publish --tag=db-sentinel-views

Published views will be located in:

resources/views/vendor/db-sentinel/

You can safely modify these views without affecting the core package.

💡 Tip: You can run php artisan vendor:publish without arguments to interactively choose which resources to publish.

⚙️ Configuration

DB Sentinel is designed to work out of the box, but you can customize its behavior using the following environment variables in your .env file.

🔌 General & Storage

Variable Description Default
DB_SENTINEL_ENABLED Toggle the entire monitoring system. true
DB_SENTINEL_CONNECTION DB connection to store the DB Sentinel logs (e.g., mysql). Your application's default database connection
DB_SENTINEL_LOGS_TABLE The name of the table for stored logs. sentinel_logs
DB_SENTINEL_PRUNE_DAYS Auto-delete logs older than X days. 30
DB_SENTINEL_SCHEDULE_ENABLED Auto-schedule pruning command. true

⚡ Performance & Scope

Variable Description Default
DB_SENTINEL_QUEUE_NAME Queue for background analysis jobs. default
DB_SENTINEL_ALLOWED_CONS Connections to monitor (comma-separated). mysql,mariadb,pgsql,sqlsrv
DB_SENTINEL_IGNORED_CONS Connections to skip (comma-separated). sqlite,testing

🖥️ Dashboard & Security

Variable Description Default
DB_SENTINEL_DASHBOARD Enable or disable the Web UI. true
DB_SENTINEL_PATH The URL slug to access the dashboard. db-sentinel
DB_SENTINEL_USER_IDS Authorized User IDs (comma-separated). (empty)

📝 Example .env Setup

# Core Settings
DB_SENTINEL_ENABLED=true
DB_SENTINEL_PRUNE_DAYS=14
DB_SENTINEL_SCHEDULE_ENABLED=true

# Storage & Connection
DB_SENTINEL_LOGS_TABLE=custom_sentinel_logs
DB_SENTINEL_CONNECTION=mysql

# Dashboard Access
DB_SENTINEL_PATH=admin/db-metrics
DB_SENTINEL_USER_IDS=1,25

⚠️ Important Logic & Security Notes

🔄 Connection Precedence

When configuring your monitoring scope, please note the following hierarchy:

  • DB_SENTINEL_IGNORED_CONS always takes precedence.
  • If a connection is listed in both "allowed" and "ignored," it will be ignored.
  • Ensure your primary connection is not accidentally added to the ignored list.

🔒 Dashboard Access

Caution

Be cautious when setting DB_SENTINEL_USER_IDS. This variable controls who can view your database performance metrics and raw SQL queries.

  • Ensure you only input the numeric IDs of trusted administrators.
  • If left empty while DB_SENTINEL_DASHBOARD is true, access will depend solely on your auth middleware, which may be too permissive depending on your app's setup.

🧹 Pruning

Auto-Pruning

By default, DB Sentinel schedules a daily cleanup of old logs.

Configuration

You can control this behavior in your .env:

# How many days to keep logs
DB_SENTINEL_PRUNE_DAYS=30

# Enable/Disable the automatic daily background task
DB_SENTINEL_SCHEDULE_ENABLED=true

Tip

If you set DB_SENTINEL_SCHEDULE_ENABLED=false, the package will not register the task. You can then manually add php artisan db-sentinel:prune to your own Scheduler at a specific time that suits your server load.

🧹 Manual Pruning

If you want to clear old logs immediately without waiting for the automated scheduler, you can run the built-in Artisan command.

Usage

Run the following command in your terminal:

php artisan db-sentinel:prune

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固