定制 omaralalwi/laravel-jobs-metrics 二次开发

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

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

omaralalwi/laravel-jobs-metrics

Composer 安装命令:

composer require omaralalwi/laravel-jobs-metrics

包简介

Tracks job memory consumption — works with or without Horizon, and enables long-term performance analysis via database logging.

README 文档

README

Latest Version on Packagist Total Downloads MIT Licensed

Tracks job memory consumption and execution time — works with or without Horizon, and enables long-term performance analysis via database logging.

laravel jobs metrics

Table of Contents

Installation

You can install the package via composer:

composer require omaralalwi/laravel-jobs-metrics

After installation, publish the configuration file (optional):

php artisan vendor:publish --provider="Omaralalwi\JobsMetrics\JobsMetricsServiceProvider" --tag="config"

Run the migrations to create the jobs_metrics table:

php artisan migrate

Usage

Basic Usage

Add the HasJobsMetricTracker trait to your job classes:

<?php

namespace App\Jobs;

use Omaralalwi\JobsMetrics\Traits\HasJobsMetricTracker;

class ProcessPodcast implements ShouldQueue
{
    use HasJobsMetricTracker;

    // Your job implementation...
}

That's it! Metrics will be automatically recorded in the jobs_metrics table.

Configuration

The package can be configured via the config/jobs-metrics.php file. Here are the available options:

return [
    // Enable or disable metrics tracking globally
    'track_jobs_metrics' => (bool) env('TRACK_JOBS_METRICS', true),
    // Log errors that occur during metrics tracking
    'log_errors' => (bool) env('JOBS_METRICS_LOG_ERRORS', true),
];

Viewing Job Metrics Report

The package provides a simple command to view job metrics:

# View job metrics with default options
php artisan jobs-metrics:top
# Customize display options
php artisan jobs-metrics:top --limit=20 --sort=time --days=2

The command displays a comprehensive info in CLI.

Available options:

  • --limit=N: Number of jobs to display (default: 10)
  • --sort=memory|time: Sort by memory usage or execution time (default: memory)
  • --days=N: Show data from the last N days (default: 7)

Exporting Job Metrics

You can export all job metrics to a single JSON file:

# Export job metrics to JSON with default options
php artisan jobs-metrics:export
# Specify a custom time period
php artisan jobs-metrics:export --days=2

The export command creates a comprehensive JSON file in the storage/app/jobs-metrics-export directory with timestamps in the filename.

Manually Cleaning Up Old Records

You can manually clean up old metrics records using the provided artisan command:

php artisan jobs-metrics:cleanup

To specify how many days of data to keep:

php artisan jobs-metrics:cleanup --days=5

Automatic Cleanup

To enable automatic cleanup, ensure your Laravel scheduler is running, and add following scheduler

Schedule::command('jobs-metrics:cleanup')->weekly();

Features

  • 📊 Records detailed metrics for each job execution (memory usage, duration)
  • 🔄 Works with or without Laravel Horizon
  • 📋 Per-job statistics including average executions per day
  • 📊 Queue-based metrics to identify bottlenecks
  • 📁 Export capabilities to JSON for further analysis
  • 🧹 Automatic and manual cleanup of old records
  • 🎛️ Highly configurable with simple interface
  • 🔌 Simple integration with a single trait
  • 📋 Tested.

Testing

composer test

Credits

License

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

📚 Helpful Open Source Packages & Projects

Packages

  • lexi translate Lexi Translate simplify managing translations for multilingual Eloquent models with power of morph relationships and caching .

  • Gpdf Gpdf Open Source HTML to PDF converter for PHP & Laravel Applications, supports Arabic content out-of-the-box and other languages.

  • laravel Taxify laravel Taxify Laravel Taxify provides a set of helper functions and classes to simplify tax (VAT) calculations within Laravel applications.

  • laravel Deployer laravel Deployer Streamlined Deployment for Laravel and Node.js apps, with Zero-Downtime and various environments and branches.

  • laravel Trash Cleaner laravel Trash Cleaner clean logs and debug files for debugging packages.

  • laravel Time Craft laravel Time Craft simple trait and helper functions that allow you, Effortlessly manage date and time queries in Laravel apps.

  • PHP builders PHP builders sample php traits to add ability to use builder design patterns with easy in PHP applications.

  • PhpPy - PHP Python PhpPy - PHP Python Interact with python in PHP applications.

  • Laravel Py - Laravel Python Laravel Py - Laravel Python interact with python in Laravel applications.

  • Deepseek PHP client deepseek PHP client robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities .

  • deepseek laravel deepseek laravel Laravel wrapper for Deepseek PHP client to seamless deepseek AI API integration with Laravel applications.

  • Qwen PHP client Qwen PHP client robust and community-driven PHP client library for seamless integration with the Qwen API .

  • qwen laravel Laravel qwen wrapper for qwen PHP client to seamless Alibaba qwen AI API integration with Laravel applications..

Dashboards

  • Laravel Startkit Laravel Startkit Laravel Admin Dashboard, Admin Template with Frontend Template, for scalable Laravel projects.

  • Kunafa Dashboard Vue Kunafa Dashboard Vue A feature-rich Vue.js 3 dashboard template with multi-language support and full RTL/LTR bidirectional layout capabilities.

References

omaralalwi/laravel-jobs-metrics 适用场景与选型建议

omaralalwi/laravel-jobs-metrics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 14, 最近一次更新时间为 2025 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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