This commit is contained in:
seb
2026-10-19 01:50:32 +02:00
parent f571328e0c
commit c958ecf604
6 changed files with 191 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import { getStore } from '../../db/store.js';
import { getLatencySeries } from '../../services/healthMonitorService.js';
/**
* Registers a database connectivity health check route.
@@ -57,4 +58,57 @@ export function register(app, basePath = '') {
}
// #endregion
/**
* @openapi
* /health/latency:
* get:
* tags: [Health]
* summary: Health latency history
* description: Returns the database healthcheck latency (ms) as three series, each oldest first with unix-ms timestamps. `raw` holds the per-minute samples of the last 3 hours; `avg` and `max` hold the 30-minute aggregates (over the last 4 hours of samples) kept for 30 days. Requires a valid JWT; no company selection needed.
* responses:
* 200:
* description: Latency series
* content:
* application/json:
* schema:
* type: object
* properties:
* raw:
* type: array
* items: { $ref: '#/components/schemas/LatencyPoint' }
* avg:
* type: array
* items: { $ref: '#/components/schemas/LatencyPoint' }
* max:
* type: array
* items: { $ref: '#/components/schemas/LatencyPoint' }
* 401:
* description: Unauthorized
* 500:
* description: Redis read failed
* components:
* schemas:
* LatencyPoint:
* type: object
* properties:
* timestamp:
* type: integer
* description: Unix epoch milliseconds
* value:
* type: number
* description: Latency in milliseconds
*/
// #region GET /health/latency
app.get(`${basePath}/health/latency`, async (_request, response) => {
try {
response.json(await getLatencySeries());
} catch (error) {
console.error('GET /health/latency failed:', error);
response.status(500).json({ error: error.message });
}
});
// #endregion
}