forked from laravel/horizon
/
dashboard.vue
335 lines (273 loc) · 12.3 KB
/
dashboard.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<script type="text/ecmascript-6">
import _ from 'lodash';
import moment from 'moment';
export default {
components: {},
/**
* The component's data.
*/
data() {
return {
stats: {},
workers: [],
workload: [],
ready: false,
};
},
/**
* Prepare the component.
*/
mounted() {
document.title = "Horizon - Dashboard";
this.refreshStatsPeriodically();
},
/**
* Clean after the component is destroyed.
*/
destroyed() {
clearTimeout(this.timeout);
},
computed: {
/**
* Determine the recent job period label.
*/
recentJobsPeriod() {
return !this.ready
? 'Jobs past hour'
: `Jobs past ${this.determinePeriod(this.stats.periods.recentJobs)}`;
},
/**
* Determine the recently failed job period label.
*/
failedJobsPeriod() {
return !this.ready
? 'Failed jobs past 7 days'
: `Failed jobs past ${this.determinePeriod(this.stats.periods.failedJobs)}`;
},
},
methods: {
/**
* Load the general stats.
*/
loadStats() {
return this.$http.get(Horizon.basePath + '/api/stats')
.then(response => {
this.stats = response.data;
if (_.values(response.data.wait)[0]) {
this.stats.max_wait_time = _.values(response.data.wait)[0];
this.stats.max_wait_queue = _.keys(response.data.wait)[0].split(':')[1];
}
});
},
/**
* Load the workers stats.
*/
loadWorkers() {
return this.$http.get(Horizon.basePath + '/api/masters')
.then(response => {
this.workers = response.data;
});
},
/**
* Load the workload stats.
*/
loadWorkload() {
return this.$http.get(Horizon.basePath + '/api/workload')
.then(response => {
this.workload = response.data;
});
},
/**
* Refresh the stats every period of time.
*/
refreshStatsPeriodically() {
Promise.all([
this.loadStats(),
this.loadWorkers(),
this.loadWorkload(),
]).then(() => {
this.ready = true;
this.timeout = setTimeout(() => {
this.refreshStatsPeriodically(false);
}, 5000);
});
},
/**
* Count processes for the given supervisor.
*/
countProcesses(processes) {
return _.chain(processes).values().sum().value().toLocaleString()
},
/**
* Format the Supervisor display name.
*/
superVisorDisplayName(supervisor, worker) {
return _.replace(supervisor, worker + ':', '');
},
/**
*
* @returns {string}
*/
humanTime(time) {
return moment.duration(time, "seconds").humanize().replace(/^(.)|\s+(.)/g, function ($1) {
return $1.toUpperCase();
});
},
/**
* Determine the unit for the given timeframe.
*/
determinePeriod(minutes) {
return moment.duration(moment().diff(moment().subtract(minutes, "minutes"))).humanize().replace(/^An?/i, '');
}
}
}
</script>
<template>
<div>
<div class="card">
<div class="card-header d-flex align-items-center justify-content-between">
<h5>Overview</h5>
</div>
<div class="card-bg-secondary">
<div class="d-flex">
<div class="w-25 border-right border-bottom">
<div class="p-4">
<small class="text-uppercase">Jobs Per Minute</small>
<h4 class="mt-4 mb-0">
{{ stats.jobsPerMinute ? stats.jobsPerMinute.toLocaleString() : 0 }}
</h4>
</div>
</div>
<div class="w-25 border-right border-bottom">
<div class="p-4">
<small class="text-uppercase" v-text="recentJobsPeriod"></small>
<h4 class="mt-4 mb-0">
{{ stats.recentJobs ? stats.recentJobs.toLocaleString() : 0 }}
</h4>
</div>
</div>
<div class="w-25 border-right border-bottom">
<div class="p-4">
<small class="text-uppercase" v-text="failedJobsPeriod"></small>
<h4 class="mt-4 mb-0">
{{ stats.failedJobs ? stats.failedJobs.toLocaleString() : 0 }}
</h4>
</div>
</div>
<div class="w-25 border-bottom">
<div class="p-4">
<small class="text-uppercase">Status</small>
<div class="d-flex align-items-center mt-4">
<svg v-if="stats.status == 'running'" class="fill-success" viewBox="0 0 20 20" style="width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM6.7 9.29L9 11.6l4.3-4.3 1.4 1.42L9 14.4l-3.7-3.7 1.4-1.42z"></path>
</svg>
<svg v-if="stats.status == 'paused'" class="fill-warning" viewBox="0 0 20 20" style="width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM7 6h2v8H7V6zm4 0h2v8h-2V6z"/>
</svg>
<svg v-if="stats.status == 'inactive'" class="fill-danger" viewBox="0 0 20 20" style=" width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm1.41-1.41A8 8 0 1 0 15.66 4.34 8 8 0 0 0 4.34 15.66zm9.9-8.49L11.41 10l2.83 2.83-1.41 1.41L10 11.41l-2.83 2.83-1.41-1.41L8.59 10 5.76 7.17l1.41-1.41L10 8.59l2.83-2.83 1.41 1.41z"/>
</svg>
<h4 class="mb-0 ml-2">{{ {running: 'Active', paused: 'Paused', inactive:'Inactive'}[stats.status] }}</h4>
<small v-if="stats.status == 'running' && stats.pausedMasters > 0" class="mb-0 ml-2">({{ stats.pausedMasters }} paused)</small>
</div>
</div>
</div>
</div>
<div class="d-flex">
<div class="w-25 border-right">
<div class="p-4 mb-0">
<small class="text-uppercase">TOTAL PROCESSES</small>
<h4 class="mt-4">
{{ stats.processes ? stats.processes.toLocaleString() : 0 }}
</h4>
</div>
</div>
<div class="w-25 border-right">
<div class="p-4 mb-0">
<small class="text-uppercase">MAX WAIT TIME</small>
<small v-if="stats.max_wait_queue">({{ stats.max_wait_queue }})</small>
<h4 class="mt-4">
{{ stats.max_wait_time ? humanTime(stats.max_wait_time) : '-' }}
</h4>
</div>
</div>
<div class="w-25 border-right">
<div class="p-4 mb-0">
<small class="text-uppercase">MAX RUNTIME</small>
<h4 class="mt-4">
{{ stats.queueWithMaxRuntime ? stats.queueWithMaxRuntime : '-' }}
</h4>
</div>
</div>
<div class="w-25">
<div class="p-4 mb-0">
<small class="text-uppercase">MAX THROUGHPUT</small>
<h4 class="mt-4">
{{ stats.queueWithMaxThroughput ? stats.queueWithMaxThroughput : '-' }}
</h4>
</div>
</div>
</div>
</div>
</div>
<div class="card mt-4" v-if="workload.length">
<div class="card-header d-flex align-items-center justify-content-between">
<h5>Current Workload</h5>
</div>
<table class="table table-hover table-sm mb-0">
<thead>
<tr>
<th>Queue</th>
<th>Processes</th>
<th>Jobs</th>
<th class="text-right">Wait</th>
</tr>
</thead>
<tbody>
<tr v-for="queue in workload">
<td>
<span>{{ queue.name.replace(/,/g, ', ') }}</span>
</td>
<td>{{ queue.processes ? queue.processes.toLocaleString() : 0 }}</td>
<td>{{ queue.length ? queue.length.toLocaleString() : 0 }}</td>
<td class="text-right">{{ humanTime(queue.wait) }}</td>
</tr>
</tbody>
</table>
</div>
<div class="card mt-4" v-for="worker in workers" :key="worker.name">
<div class="card-header d-flex align-items-center justify-content-between">
<h5>{{ worker.name }}</h5>
<svg v-if="worker.status == 'running'" class="fill-success" viewBox="0 0 20 20" style="width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM6.7 9.29L9 11.6l4.3-4.3 1.4 1.42L9 14.4l-3.7-3.7 1.4-1.42z"></path>
</svg>
<svg v-if="worker.status == 'paused'" class="fill-warning" viewBox="0 0 20 20" style="width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM7 6h2v8H7V6zm4 0h2v8h-2V6z"/>
</svg>
</div>
<table class="table table-hover table-sm mb-0">
<thead>
<tr>
<th>Supervisor</th>
<th>Processes</th>
<th>Queues</th>
<th class="text-right">Balancing</th>
</tr>
</thead>
<tbody>
<tr v-for="supervisor in worker.supervisors">
<td>{{ superVisorDisplayName(supervisor.name, worker.name) }}</td>
<td>{{ countProcesses(supervisor.processes) }}</td>
<td>{{ supervisor.options.queue.replace(/,/g, ', ') }}</td>
<td class="text-right" v-if="supervisor.options.balance">
({{ supervisor.options.balance.charAt(0).toUpperCase() + supervisor.options.balance.slice(1) }})
</td>
<td class="text-right" v-else>
(Disabled)
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>