{"id":16749930,"url":"https://github.com/danilopolani/filament-memory-tracker","last_synced_at":"2025-10-19T19:40:22.420Z","repository":{"id":48501331,"uuid":"387237903","full_name":"danilopolani/filament-memory-tracker","owner":"danilopolani","description":"Track the memory usage of workers and Laravel queues and display them in Filament Admin Dashboard","archived":false,"fork":false,"pushed_at":"2023-02-15T16:39:30.000Z","size":178,"stargazers_count":27,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"2.x","last_synced_at":"2025-06-11T13:15:08.520Z","etag":null,"topics":["filament","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danilopolani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"danilopolani","custom":["https://www.buymeacoffee.com/theraloss"]}},"created_at":"2021-07-18T17:57:46.000Z","updated_at":"2023-08-19T14:54:42.000Z","dependencies_parsed_at":"2024-10-28T11:38:38.063Z","dependency_job_id":"e16d56e0-1fe1-460a-a903-3f259d9fd6b1","html_url":"https://github.com/danilopolani/filament-memory-tracker","commit_stats":{"total_commits":15,"total_committers":2,"mean_commits":7.5,"dds":0.06666666666666665,"last_synced_commit":"3408272fa4be98aeab30a82831349484817c719b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/danilopolani/filament-memory-tracker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Ffilament-memory-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Ffilament-memory-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Ffilament-memory-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Ffilament-memory-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danilopolani","download_url":"https://codeload.github.com/danilopolani/filament-memory-tracker/tar.gz/refs/heads/2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danilopolani%2Ffilament-memory-tracker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279490879,"owners_count":26179467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-18T02:00:06.492Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filament","laravel","php"],"created_at":"2024-10-13T02:26:31.458Z","updated_at":"2025-10-19T19:40:22.402Z","avatar_url":"https://github.com/danilopolani.png","language":"PHP","funding_links":["https://github.com/sponsors/danilopolani","https://www.buymeacoffee.com/theraloss"],"categories":[],"sub_categories":[],"readme":"# Filament Memory Tracker\n\n[![Latest Stable Version](http://poser.pugx.org/danilopolani/filament-memory-tracker/v)](https://packagist.org/packages/danilopolani/filament-memory-tracker)\n[![Total Downloads](http://poser.pugx.org/danilopolani/filament-memory-tracker/downloads)](https://packagist.org/packages/danilopolani/filament-memory-tracker)\n\nTrack the memory usage of your workers and display them in Filament.\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"https://i.imgur.com/Y5gnWfl.png\" alt=\"Filament Worker Memory widget preview\"\u003e\u003c/p\u003e\n\n\u003e If you're using Filament v1, please navigate the [1.x branch](https://github.com/danilopolani/filament-memory-tracker/tree/1.x).\n\n## Installation\n\nInstall the package via composer:\n\n```bash\ncomposer require danilopolani/filament-memory-tracker\n```\n\nThen publish the assets and the config of the package:\n\n```bash\nphp artisan vendor:publish --tag=filament-memory-tracker-assets\nphp artisan vendor:publish --tag=filament-memory-tracker-config\n```\n\n\u003e If you're upgrading from v1 to v2 please note that the namespace changed from `\\DaniloPolani\\`  to `\\DaniloPolani\\`.\n\n### Upgrade\nWhen upgrading be sure to republish the assets:\n\n```bash\nphp artisan vendor:publish --tag=filament-memory-tracker-assets --force\n```\n\n## Configuration\n\nThere are a few notable configuration options for the package.\n\nKey | Type | Description\n------------ | ------------- | -------------\n`cache_store` | String | Define the cache store used to track memory usage. By default it will be your `CACHE_DRIVER` env value.\n`trackers` | Array | A list of trackers names to be displayed in the dashboard. They must be the same used in your `MemoryTracker()` instance. See **Usage** below to discover more.\n`date_format` | String | The [DateTime format](https://www.php.net/manual/en/datetime.format.php) to display dates.\n\n## Usage\n\nIn your Worker create a new `MemoryTracker` instance and then ping the `track()` method every time you want. There's an example with [ReactPHP Event Loop](https://reactphp.org/event-loop/).\n\n\nℹ️ | The `$realUsage` flag is the same as [memory_get_usage()](https://www.php.net/manual/en/function.memory-get-usage.php).\n:---: | :---\n\n```php\n\u003c?php\n\nnamespace App\\Console\\Commands;\n\nuse DaniloPolani\\FilamentMemoryTracker\\MemoryTracker;\nuse Illuminate\\Console\\Command;\nuse React\\EventLoop\\Loop;\n\nclass MyWorker extends Command\n{\n    /**\n     * The name and signature of the console command.\n     *\n     * @var string\n     */\n    protected $signature = 'worker:run';\n\n    /**\n     * The memory tracker instance.\n     *\n     * @var MemoryTracker\n     */\n    protected MemoryTracker $memoryTracker;\n\n    /**\n     * Class constructor.\n     */\n    public function __construct()\n    {\n        parent::__construct();\n\n        $this-\u003ememoryTracker = new MemoryTracker('Worker');\n    }\n\n    /**\n     * Execute the console command.\n     *\n     * @return int\n     */\n    public function handle()\n    {\n        // Ping every 5minutes\n        Loop::addPeriodicTimer(60 * 5, function () {\n            $this-\u003ememoryTracker-\u003etrack(bool $realUsage = false);\n        });\n\n        return 0;\n    }\n}\n```\n\nThen don't forget to add your tracker name inside the configuration too:\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n\n    'trackers' =\u003e [\n        'Worker',\n    ],\n\n];\n```\n\n### Track restarts\n\nYou can track the latest Worker restart date and memory usage as well! If you're working on a custom Worker, you should intercept the exit signals and then call the `$memoryTracker-\u003etrackRestart()` method. Otherwise you can use the Trait provided by the package to achieve that:\n\n1. Include `DaniloPolani\\FilamentMemoryTracker\\Concerns\\TracksRestart` inside your class;\n2. Call `$this-\u003etrackRestartMemory(MemoryTracker $memoryTrackerInstance)` inside your constructor.\n\n⚠️ | The `TracksRestart` requires the extension **`pcntl`** to be enabled.\n:---: | :---\n\n```php\n\u003c?php\n\nnamespace App\\Console\\Commands;\n\nuse DaniloPolani\\FilamentMemoryTracker\\MemoryTracker;\nuse DaniloPolani\\FilamentMemoryTracker\\Concerns\\TracksRestart;\nuse Illuminate\\Console\\Command;\nuse React\\EventLoop\\Loop;\n\nclass MyWorker extends Command\n{\n    use TracksRestart;\n\n    // ...\n\n    public function __construct()\n    {\n        parent::__construct();\n\n        $this-\u003ememoryTracker = new MemoryTracker('Worker');\n        $this-\u003etrackRestartMemory($this-\u003ememoryTracker);\n    }\n\n    // ...\n}\n```\n\n### Laravel Queue\n\nYou can track [Laravel Queue](laravel.com/docs/8.x/queues) too by listening to some specific events in a provider, for example your `AppServiceProvider`.\n\n```php\n\u003c?php\n\nnamespace App\\Providers;\n\nuse DaniloPolani\\FilamentMemoryTracker\\MemoryTracker;\nuse Filament\\Filament;\nuse Illuminate\\Queue\\Events\\Looping;\nuse Illuminate\\Queue\\Events\\WorkerStopping;\nuse Illuminate\\Support\\Facades\\Event;\nuse Illuminate\\Support\\ServiceProvider;\n\nclass AppServiceProvider extends ServiceProvider\n{\n    /**\n     * Bootstrap any application services.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        $memoryTracker = new MemoryTracker('Queue');\n\n        // Track memory usage\n        Event::listen(Looping::class, function () use ($memoryTracker) {\n            $memoryTracker-\u003etrack();\n        });\n\n        // Track restarts\n        Event::listen(WorkerStopping::class, function () use ($memoryTracker) {\n            $memoryTracker-\u003etrackRestart();\n        });\n    }\n}\n```\n\n### Additional notes\n\n- The widget will refresh every 5s automatically;\n- By default the widget will be shown full-width if there's more than 1 tracker; otherwise, the widget will be a single block:\n\n\u003cimg src=\"https://i.imgur.com/Gg3whu1.png\" alt=\"Memory Tracker widget single block\" width=\"50%\"\u003e\n\n## APIs\n\nThese are the available methods of the `MemoryTracker` class:\n\nKey | Description\n------------ | -------------\n`track(): void` | Track the current memory usage for the worker.\n`trackRestart(bool $resetPeak = true): void` | Track a restart. If `$resetPeak` is true, the memory peak will be purged as well.\n`getHistory(): array` | Get the worker's history of memory usage.\n`getPeak(): array\\|null` | Get the worker's memory peak. Returns `null` if no peak found.\n`getLatestRestart(): array\\|null` | Get the worker's latest restart data. Returns `null` if no restart found.\n`purge(): void` | Purge all the data of the current worker.\n`purgeHistory(): void` | Purge the track history only of the current worker.\n`purgePeak(): void` | Purge the memory peak of the current worker.\n`purgeRestart(): void` | Purge the latest restart data of the current worker.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email danilo.polani@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Danilo Polani](https://github.com/danilopolani)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Laravel Package Boilerplate\n\nThis package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilopolani%2Ffilament-memory-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanilopolani%2Ffilament-memory-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanilopolani%2Ffilament-memory-tracker/lists"}