Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit b4b6ec9

Browse files
committed
Merge branch 'master' of github.com:beyondcode/laravel-websockets
2 parents 016a6f4 + df25725 commit b4b6ec9

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

resources/views/dashboard.blade.php

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
<div class="card-body">
3737
<div v-if="connected && app.statisticsEnabled">
38-
<h4>Peak Connections</h4>
38+
<h4>Realtime Statistics</h4>
3939
<div id="statisticsChart" style="width: 100%; height: 250px;"></div>
4040
</div>
4141
<div v-if="connected">
@@ -147,19 +147,38 @@
147147
148148
loadChart() {
149149
$.getJSON('/{{ request()->path() }}/api/'+this.app.id+'/statistics', (data) => {
150-
this.chart = Plotly.plot('statisticsChart', [{
151-
x: data.peak_connections.x,
152-
y: data.peak_connections.y,
153-
mode: 'lines',
154-
line: {color: '#80CAF6'}
155-
}], {
156-
margin: {
157-
l: 0,
158-
r: 0,
159-
b: 0,
160-
t: 50,
161-
pad: 4
162-
} });
150+
151+
let chartData = [
152+
{
153+
x: data.peak_connections.x,
154+
y: data.peak_connections.y,
155+
type: 'lines',
156+
name: '# Peak Connections'
157+
},
158+
{
159+
x: data.websocket_message_count.x,
160+
y: data.websocket_message_count.y,
161+
type: 'bar',
162+
name: '# Websocket Messages'
163+
},
164+
{
165+
x: data.api_message_count.x,
166+
y: data.api_message_count.y,
167+
type: 'bar',
168+
name: '# API Messages'
169+
}
170+
];
171+
let layout = {
172+
margin: {
173+
l: 50,
174+
r: 0,
175+
b: 50,
176+
t: 50,
177+
pad: 4
178+
}
179+
};
180+
181+
this.chart = Plotly.newPlot('statisticsChart', chartData, layout);
163182
});
164183
},
165184
@@ -186,11 +205,11 @@
186205
this.pusher.subscribe('{{ \BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger::LOG_CHANNEL_PREFIX }}statistics')
187206
.bind('statistics-updated', (data) => {
188207
var update = {
189-
x: [[data.time]],
190-
y: [[data.peak_connection_count]]
208+
x: [[data.time], [data.time], [data.time]],
209+
y: [[data.peak_connection_count], [data.websocket_message_count], [data.api_message_count]]
191210
};
192211
193-
Plotly.extendTraces('statisticsChart', update, [0]);
212+
Plotly.extendTraces('statisticsChart', update, [0, 1, 2]);
194213
});
195214
},
196215

src/Dashboard/Http/Controllers/DashboardApiController.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@ public function getStatistics($appId)
99
$webSocketsStatisticsEntryModelClass = config('websockets.statistics_model');
1010
$statistics = $webSocketsStatisticsEntryModelClass::where('app_id', $appId)->latest()->limit(120)->get();
1111

12-
$peakConnections = $statistics->map(function ($statistic) {
12+
$statisticData = $statistics->map(function ($statistic) {
1313
return [
1414
'timestamp' => (string)$statistic->created_at,
15-
'count' => $statistic->peak_connection_count
15+
'peak_connection_count' => $statistic->peak_connection_count,
16+
'websocket_message_count' => $statistic->websocket_message_count,
17+
'api_message_count' => $statistic->api_message_count,
1618
];
1719
})->reverse();
1820

1921
return [
2022
'peak_connections' => [
21-
'x' => $peakConnections->pluck('timestamp'),
22-
'y' => $peakConnections->pluck('count'),
23+
'x' => $statisticData->pluck('timestamp'),
24+
'y' => $statisticData->pluck('peak_connection_count'),
25+
],
26+
'websocket_message_count' => [
27+
'x' => $statisticData->pluck('timestamp'),
28+
'y' => $statisticData->pluck('websocket_message_count'),
29+
],
30+
'api_message_count' => [
31+
'x' => $statisticData->pluck('timestamp'),
32+
'y' => $statisticData->pluck('api_message_count'),
2333
]
2434
];
2535
}

0 commit comments

Comments
 (0)