feat: remove hot ip in debug info

This commit is contained in:
DIYgod
2021-01-21 11:57:16 +08:00
parent a0dd6756da
commit 6506c39239
4 changed files with 0 additions and 20 deletions

View File

@@ -48,7 +48,6 @@ app.context.debug = {
etag: 0, etag: 0,
paths: [], paths: [],
routes: [], routes: [],
ips: [],
errorPaths: [], errorPaths: [],
errorRoutes: [], errorRoutes: [],
}; };

View File

@@ -4,11 +4,6 @@ module.exports = async (ctx, next) => {
} }
ctx.debug.paths[ctx.request.path]++; ctx.debug.paths[ctx.request.path]++;
const ip = ctx.ips[0] || ctx.ip;
if (!ctx.debug.ips[ip]) {
ctx.debug.ips[ip] = 0;
}
ctx.debug.ips[ip]++;
ctx.debug.request++; ctx.debug.request++;
await next(); await next();

View File

@@ -48,13 +48,6 @@ module.exports = async (ctx) => {
}); });
} }
const ips = Object.keys(ctx.debug.ips).sort((a, b) => ctx.debug.ips[b] - ctx.debug.ips[a]);
const hotIPs = ips.slice(0, 50);
let hotIPsValue = '';
hotIPs.forEach((item) => {
hotIPsValue += `${ctx.debug.ips[item]} ${item}<br>`;
});
let showDebug; let showDebug;
if (!config.debugInfo || config.debugInfo === 'false') { if (!config.debugInfo || config.debugInfo === 'false') {
showDebug = false; showDebug = false;
@@ -115,10 +108,6 @@ module.exports = async (ctx) => {
name: 'Hot Paths', name: 'Hot Paths',
value: hotPathsValue, value: hotPathsValue,
}, },
{
name: 'Hot IP',
value: hotIPsValue,
},
{ {
name: 'Hot Error Routes', name: 'Hot Error Routes',
value: hotErrorRoutesValue, value: hotErrorRoutesValue,

View File

@@ -52,9 +52,6 @@ describe('debug', () => {
case 'Hot Paths:': case 'Hot Paths:':
expect(value).toBe('3 /test/1<br>2 /test/2<br>2 /test/empty<br>1 /<br>'); expect(value).toBe('3 /test/1<br>2 /test/2<br>2 /test/empty<br>1 /<br>');
break; break;
case 'Hot IP:':
expect(value).toBe('5 233.233.233.233<br>3 233.233.233.234<br>');
break;
case 'Hot Error Routes:': case 'Hot Error Routes:':
expect(value).toBe('1 /test/:id<br>'); expect(value).toBe('1 /test/:id<br>');
break; break;