├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── codecov.yml ├── composer.json ├── resources └── views │ ├── cache │ └── tile.blade.php │ ├── database │ └── tile.blade.php │ └── environment │ ├── chart.blade.php │ └── tile.blade.php └── src ├── Charts ├── BarChart.php └── ChartType.php ├── Commands ├── Concerns │ └── VaporMetricsCommandTrait.php ├── FetchVaporCacheMetricsCommand.php ├── FetchVaporDatabaseMetricsCommand.php └── FetchVaporEnvironmentMetricsCommand.php ├── Components ├── Concerns │ └── VaporMetricsComponentTrait.php ├── VaporCacheMetricsComponent.php ├── VaporDatabaseMetricsComponent.php ├── VaporEnvironmentMetricsChartComponent.php └── VaporEnvironmentMetricsComponent.php ├── Stores ├── Concerns │ └── VaporMetricsStoreTrait.php ├── VaporCacheMetricsStore.php ├── VaporDatabaseMetricsStore.php └── VaporEnvironmentMetricsStore.php ├── VaporMetricsClient.php └── VaporMetricsTileServiceProvider.php /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `fidum/laravel-dashboard-vapor-metrics-tile` will be documented in this file 4 | 5 | ## 4.2.0 - 2025-02-24 6 | 7 | ### What's Changed 8 | 9 | * Run tests on PHP 8.4 by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/17 10 | * Add support for Laravel 12.x by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/18 11 | 12 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/compare/4.1.0...4.2.0 13 | 14 | ## 4.1.0 - 2024-03-13 15 | 16 | ### What's Changed 17 | 18 | * Support Laravel 11 by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/16 19 | 20 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/compare/4.0.0...4.1.0 21 | 22 | ## 4.0.0 - 2023-12-02 23 | 24 | ### What's Changed 25 | 26 | * Run tests on PHP 8.3 by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/14 27 | * Update to Laravel Dashboard 3.x and Chart Tile 6.x by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/15 28 | 29 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/compare/3.0.1...4.0.0 30 | 31 | ## 3.0.1 - 2023-02-08 32 | 33 | ### What's Changed 34 | 35 | - Add Laravel 10 Support by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/13 36 | 37 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/compare/3.0.0...3.0.1 38 | 39 | ## 3.0.0 - 2022-08-19 40 | 41 | ### What's Changed 42 | 43 | - Upgraded [fidum/laravel-dashboard-chart-tile](https://github.com/fidum/laravel-dashboard-chart-tile) to 5.0.0 by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/12 44 | 45 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/compare/2.1.0...3.0.0 46 | 47 | ## 2.1.0 - 2022-02-10 48 | 49 | ## What's Changed 50 | 51 | - Run tests on PHP 8.1 by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/9 52 | - Add Laravel 9 Support by @dmason30 in https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/10 53 | 54 | **Full Changelog**: https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/compare/2.0.1...2.1.0 55 | 56 | ## 2.0.1 - 2020-12-12 57 | 58 | **Added** 59 | 60 | - Added PHP 8 Support 61 | 62 | ## 2.0.0 - 2020-09-10 63 | 64 | **Added** 65 | 66 | - Added Laravel 8 Support 67 | - Added `spatie/laravel-dashboard` 2.0.0 support 68 | 69 | **Changed** 70 | 71 | - Upgraded [fidum/laravel-dashboard-chart-tile](https://github.com/fidum/laravel-dashboard-chart-tile) to 4.0.0 72 | 73 | **Breaking** 74 | 75 | - Dropped Laravel 7 support 76 | - Dropped `spatie/laravel-dashboard` 1.x support 77 | 78 | ## 1.3.0 - 2020-07-05 79 | 80 | **Changed** 81 | 82 | - Upgraded [fidum/laravel-dashboard-chart-tile](https://github.com/fidum/laravel-dashboard-chart-tile) to v3 83 | 84 | ## 1.2.0 - 2020-04-15 85 | 86 | **Changed** 87 | 88 | - Changed charts to use [fidum/laravel-dashboard-chart-tile](https://github.com/fidum/laravel-dashboard-chart-tile) internally ([#2](https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/pull/2)) 89 | 90 | ## 1.1.0 - 2020-04-09 91 | 92 | **Added** 93 | 94 | - Added charts tiles! 95 | 96 | ## 1.0.1 - 2020-04-07 97 | 98 | **Fixed** 99 | 100 | - Fixed docs folder no longer downloaded when package is installed 101 | 102 | ## 1.0.0 - 2020-04-06 103 | 104 | **Added** 105 | 106 | - Added tests with full coverage! 107 | 108 | ## 0.0.1 - 2020-04-06 109 | 110 | - initial release 111 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) :vendor_name 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vapor Metrics Tile 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/fidum/laravel-dashboard-vapor-metrics-tile.svg?style=for-the-badge)](https://packagist.org/packages/fidum/laravel-dashboard-vapor-metrics-tile) 4 | [![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/fidum/laravel-dashboard-vapor-metrics-tile/run-tests.yml?branch=main&style=for-the-badge)](https://github.com/fidum/laravel-dashboard-vapor-metrics-tile/actions?query=workflow%3Arun-tests+branch%3Amaster) 5 | [![Codecov](https://img.shields.io/codecov/c/github/fidum/laravel-dashboard-vapor-metrics-tile?logo=codecov&logoColor=white&style=for-the-badge)](https://codecov.io/gh/fidum/laravel-dashboard-vapor-metrics-tile) 6 | [![Twitter Follow](https://img.shields.io/badge/follow-%40danmasonmp-1DA1F2?logo=twitter&style=for-the-badge)](https://twitter.com/danmasonmp) 7 | 8 | Displays metrics for **all** of your laravel vapor projects - caches, databases and environment metrics and charts included! 9 | 10 | ![Preview](docs/preview.png) 11 | 12 | ## Installation 13 | 14 | You can install the package via composer: 15 | 16 | ```bash 17 | composer require fidum/laravel-dashboard-vapor-metrics-tile 18 | ``` 19 | 20 | ## Usage 21 | In the `dashboard` config file, you must add this configuration in the `tiles` key. There are separate settings for 22 | `caches`, `databases` and `environments`. 23 | 24 | ```php 25 | // in config/dashboard.php 26 | return [ 27 | // ... 28 | 'tiles' => [ 29 | 'vapor_metrics' => [ 30 | 'secret' => env('VAPOR_API_TOKEN'), // optional: Uses `VAPOR_API_TOKEN` env by default 31 | 'refresh_interval_in_seconds' => 300, // optional: Default: 300 seconds (5 minutes) 32 | 'period' => '7d', // optional: 1m, 5m, 30m, 1h, 8h, 1d (default), 3d, 7d, 1M 33 | 'caches' => [ // Leave empty if you don't want any cache tiles 34 | 'My Cache Instance' => [ // Key will be used as the title of the displayed tile 35 | 'cache_id' => 222, // required: The id of your vapor cache instance 36 | 'period' => '7d', // optional: 1m, 5m, 30m, 1h, 8h, 1d (default), 3d, 7d, 1M 37 | 'refresh_interval_in_seconds' => 60, // optional: override individual tile 38 | 'secret' => null, // :optional: override individual tile 39 | ], 40 | 'Another Cache' => ['cache_id' => 333] 41 | ], 42 | 'databases' => [ // Leave empty if you don't want any database tiles 43 | 'My Database' => [ // Key will be used as the title of the displayed tile 44 | 'database_id' => 555, // required: The id of your vapor database instance 45 | 'period' => '7d', // optional: 1m, 5m, 30m, 1h, 8h, 1d (default), 3d, 7d, 1M 46 | 'refresh_interval_in_seconds' => 60, // optional: override individual tile 47 | 'secret' => null, // :optional: override individual tile 48 | ], 49 | 'Another Database' => ['database_id' => 444] 50 | ], 51 | 'environments' => [ // Leave empty if you don't want any envrionment tiles 52 | 'My Staging Website' => [ // Key will be used as the title of the displayed tile 53 | 'project_id' => 1111, // required: The id of your vapor project 54 | 'environment' => 'staging', // optional: Defaults to 'production' 55 | 'period' => '7d', // optional: 1m, 5m, 30m, 1h, 8h, 1d (default), 3d, 7d, 1M 56 | 'refresh_interval_in_seconds' => 60, // optional: override individual tile 57 | 'secret' => null, // :optional: override individual tile 58 | ], 59 | 'My Production Website' => ['project_id' => 1111], 60 | ], 61 | ], 62 | ], 63 | ]; 64 | ``` 65 | 66 | In `app\Console\Kernel.php` you should schedule the below to run every `x` minutes. Only add the commands where you have configured the related tiles above. 67 | 68 | ```php 69 | // in app/console/Kernel.php 70 | protected function schedule(Schedule $schedule) 71 | { 72 | $schedule->command(\Fidum\VaporMetricsTile\Commands\FetchVaporCacheMetricsCommand::class)->everyThirtyMinutes(); 73 | $schedule->command(\Fidum\VaporMetricsTile\Commands\FetchVaporDatabaseMetricsCommand::class)->everyThirtyMinutes(); 74 | $schedule->command(\Fidum\VaporMetricsTile\Commands\FetchVaporEnvironmentMetricsCommand::class)->everyThirtyMinutes(); 75 | } 76 | ``` 77 | 78 | In your dashboard view you can use one or all or multiple of each of these components. The `tileName` and `position` 79 | attributes are **required**. The `tileName` attribute value needs to match the name specified in the config: 80 | 81 | ```blade 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | ``` 94 | 95 | For charts an additional `type` value should be provided to select which chart to show: 96 | 97 | - `cli-avg-duration`: Average CLI Invocation Duration (ms) 98 | - `cli-invocations-total`: CLI Invocations 99 | - `http-requests-avg-duration`: Average HTTP Request Duration (ms) 100 | - `http-requests-total`: HTTP Requests 101 | - `queue-avg-duration`: Average Queue Invocation Duration (ms) 102 | - `queue-invocations-total`: Queue Invocations 103 | 104 | The charts use [fidum/laravel-dashboard-chart-tile](https://github.com/fidum/laravel-dashboard-chart-tile) internally. 105 | You can use the below additional properties for further customisation: 106 | 107 | - `height` sets the height of the chart, depending on your dashboard layout you may need to adjust this (defaults to `100%`). 108 | - `refreshIntervalInSeconds` use this to override the refresh rate of an individual tile (defaults to above configured setting) 109 | 110 | ## Testing 111 | ```bash 112 | composer test 113 | ``` 114 | 115 | ## Changelog 116 | 117 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 118 | 119 | ## Contributing 120 | 121 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 122 | 123 | ## Security 124 | 125 | If you discover any security related issues, please email :author_email instead of using the issue tracker. 126 | 127 | ## Credits 128 | 129 | - [All Contributors](../../contributors) 130 | 131 | ## License 132 | 133 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 134 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | informational: true 6 | patch: 7 | default: 8 | informational: true 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fidum/laravel-dashboard-vapor-metrics-tile", 3 | "description": "Vapor environment, cache and database metrics tiles for laravel dashboard", 4 | "keywords": [ 5 | "fidum", 6 | "laravel-dashboard", 7 | "laravel-dashboard-vapor-metrics-tile", 8 | "vapor" 9 | ], 10 | "homepage": "https://github.com/fidum/laravel-dashboard-vapor-metrics-tile", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Daniel Mason", 15 | "email": "fidum.dev@gmail.com", 16 | "homepage": "https://fidum.uk", 17 | "role": "Developer" 18 | } 19 | ], 20 | "require": { 21 | "php": "^8.1", 22 | "fidum/laravel-dashboard-chart-tile": "^6.0", 23 | "laravel/vapor-cli": "^1.60", 24 | "spatie/laravel-dashboard": "^3.0" 25 | }, 26 | "require-dev": { 27 | "mockery/mockery": "^1.5", 28 | "orchestra/testbench": "^8.0|^9.0|^10.0", 29 | "phpunit/phpunit": "^10.5|^11.5.3" 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "Fidum\\VaporMetricsTile\\": "src" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Fidum\\VaporMetricsTile\\Tests\\": "tests" 39 | } 40 | }, 41 | "scripts": { 42 | "test": "vendor/bin/phpunit" 43 | }, 44 | "config": { 45 | "sort-packages": true 46 | }, 47 | "extra": { 48 | "laravel": { 49 | "providers": [ 50 | "Fidum\\VaporMetricsTile\\VaporMetricsTileServiceProvider" 51 | ] 52 | } 53 | }, 54 | "minimum-stability": "dev", 55 | "prefer-stable": true 56 | } 57 | -------------------------------------------------------------------------------- /resources/views/cache/tile.blade.php: -------------------------------------------------------------------------------- 1 | @php 2 | $nodeCount = count($data['totalCacheHits'] ?? [[]]); 3 | $displayNodeClass = $nodeCount > 1 ? 'pl-2' : null; 4 | @endphp 5 | 9 |
10 |
11 |

{{$tileName}}

12 |
13 | 33 |
34 |
35 | -------------------------------------------------------------------------------- /resources/views/database/tile.blade.php: -------------------------------------------------------------------------------- 1 | 5 |
6 |
7 |

{{$tileName}}

8 |
9 | 20 |
21 |
22 | -------------------------------------------------------------------------------- /resources/views/environment/chart.blade.php: -------------------------------------------------------------------------------- 1 | @php /** @var \Fidum\VaporMetricsTile\Charts\BarChart $chart */ @endphp 2 | 3 | @livewire('chart-tile', [ 4 | 'chartFactory' => \Fidum\VaporMetricsTile\Charts\BarChart::class, 5 | 'chartFilters' => compact('tileName', 'type'), 6 | 'height' => $height, 7 | 'position' => $position, 8 | 'refreshIntervalInSeconds' => $refreshIntervalInSeconds 9 | ]) 10 | -------------------------------------------------------------------------------- /resources/views/environment/tile.blade.php: -------------------------------------------------------------------------------- 1 | 5 |
6 |
7 |

{{$tileName}}

8 |
9 | 32 |
33 |
34 | -------------------------------------------------------------------------------- /src/Charts/BarChart.php: -------------------------------------------------------------------------------- 1 | tileName = $tileName; 20 | $this->chartType = $chartType; 21 | } 22 | 23 | public static function make(array $settings): ChartFactory 24 | { 25 | $defaultTile = Arr::get(array_keys(config('dashboard.tiles.vapor_metrics.environments', [])), 0, ''); 26 | 27 | return new static( 28 | Arr::get($settings, 'tileName', $defaultTile), 29 | Arr::get($settings, 'type', ChartType::DEFAULT) 30 | ); 31 | } 32 | 33 | public function chart(): Chart 34 | { 35 | $chart = new Chart(); 36 | 37 | $key = VaporEnvironmentMetricsStore::key($this->tileName); 38 | $metrics = VaporEnvironmentMetricsStore::make()->metrics($key); 39 | $field = ChartType::field($this->chartType); 40 | $data = collect($metrics[$field] ?? []); 41 | 42 | $dataset = $data->map(fn ($metric, $date) => [ 43 | 'x' => $date, 44 | 'y' => number_format($metric, 0, '.', ''), 45 | ])->values(); 46 | 47 | $chart 48 | ->loader(false) 49 | ->labels($data->keys()) 50 | ->options($this->options(), true) 51 | ->dataset(ChartType::label($this->tileName, $this->chartType), 'bar', $dataset) 52 | ->backgroundColor('#848584'); 53 | 54 | return $chart; 55 | } 56 | 57 | private function options(): array 58 | { 59 | return [ 60 | 'animation' => [ 61 | 'duration' => 0, 62 | ], 63 | 'responsive' => true, 64 | 'maintainAspectRatio' => false, 65 | 'legend' => [ 66 | 'display' => true, 67 | 'labels' => [ 68 | 'boxWidth' => 0, 69 | ], 70 | ], 71 | 'scales' => [ 72 | 'xAxes' => [[ 73 | 'display' => true, 74 | 'offset' => true, 75 | 'type' => 'time', 76 | 'ticks' => [ 77 | 'source' => 'auto', 78 | 'maxRotation' => 0, 79 | ], 80 | 'time' => [ 81 | 'unit' => $this->unit(), 82 | 'round' => true, 83 | 'displayFormats' => [ 84 | 'second' => 'hh:mm:ss', 85 | 'minute' => 'hh:mm a', 86 | 'hour' => 'hh:mm a', 87 | 'day' => 'MMM D', 88 | 'week' => 'MMM D', 89 | ], 90 | ], 91 | ]], 92 | ], 93 | ]; 94 | } 95 | 96 | private function period(): string 97 | { 98 | $tileConfig = config('dashboard.tiles.vapor_metrics.environments.'.$this->tileName) ?? []; 99 | 100 | return $tileConfig['period'] 101 | ?? config('dashboard.tiles.vapor_metrics.period') 102 | ?? VaporMetricsClient::DEFAULT_PERIOD; 103 | } 104 | 105 | private function unit(): string 106 | { 107 | $periodString = Str::of($this->period()); 108 | 109 | $oneUnit = filter_var($periodString, FILTER_SANITIZE_NUMBER_INT) === '1'; 110 | 111 | $availableUnits = [ 112 | 'm' => $oneUnit ? 'second' : 'minute', 113 | 'h' => $oneUnit ? 'minute' : 'hour', 114 | 'd' => $oneUnit ? 'hour' : 'day', 115 | 'M' => $oneUnit ? 'day' : 'week', 116 | ]; 117 | 118 | $unit = (string) $periodString->substr(-1); 119 | 120 | return $availableUnits[$unit] ?? 'hour'; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Charts/ChartType.php: -------------------------------------------------------------------------------- 1 | [ 13 | 'label' => 'Average CLI Invocation Duration (ms)', 14 | 'field' => 'averageCliFunctionDurationByInterval', 15 | ], 16 | 'cli-invocations-total' => [ 17 | 'label' => 'CLI Invocations', 18 | 'field' => 'totalCliFunctionInvocationsByInterval', 19 | ], 20 | 'http-requests-avg-duration' => [ 21 | 'label' => 'Average HTTP Request Duration (ms)', 22 | 'field' => 'averageFunctionDurationByInterval', 23 | ], 24 | 'http-requests-total' => [ 25 | 'label' => 'HTTP Requests', 26 | 'field' => 'totalFunctionInvocationsByInterval', 27 | ], 28 | 'queue-avg-duration' => [ 29 | 'label' => 'Average Queue Invocation Duration (ms)', 30 | 'field' => 'averageQueueFunctionDurationByInterval', 31 | ], 32 | 'queue-invocations-total' => [ 33 | 'label' => 'Queue Invocations', 34 | 'field' => 'totalQueueFunctionInvocationsByInterval', 35 | ], 36 | ]; 37 | 38 | public static function field(string $type = self::DEFAULT): string 39 | { 40 | return Arr::get(static::TYPES, $type, [])['field'] ?? static::defaultField(); 41 | } 42 | 43 | public static function label(string $tileName, string $type = self::DEFAULT): string 44 | { 45 | $label = Arr::get(static::TYPES, $type, [])['label'] ?? static::defaultLabel(); 46 | 47 | return "$label ($tileName)"; 48 | } 49 | 50 | private static function defaultField() 51 | { 52 | return static::TYPES[static::DEFAULT]['field']; 53 | } 54 | 55 | private static function defaultLabel() 56 | { 57 | return static::TYPES[static::DEFAULT]['label']; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Commands/Concerns/VaporMetricsCommandTrait.php: -------------------------------------------------------------------------------- 1 | each(function (array $config) { 24 | $id = $config['cache_id']; 25 | $period = $this->period($config); 26 | $secret = Arr::get($config, 'secret'); 27 | 28 | $data = VaporMetricsClient::make($secret)->cacheMetricsRaw($id, $period); 29 | 30 | VaporCacheMetricsStore::make()->setMetrics($id, $data); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Commands/FetchVaporDatabaseMetricsCommand.php: -------------------------------------------------------------------------------- 1 | each(function (array $config) { 24 | $id = $config['database_id']; 25 | $period = $this->period($config); 26 | $secret = Arr::get($config, 'secret'); 27 | 28 | $data = VaporMetricsClient::make($secret)->databaseMetricsRaw($id, $period); 29 | 30 | VaporDatabaseMetricsStore::make()->setMetrics($id, $data); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Commands/FetchVaporEnvironmentMetricsCommand.php: -------------------------------------------------------------------------------- 1 | each(function (array $config, string $name) { 24 | $id = $config['project_id']; 25 | $env = Arr::get($config, 'environment', 'production'); 26 | $period = $this->period($config); 27 | $secret = Arr::get($config, 'secret'); 28 | 29 | $data = VaporMetricsClient::make($secret)->environmentMetricsRaw($id, $env, $period); 30 | $key = VaporEnvironmentMetricsStore::key($name); 31 | 32 | VaporEnvironmentMetricsStore::make()->setMetrics($key, $data); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Components/Concerns/VaporMetricsComponentTrait.php: -------------------------------------------------------------------------------- 1 | position = $position; 20 | $this->tileName = $tileName; 21 | } 22 | 23 | public function render() 24 | { 25 | $config = config('dashboard.tiles.vapor_metrics.caches.'.$this->tileName) ?? []; 26 | $key = $config['cache_id'] ?? 0; 27 | 28 | return view('dashboard-vapor-metrics-tiles::cache.tile', [ 29 | 'data' => VaporCacheMetricsStore::make()->metrics($key), 30 | 'refreshIntervalInSeconds' => $this->refreshIntervalInSeconds($config), 31 | ]); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Components/VaporDatabaseMetricsComponent.php: -------------------------------------------------------------------------------- 1 | position = $position; 20 | $this->tileName = $tileName; 21 | } 22 | 23 | public function render() 24 | { 25 | $config = config('dashboard.tiles.vapor_metrics.databases.'.$this->tileName) ?? []; 26 | $key = $config['database_id'] ?? 0; 27 | 28 | return view('dashboard-vapor-metrics-tiles::database.tile', [ 29 | 'data' => VaporDatabaseMetricsStore::make()->metrics($key), 30 | 'refreshIntervalInSeconds' => $this->refreshIntervalInSeconds($config), 31 | ]); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Components/VaporEnvironmentMetricsChartComponent.php: -------------------------------------------------------------------------------- 1 | height = $height; 31 | $this->position = $position; 32 | $this->tileName = $tileName ?? $this->tileName ?? ''; 33 | $this->type = $type ?? $this->type ?? ChartType::DEFAULT; 34 | 35 | $config = config('dashboard.tiles.vapor_metrics.environments.'.$this->tileName) ?? []; 36 | $this->refreshIntervalInSeconds = $refreshIntervalInSeconds ?? $this->refreshIntervalInSeconds($config); 37 | } 38 | 39 | public function render() 40 | { 41 | return view('dashboard-vapor-metrics-tiles::environment.chart'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Components/VaporEnvironmentMetricsComponent.php: -------------------------------------------------------------------------------- 1 | position = $position; 20 | $this->tileName = $tileName; 21 | } 22 | 23 | public function render() 24 | { 25 | $config = config('dashboard.tiles.vapor_metrics.environments.'.$this->tileName) ?? []; 26 | $key = VaporEnvironmentMetricsStore::key($this->tileName); 27 | 28 | return view('dashboard-vapor-metrics-tiles::environment.tile', [ 29 | 'data' => VaporEnvironmentMetricsStore::make()->metrics($key), 30 | 'refreshIntervalInSeconds' => $this->refreshIntervalInSeconds($config), 31 | ]); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Stores/Concerns/VaporMetricsStoreTrait.php: -------------------------------------------------------------------------------- 1 | tile = Tile::firstOrCreateForName(static::tileName()); 19 | } 20 | 21 | /** @param string|int $key */ 22 | public function setMetrics($key, array $data): self 23 | { 24 | $this->tile->putData("metrics:$key", $data); 25 | 26 | return $this; 27 | } 28 | 29 | /** @param string|int $key */ 30 | public function metrics($key): array 31 | { 32 | return $this->tile->getData("metrics:$key") ?? []; 33 | } 34 | 35 | abstract public static function tileName(): string; 36 | } 37 | -------------------------------------------------------------------------------- /src/Stores/VaporCacheMetricsStore.php: -------------------------------------------------------------------------------- 1 | snake()->lower(); 15 | } 16 | 17 | public static function tileName(): string 18 | { 19 | return 'vapor-environment-metrics'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/VaporMetricsClient.php: -------------------------------------------------------------------------------- 1 | $secret]); 21 | } 22 | 23 | return app(static::class); 24 | } 25 | 26 | public function environmentMetricsRaw(int $projectId, string $environment, string $period): array 27 | { 28 | return $this->rawRequest( 29 | 'get', 30 | sprintf('/api/projects/%s/environments/%s/metrics?period=%s', $projectId, $environment, $period) 31 | ); 32 | } 33 | 34 | public function cacheMetricsRaw(int $cacheId, string $period): array 35 | { 36 | return $this->rawRequest( 37 | 'get', 38 | sprintf('/api/caches/%s/metrics?period=%s', $cacheId, $period) 39 | ); 40 | } 41 | 42 | public function databaseMetricsRaw(int $databaseId, string $period): array 43 | { 44 | return $this->rawRequest( 45 | 'get', 46 | sprintf('/api/databases/%s/metrics?period=%s', $databaseId, $period), 47 | ); 48 | } 49 | 50 | private function rawRequest(string $method, string $uri, array $json = []): array 51 | { 52 | return rescue(fn () => $this->requestWithoutErrorHandling($method, $uri, $json) ?? [], []); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/VaporMetricsTileServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 25 | $this->commands([ 26 | FetchVaporEnvironmentMetricsCommand::class, 27 | FetchVaporCacheMetricsCommand::class, 28 | FetchVaporDatabaseMetricsCommand::class, 29 | ]); 30 | } 31 | 32 | $this->publishes([ 33 | __DIR__.'/../resources/views' => resource_path('views/vendor/dashboard-vapor-metrics-tiles'), 34 | ], 'dashboard-vapor-metrics-tiles'); 35 | 36 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'dashboard-vapor-metrics-tiles'); 37 | } 38 | } 39 | --------------------------------------------------------------------------------