mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-15 18:30:53 +08:00
app: debug: add hot routes
This commit is contained in:
1
index.js
1
index.js
@@ -36,6 +36,7 @@ app.use(header);
|
|||||||
app.context.debug = {
|
app.context.debug = {
|
||||||
hitCache: 0,
|
hitCache: 0,
|
||||||
request: 0,
|
request: 0,
|
||||||
|
routes: [],
|
||||||
};
|
};
|
||||||
app.use(debug);
|
app.use(debug);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
module.exports = async (ctx, next) => {
|
module.exports = async (ctx, next) => {
|
||||||
await next();
|
if (!ctx.debug.routes[ctx.request.path]) {
|
||||||
|
ctx.debug.routes[ctx.request.path] = 0;
|
||||||
|
}
|
||||||
|
ctx.debug.routes[ctx.request.path]++;
|
||||||
|
|
||||||
if (ctx.request.path !== '/') {
|
if (ctx.request.path !== '/') {
|
||||||
ctx.debug.request++;
|
ctx.debug.request++;
|
||||||
|
}
|
||||||
|
|
||||||
|
await next();
|
||||||
|
|
||||||
|
if (ctx.request.path !== '/') {
|
||||||
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
|
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
|
||||||
ctx.debug.hitCache++;
|
ctx.debug.hitCache++;
|
||||||
}
|
}
|
||||||
|
|||||||
12
router.js
12
router.js
@@ -16,7 +16,15 @@ router.get('/', async (ctx) => {
|
|||||||
ctx.set({
|
ctx.set({
|
||||||
'Content-Type': 'text/html; charset=UTF-8',
|
'Content-Type': 'text/html; charset=UTF-8',
|
||||||
});
|
});
|
||||||
|
|
||||||
const time = (+new Date() - startTime) / 1000;
|
const time = (+new Date() - startTime) / 1000;
|
||||||
|
const routes = Object.keys(ctx.debug.routes).sort((a, b) => ctx.debug.routes[b] - ctx.debug.routes[a]);
|
||||||
|
const hotRoutes = routes.slice(0, 10);
|
||||||
|
let hotRoutesValue = '';
|
||||||
|
hotRoutes.forEach((item) => {
|
||||||
|
hotRoutesValue += `${ctx.debug.routes[item]} ${item}<br>`;
|
||||||
|
});
|
||||||
|
|
||||||
ctx.body = art(path.resolve(__dirname, './views/welcome.art'), {
|
ctx.body = art(path.resolve(__dirname, './views/welcome.art'), {
|
||||||
debug: [
|
debug: [
|
||||||
{
|
{
|
||||||
@@ -43,6 +51,10 @@ router.get('/', async (ctx) => {
|
|||||||
name: '运行时间',
|
name: '运行时间',
|
||||||
value: time + ' 秒',
|
value: time + ' 秒',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: '热门路由',
|
||||||
|
value: hotRoutesValue,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
summary {
|
summary {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 10px;
|
||||||
outline: none;
|
outline: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@@ -41,8 +41,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.debug-item {
|
.debug-item {
|
||||||
margin: 10px 0;
|
margin: 5px 0;
|
||||||
font-size: 14px;
|
font-size: 12px;
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.debug-value {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -72,7 +78,7 @@
|
|||||||
{{ each debug }}
|
{{ each debug }}
|
||||||
<div class="debug-item">
|
<div class="debug-item">
|
||||||
<span class="debug-key">{{ $value.name }}: </span>
|
<span class="debug-key">{{ $value.name }}: </span>
|
||||||
<span class="debug-value">{{ $value.value }}</span>
|
<span class="debug-value">{{@ $value.value }}</span>
|
||||||
</div>
|
</div>
|
||||||
{{ /each }}
|
{{ /each }}
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Reference in New Issue
Block a user