iperamuna/laravel-caddy-metrics 问题修复 & 功能扩展

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

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

iperamuna/laravel-caddy-metrics

Composer 安装命令:

composer require iperamuna/laravel-caddy-metrics

包简介

A Laravel package for visualizing Caddy server metrics with a beautiful dashboard

README 文档

README

Latest Version on Packagist Total Downloads

A beautiful, real-time metrics dashboard for Caddy server in your Laravel application. Monitor performance, visualize traffic, and optimize your FrankenPHP thread configuration with an interactive simulator.

Features

  • 📊 Real-time Metrics - Live updating charts with 5-second polling (Chart.js)
  • 🧠 Thread Optimization Advisor - Smart analysis of your Go goroutines and memory usage
  • 🎚️ Interactive Simulator - Test different safety margins to find your ideal num_threads setting
  • 🎨 Premium UI - Modern, status-reactive dashboard with distinct "System Optimal", "Can Scale", and "Caution" states
  • 📈 Core Metrics - Request counts, response sizes, goroutines, memory, and total responses
  • 🔧 Easy Installation - Interactive CLI installer for systemd (Linux) and launchd (macOS)
  • 🗑️ Data Management - Built-in commands for pruning data and clearing the entire metrics history
  • 🧪 Full Test Suite - Comprehensive Pest tests for advisor logic and data generation

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12
  • Livewire 3.x
  • Caddy server with metrics enabled (servers { metrics } in Caddyfile)
  • SQLite support

Installation

1. Install the package

composer require iperamuna/laravel-caddy-metrics

2. Publish configurations and assets

# Configuration
php artisan vendor:publish --tag=caddy-metrics-config

# Collector Binary
php artisan vendor:publish --tag=caddy-metrics-binary

# Dashboard Views (Optional for customization)
php artisan vendor:publish --tag=caddy-metrics-views

3. Install the collector service

The installer handles everything for you:

  • Installs the Go collector binary
  • Creates the systemd (Linux) or launchd (macOS) service
  • Publishes the CaddyMetricsServiceProvider for access control
  • Registers the provider in bootstrap/providers.php
# Linux (requires sudo)
sudo php artisan caddy-metrics:install

# macOS
php artisan caddy-metrics:install

3a. Configure Remote Servers

On remote servers where you cannot run the full installer or need to manage settings via environment variables, use the configuration command:

php artisan caddy-metrics:configure

This interactive command will help you set up your .env file with the correct ports, URLs, and paths for Caddy metrics. You can run it with --no-interaction in deployment scripts as long as your environment variables are already set.

4. Dashboard Authorization

To control who can access the Caddy Metrics dashboard in production, you must configure the viewCaddyMetrics gate in your app/Providers/CaddyMetricsServiceProvider.php file (created during installation).

/**
 * Register the Caddy Metrics gate.
 *
 * This gate determines who can access Caddy Metrics in non-local environments.
 *
 * @return void
 */
protected function gate()
{
    Gate::define('viewCaddyMetrics', function ($user) {
        return in_array($user->email, [
            'taylor@laravel.com',
        ]);
    });
}

By default, the dashboard is only accessible in the local environment.

Configuration

Edit config/caddy-metrics.php to match your environment:

return [
    'enabled' => env('CADDY_METRICS_ENABLED', true),
    'dashboard_url' => env('CADDY_METRICS_DASHBOARD_URL', '/caddy/metrics'),
    'frankenphp_threads' => env('FRANKENPHP_THREADS', 12),
    'caddyfile_path' => env('CADDYFILE_PATH', '/etc/frankenphp/Caddyfile'),
    'retention_days' => env('CADDY_METRICS_RETENTION_DAYS', 7),
];

Thread Optimization Advisor

The dashboard includes a dedicated Thread Advisor that analyzes your server's average and peak loads.

  • Interactive Simulation: Adjust the Safety Margin Slider to see exactly how many threads you should allocate to maintain your desired headroom.
  • Can Scale Branding: Identifies when your server has "headroom" to scale up for better performance.
  • Caddyfile Recommendations: provides copy-and-paste snippets for your Caddyfile based on simulation results.

Commands

Command Description
caddy-metrics:install Interactive installer for the collector service
caddy-metrics:configure Helper for configuring .env variables on remote servers
caddy-metrics:maintain Manage service (start/stop/restart/status/enable/disable)
caddy-metrics:generate Generate scenario-based dummy data (Optimal, High Load, Spikes, etc.)
caddy-metrics:clear Wipe all metrics data from the database (includes --force)

Service Management Examples

# Check if the collector is running
sudo php artisan caddy-metrics:maintain status

# Restart the service after config changes
sudo php artisan caddy-metrics:maintain restart

# Stop the collector
sudo php artisan caddy-metrics:maintain stop

Testing

The package includes a robust test suite using Pest.

cd packages/iperamuna/laravel-caddy-metrics
composer install
vendor/bin/pest

License

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

Author

Indunil Peramuna

iperamuna/laravel-caddy-metrics 适用场景与选型建议

iperamuna/laravel-caddy-metrics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 iperamuna/laravel-caddy-metrics 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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