first commit
This commit is contained in:
commit
3c0479faf0
169 files changed
+27617
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import vine from '@vinejs/vine'
|
||||
import type { HttpContext } from '@adonisjs/core/http'
|
||||
import metricsService, { type HostSample } from '#services/metrics_service'
|
||||
import { openSse } from '#services/sse'
|
||||
|
||||
const historyValidator = vine.create({
|
||||
range: vine.enum(['1h', '24h', '7d', '30d'] as const),
|
||||
})
|
||||
|
||||
export default class MetricsController {
|
||||
/**
|
||||
* Live samples (every 5 s) for the charts of the overview.
|
||||
*/
|
||||
async live(ctx: HttpContext) {
|
||||
const channel = openSse(ctx)
|
||||
channel.send('init', metricsService.live)
|
||||
|
||||
const onSample = (sample: HostSample) => channel.send('sample', sample)
|
||||
metricsService.on('sample', onSample)
|
||||
channel.onClose(() => metricsService.off('sample', onSample))
|
||||
}
|
||||
|
||||
async history({ request }: HttpContext) {
|
||||
const { range } = await historyValidator.validate(request.qs())
|
||||
return metricsService.history(range)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user