定制 theihasan/dual-agent 二次开发

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

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

theihasan/dual-agent

Composer 安装命令:

composer require theihasan/dual-agent

包简介

Dual agent monitoring for Laravel Nightwatch with database storage

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads License

Dual Agent is a Laravel package that automatically saves all Nightwatch monitoring data to your application's database while maintaining full compatibility with the original Nightwatch service.

Requirements

  • PHP 8.2+
  • Laravel 10.0+
  • Laravel Nightwatch installed and configured with sampling rates set appropriately

Installation

  1. Install the package:

    composer require theihasan/dual-agent
  2. Add service providers (after Nightwatch):

    For Laravel 10: Add to config/app.php:

    'providers' => [
        // ...
        \Laravel\Nightwatch\NightwatchServiceProvider::class,
        \Ihasan\DualAgent\DualAgentServiceProvider::class,
        // ...
    ],

    For Laravel 11+: Add to bootstrap/app.php:

    'providers' => [
        \Laravel\Nightwatch\NightwatchServiceProvider::class,
        \Ihasan\DualAgent\DualAgentServiceProvider::class,
    ]
  3. Configure your .env file:

    # Nightwatch Configuration
    NIGHTWATCH_ENABLED=true
    NIGHTWATCH_TOKEN=your-nightwatch-token
    NIGHTWATCH_REQUEST_SAMPLE_RATE=1.0
    NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
    NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0
    
    # Dual Agent Configuration
    DUAL_AGENT_ENABLED=true
    DUAL_AGENT_AUTO_CONFIGURE=true
  4. Run the installer:

    php artisan dual-agent:install

Configuration

Variable Default Description
DUAL_AGENT_ENABLED true Enable/disable database storage
DUAL_AGENT_AUTO_CONFIGURE true Auto-configure when Nightwatch detected
DUAL_AGENT_BUFFER_SIZE 100 Records to buffer before database insert
DUAL_AGENT_REQUEST_SAMPLE_RATE 1.0 Sampling rate for requests (0.0-1.0)
DUAL_AGENT_QUERY_SAMPLE_RATE 0.1 Sampling rate for database queries
DUAL_AGENT_EXCEPTION_SAMPLE_RATE 1.0 Sampling rate for exceptions
DUAL_AGENT_JOB_SAMPLE_RATE 0.5 Sampling rate for queue jobs
DUAL_AGENT_LOG_SAMPLE_RATE 0.01 Sampling rate for log entries
DUAL_AGENT_CLEANUP_ENABLED true Enable automatic data cleanup
DUAL_AGENT_RETENTION_DAYS 30 Days to retain metrics data
DUAL_AGENT_AGGREGATION_ENABLED true Enable metric aggregation

Type Safety

This package includes a comprehensive PHPStan configuration for maximum type safety. The configuration is set to level 9 with strict rules enabled.

Running Type Analysis

# Run PHPStan analysis
composer run phpstan

# Generate baseline for existing issues
composer run phpstan:baseline

# Clear PHPStan cache
composer run phpstan:clear

# Run type checking and tests together
composer run test:all

Configuration Files

  • phpstan.neon - Main PHPStan configuration with strict type checking
  • phpstan-baseline.neon - Baseline file for managing existing issues

The configuration includes:

  • Level 9 strictness with all strict rules enabled
  • Laravel-specific ignores for dynamic methods and facades
  • Type coverage requirements for all methods and properties
  • Dead code detection for unused private methods and properties
  • Strict comparison rules to prevent type coercion issues
  • Missing type hints detection for all parameters and return types

Basic Usage

Query your monitoring data using the provided models:

use Ihasan\DualAgent\Models\DualAgentMetric;

// Get today's requests
$requests = DualAgentMetric::requests()->today()->get();

// Find slow requests
$slowRequests = DualAgentMetric::slowRequests(1000)->get();

// Get recent exceptions
$exceptions = DualAgentMetric::exceptions()->latest()->limit(10)->get();

See full documentation for more query examples and available scopes.

Common Issues

Data Not Appearing

Ensure Nightwatch sampling rates are set appropriately in your .env:

NIGHTWATCH_REQUEST_SAMPLE_RATE=1.0
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0

Installation Fails

Make sure Laravel Nightwatch is installed first:

composer require laravel/nightwatch
php artisan migrate

Links to Full Documentation

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Changelog

Please see CHANGELOG.md for recent changes.

Security

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

License

The MIT License (MIT). Please see License File for more information.

Credits

theihasan/dual-agent 适用场景与选型建议

theihasan/dual-agent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 theihasan/dual-agent 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-02