laravel-websockets/src/Dashboard/Http/Controllers/DashboardApiController.php

37 lines
1.3 KiB
PHP
Raw Normal View History

2018-12-03 21:59:50 +00:00
<?php
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
class DashboardApiController
{
public function getStatistics($appId)
{
2018-12-04 13:06:16 +00:00
$webSocketsStatisticsEntryModelClass = config('websockets.statistics.model');
2018-12-03 21:59:50 +00:00
$statistics = $webSocketsStatisticsEntryModelClass::where('app_id', $appId)->latest()->limit(120)->get();
2018-12-04 08:03:27 +00:00
$statisticData = $statistics->map(function ($statistic) {
2018-12-03 21:59:50 +00:00
return [
2018-12-04 21:22:33 +00:00
'timestamp' => (string) $statistic->created_at,
2018-12-04 08:03:27 +00:00
'peak_connection_count' => $statistic->peak_connection_count,
'websocket_message_count' => $statistic->websocket_message_count,
'api_message_count' => $statistic->api_message_count,
2018-12-03 21:59:50 +00:00
];
2018-12-04 00:03:47 +00:00
})->reverse();
2018-12-03 21:59:50 +00:00
return [
2018-12-04 00:03:47 +00:00
'peak_connections' => [
2018-12-04 08:03:27 +00:00
'x' => $statisticData->pluck('timestamp'),
'y' => $statisticData->pluck('peak_connection_count'),
],
'websocket_message_count' => [
'x' => $statisticData->pluck('timestamp'),
'y' => $statisticData->pluck('websocket_message_count'),
],
'api_message_count' => [
'x' => $statisticData->pluck('timestamp'),
'y' => $statisticData->pluck('api_message_count'),
2018-12-04 21:22:33 +00:00
],
2018-12-03 21:59:50 +00:00
];
}
2018-12-04 21:22:33 +00:00
}