feat: debug info for hot route and path

This commit is contained in:
DIYgod
2019-06-19 18:39:40 +08:00
parent 638c613f0b
commit 7c2f4777af
4 changed files with 24 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
module.exports = async (ctx, next) => {
if (!ctx.debug.routes[ctx.request.path]) {
ctx.debug.routes[ctx.request.path] = 0;
if (!ctx.debug.paths[ctx.request.path]) {
ctx.debug.paths[ctx.request.path] = 0;
}
ctx.debug.routes[ctx.request.path]++;
ctx.debug.paths[ctx.request.path]++;
const ip = ctx.ips[0] || ctx.ip;
if (!ctx.debug.ips[ip]) {
@@ -13,6 +13,11 @@ module.exports = async (ctx, next) => {
await next();
if (!ctx.debug.routes[ctx._matchedRoute]) {
ctx.debug.routes[ctx._matchedRoute] = 0;
}
ctx.debug.routes[ctx._matchedRoute]++;
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
ctx.debug.hitCache++;
}