[增加]Metrics在表格中数据显示
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\MetricResource\Pages;
|
||||
use App\Filament\Resources\MetricResource\RelationManagers;
|
||||
use App\Livewire\MetricWidgetChart;
|
||||
use App\Models\Metric;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
@@ -16,6 +16,7 @@ use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use LaraZeus\InlineChart\Tables\Columns\InlineChart;
|
||||
|
||||
class MetricResource extends Resource
|
||||
{
|
||||
@@ -111,7 +112,15 @@ class MetricResource extends Resource
|
||||
}
|
||||
}),
|
||||
TextColumn::make('help')
|
||||
->label('帮助')
|
||||
->label('帮助'),
|
||||
|
||||
InlineChart::make('data')
|
||||
->label('数据')
|
||||
->chart(MetricWidgetChart::class)
|
||||
->maxWidth(350)
|
||||
->maxHeight(90)
|
||||
->description('')
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
||||
61
management-panel/app/Livewire/MetricWidgetChart.php
Normal file
61
management-panel/app/Livewire/MetricWidgetChart.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Services\PrometheusService;
|
||||
use LaraZeus\InlineChart\InlineChartWidget;
|
||||
|
||||
class MetricWidgetChart extends InlineChartWidget
|
||||
{
|
||||
protected function getData(): array
|
||||
{
|
||||
$prometheus = new PrometheusService();
|
||||
|
||||
$query1 = $this->record->name . '{data="real"}';
|
||||
$query2 = $this->record->name . '{data="simulate"}';
|
||||
|
||||
$start = now()->subDays(1)->timestamp;
|
||||
$end = now()->timestamp;
|
||||
$step = 60;
|
||||
$realdata = $prometheus->queryRange($query1, $start, $end, $step);
|
||||
$simulatedata = $prometheus->queryRange($query2, $start, $end, $step);
|
||||
|
||||
// 将数据格式化为 InlineChartWidget 所需的格式
|
||||
$formattedRealData = $this->formatData($realdata, 'Real Data');
|
||||
$formattedSimulateData = $this->formatData($simulatedata, 'Simulate Data');
|
||||
|
||||
return [
|
||||
'labels' => $formattedRealData['labels'],
|
||||
'datasets' => [
|
||||
$formattedRealData['datasets'],
|
||||
$formattedSimulateData['datasets'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Prometheus 查询结果格式化为 InlineChartWidget 所需的数据格式
|
||||
*
|
||||
* @param array $data Prometheus 查询结果
|
||||
* @param string $label 数据集标签
|
||||
* @return array 格式化后的数据
|
||||
*/
|
||||
protected function formatData(array $data, string $label): array
|
||||
{
|
||||
$labels = [];
|
||||
$dataset = [
|
||||
'label' => $label,
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
foreach ($data['data']['result'][0]['values'] as $point) {
|
||||
$labels[] = date('H:i', $point[0]);
|
||||
$dataset['data'][] = $point[1];
|
||||
}
|
||||
|
||||
return [
|
||||
'labels' => $labels,
|
||||
'datasets' => $dataset,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
"fakerphp/faker": "^1.23",
|
||||
"filament/filament": "^3.2",
|
||||
"filament/spatie-laravel-settings-plugin": "^3.2",
|
||||
"lara-zeus/inline-chart": "^1.1",
|
||||
"laravel/framework": "^11.9",
|
||||
"laravel/octane": "^2.5",
|
||||
"laravel/tinker": "^2.9",
|
||||
|
||||
250
management-panel/composer.lock
generated
250
management-panel/composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "0384a2e68cafacbc7a470648824ea732",
|
||||
"content-hash": "44cafcd7ddb03aa85528abd66ff2ccd7",
|
||||
"packages": [
|
||||
{
|
||||
"name": "anourvalar/eloquent-serialize",
|
||||
@@ -2215,6 +2215,89 @@
|
||||
],
|
||||
"time": "2024-02-16T16:06:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "lara-zeus/inline-chart",
|
||||
"version": "1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lara-zeus/inline-chart.git",
|
||||
"reference": "59afabb7ea2c8326dda9384a041c98c4a3a375f2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/lara-zeus/inline-chart/zipball/59afabb7ea2c8326dda9384a041c98c4a3a375f2",
|
||||
"reference": "59afabb7ea2c8326dda9384a041c98c4a3a375f2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"filament/filament": "^3.0",
|
||||
"php": "^8.1",
|
||||
"spatie/laravel-package-tools": "^1.16"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "^1.0",
|
||||
"nunomaduro/collision": "^7.0",
|
||||
"nunomaduro/larastan": "^2.0.1",
|
||||
"nunomaduro/phpinsights": "^2.8",
|
||||
"orchestra/testbench": "^8.0",
|
||||
"phpstan/extension-installer": "^1.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"LaraZeus\\InlineChart\\InlineChartServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"LaraZeus\\InlineChart\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "php coder",
|
||||
"email": "info@larazeus.com",
|
||||
"role": "Owner"
|
||||
}
|
||||
],
|
||||
"description": "Zeus Inline Chart easily add a chart in filamentPHP table column",
|
||||
"homepage": "https://larazeus.com/inline-chart",
|
||||
"keywords": [
|
||||
"chart",
|
||||
"coulmn",
|
||||
"design",
|
||||
"filamentphp",
|
||||
"generator",
|
||||
"inline",
|
||||
"input",
|
||||
"lara-zeus",
|
||||
"laravel",
|
||||
"mini",
|
||||
"table",
|
||||
"ui"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/lara-zeus/inline-chart/issues",
|
||||
"source": "https://github.com/lara-zeus/inline-chart"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.buymeacoffee.com/larazeus",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/atmonshi",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-02-07T10:24:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v11.21.0",
|
||||
@@ -5265,97 +5348,6 @@
|
||||
],
|
||||
"time": "2024-05-17T09:06:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/laravel-activitylog",
|
||||
"version": "4.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/spatie/laravel-activitylog.git",
|
||||
"reference": "eb6f37dd40af950ce10cf5280f0acfa3e08c3bff"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/spatie/laravel-activitylog/zipball/eb6f37dd40af950ce10cf5280f0acfa3e08c3bff",
|
||||
"reference": "eb6f37dd40af950ce10cf5280f0acfa3e08c3bff",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/config": "^8.0 || ^9.0 || ^10.0 || ^11.0",
|
||||
"illuminate/database": "^8.69 || ^9.27 || ^10.0 || ^11.0",
|
||||
"illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0",
|
||||
"php": "^8.1",
|
||||
"spatie/laravel-package-tools": "^1.6.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-json": "*",
|
||||
"orchestra/testbench": "^6.23 || ^7.0 || ^8.0 || ^9.0",
|
||||
"pestphp/pest": "^1.20 || ^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Spatie\\Activitylog\\ActivitylogServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/helpers.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Spatie\\Activitylog\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Freek Van der Herten",
|
||||
"email": "freek@spatie.be",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Sebastian De Deyne",
|
||||
"email": "sebastian@spatie.be",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Tom Witkowski",
|
||||
"email": "dev.gummibeer@gmail.com",
|
||||
"homepage": "https://gummibeer.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "A very simple activity logger to monitor the users of your website or application",
|
||||
"homepage": "https://github.com/spatie/activitylog",
|
||||
"keywords": [
|
||||
"activity",
|
||||
"laravel",
|
||||
"log",
|
||||
"spatie",
|
||||
"user"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/spatie/laravel-activitylog/issues",
|
||||
"source": "https://github.com/spatie/laravel-activitylog/tree/4.8.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://spatie.be/open-source/support-us",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/spatie",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-03-08T22:28:17+00:00"
|
||||
},
|
||||
{
|
||||
"name": "spatie/laravel-package-tools",
|
||||
"version": "1.16.4",
|
||||
@@ -8284,80 +8276,6 @@
|
||||
"source": "https://github.com/webmozarts/assert/tree/1.11.0"
|
||||
},
|
||||
"time": "2022-06-03T18:03:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "z3d0x/filament-logger",
|
||||
"version": "v0.7.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Z3d0X/filament-logger.git",
|
||||
"reference": "8a8a20b9921d1b37bb2d32bdf1c06b598685182b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Z3d0X/filament-logger/zipball/8a8a20b9921d1b37bb2d32bdf1c06b598685182b",
|
||||
"reference": "8a8a20b9921d1b37bb2d32bdf1c06b598685182b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"filament/filament": "^3.0",
|
||||
"illuminate/contracts": "^8.0 | ^9.0 | ^10.0 | ^11.0",
|
||||
"php": "^8.0 | ^8.1",
|
||||
"spatie/laravel-activitylog": "^4.5",
|
||||
"spatie/laravel-package-tools": "^1.13.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"nunomaduro/collision": "^6.0 | ^8.0",
|
||||
"nunomaduro/larastan": "^2.0.1",
|
||||
"orchestra/testbench": "^7.0 | ^9.0",
|
||||
"pestphp/pest": "^1.21 | ^2.34",
|
||||
"pestphp/pest-plugin-laravel": "^1.1 | ^2.3",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan-deprecation-rules": "^1.0",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"phpunit/phpunit": "^9.5 | ^10.5",
|
||||
"spatie/laravel-ray": "^1.26"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Z3d0X\\FilamentLogger\\FilamentLoggerServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"FilamentLogger": "Z3d0X\\FilamentLogger\\Facades\\FilamentLogger"
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Z3d0X\\FilamentLogger\\": "src",
|
||||
"Z3d0X\\FilamentLogger\\Database\\Factories\\": "database/factories"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ziyaan Hassan",
|
||||
"email": "ziyaan2010@gmail.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Activity logger for filament",
|
||||
"homepage": "https://github.com/z3d0x/filament-logger",
|
||||
"keywords": [
|
||||
"Z3d0X",
|
||||
"filament-logger",
|
||||
"laravel"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Z3d0X/filament-logger/issues",
|
||||
"source": "https://github.com/Z3d0X/filament-logger/tree/v0.7.2"
|
||||
},
|
||||
"time": "2024-06-09T12:05:25+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
||||
Reference in New Issue
Block a user