mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-16 02:42:57 +08:00
app: debug: add hot ips
This commit is contained in:
1
index.js
1
index.js
@@ -38,6 +38,7 @@ app.context.debug = {
|
||||
hitCache: 0,
|
||||
request: 0,
|
||||
routes: [],
|
||||
ips: [],
|
||||
};
|
||||
app.use(debug);
|
||||
|
||||
|
||||
@@ -4,6 +4,12 @@ module.exports = async (ctx, next) => {
|
||||
}
|
||||
ctx.debug.routes[ctx.request.path]++;
|
||||
|
||||
const ip = ctx.ips[0] || ctx.ip;
|
||||
if (!ctx.debug.ips[ip]) {
|
||||
ctx.debug.ips[ip] = 0;
|
||||
}
|
||||
ctx.debug.ips[ip]++;
|
||||
|
||||
if (ctx.request.path !== '/') {
|
||||
ctx.debug.request++;
|
||||
}
|
||||
|
||||
12
router.js
12
router.js
@@ -18,6 +18,7 @@ router.get('/', async (ctx) => {
|
||||
});
|
||||
|
||||
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 = '';
|
||||
@@ -25,6 +26,13 @@ router.get('/', async (ctx) => {
|
||||
hotRoutesValue += `${ctx.debug.routes[item]} ${item}<br>`;
|
||||
});
|
||||
|
||||
const ips = Object.keys(ctx.debug.ips).sort((a, b) => ctx.debug.ips[b] - ctx.debug.ips[a]);
|
||||
const hotIPs = ips.slice(0, 10);
|
||||
let hotIPsValue = '';
|
||||
hotIPs.forEach((item) => {
|
||||
hotIPsValue += `${ctx.debug.ips[item]} ${item}<br>`;
|
||||
});
|
||||
|
||||
ctx.body = art(path.resolve(__dirname, './views/welcome.art'), {
|
||||
debug: [
|
||||
{
|
||||
@@ -55,6 +63,10 @@ router.get('/', async (ctx) => {
|
||||
name: '热门路由',
|
||||
value: hotRoutesValue,
|
||||
},
|
||||
{
|
||||
name: '热门IP',
|
||||
value: hotIPsValue,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,6 +25,21 @@
|
||||
|
||||
details {
|
||||
text-align: left;
|
||||
max-height: 400px;
|
||||
overflow: scroll;
|
||||
}
|
||||
|
||||
details::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
details::-webkit-scrollbar-thumb {
|
||||
border-radius: 3px;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
details::-webkit-scrollbar-thumb:hover {
|
||||
background-color: #ccc;
|
||||
}
|
||||
|
||||
summary {
|
||||
|
||||
Reference in New Issue
Block a user