Rename /probe to /metrics
This commit is contained in:
parent
ff7fd44f2c
commit
d0b9b6a36e
3 changed files with 17 additions and 14 deletions
|
@ -9,9 +9,9 @@ export type HttpResponse = {
|
|||
export type HttpServerConfig = {
|
||||
port: number
|
||||
requestInterceptor: () => HttpResponse | undefined
|
||||
probeController: () => HttpResponse
|
||||
metricsController: () => HttpResponse
|
||||
notFoundController: () => HttpResponse
|
||||
errorController: () => HttpResponse
|
||||
errorController: (error: unknown) => HttpResponse
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ function adaptResponseToReply(response: HttpResponse, reply: FastifyReply): void
|
|||
export const serve: HttpServer = async ({
|
||||
port,
|
||||
requestInterceptor,
|
||||
probeController,
|
||||
metricsController,
|
||||
notFoundController,
|
||||
errorController,
|
||||
}) => {
|
||||
|
@ -61,15 +61,15 @@ export const serve: HttpServer = async ({
|
|||
})
|
||||
|
||||
fastify.setErrorHandler(async (error, request: FastifyRequest, reply: FastifyReply) => {
|
||||
adaptResponseToReply(errorController(), reply)
|
||||
adaptResponseToReply(errorController(error), reply)
|
||||
})
|
||||
|
||||
fastify.setNotFoundHandler(async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
adaptResponseToReply(notFoundController(), reply)
|
||||
})
|
||||
|
||||
fastify.get('/probe', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
adaptResponseToReply(probeController(), reply)
|
||||
fastify.get('/metrics', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
adaptResponseToReply(metricsController(), reply)
|
||||
})
|
||||
|
||||
await fastify.listen({ port, host: '::' })
|
||||
|
|
|
@ -61,9 +61,9 @@ export class PrometheusExporterPlatform implements IndependentPlatformPlugin {
|
|||
}
|
||||
}
|
||||
},
|
||||
probeController: () => {
|
||||
metricsController: () => {
|
||||
const renderer = new MetricsRenderer('homebridge')
|
||||
const metrics = this.metrics.map(renderer.render).join('\n')
|
||||
const metrics = this.metrics.map((metric) => renderer.render(metric)).join('\n')
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
|
@ -74,13 +74,16 @@ export class PrometheusExporterPlatform implements IndependentPlatformPlugin {
|
|||
notFoundController: () => ({
|
||||
statusCode: 404,
|
||||
headers: contentTypeHeader,
|
||||
body: 'Not found. Try /probe',
|
||||
}),
|
||||
errorController: () => ({
|
||||
statusCode: 500,
|
||||
headers: contentTypeHeader,
|
||||
body: 'Server error',
|
||||
body: 'Not found. Try /metrics',
|
||||
}),
|
||||
errorController: (e) => {
|
||||
this.log.error('HTTP request error: %o', e)
|
||||
return {
|
||||
statusCode: 500,
|
||||
headers: contentTypeHeader,
|
||||
body: 'Server error',
|
||||
}
|
||||
},
|
||||
})
|
||||
.then((http) => {
|
||||
this.log.debug('HTTP server started on port %d', this.config.probe_port)
|
||||
|
|
Loading…
Reference in a new issue