2018-12-03 21:59:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
class DashboardApiController
|
|
|
|
|
{
|
|
|
|
|
public function getStatistics($appId)
|
|
|
|
|
{
|
|
|
|
|
$webSocketsStatisticsEntryModelClass = config('websockets.statistics_model');
|
|
|
|
|
$statistics = $webSocketsStatisticsEntryModelClass::where('app_id', $appId)->latest()->limit(120)->get();
|
|
|
|
|
|
|
|
|
|
$peakConnections = $statistics->map(function ($statistic) {
|
|
|
|
|
return [
|
2018-12-04 00:03:47 +00:00
|
|
|
'timestamp' => (string)$statistic->created_at,
|
|
|
|
|
'count' => $statistic->peak_connection_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' => [
|
|
|
|
|
'x' => $peakConnections->pluck('timestamp'),
|
|
|
|
|
'y' => $peakConnections->pluck('count'),
|
|
|
|
|
]
|
2018-12-03 21:59:50 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|