Improve chart engine (#8253)
* wip * wip * wip * wip * wip * wip * wip * Update core.ts * wip * wip * #7361 * delete network chart * federationChart強化 apRequestChart追加 * tweak
This commit is contained in:
@ -22,7 +22,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(activeUsersChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import { convertLog } from '@/services/chart/core';
|
||||
import { networkChart } from '@/services/chart/index';
|
||||
import { apRequestChart } from '@/services/chart/index';
|
||||
|
||||
export const meta = {
|
||||
tags: ['charts'],
|
||||
@ -22,10 +22,10 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(networkChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, async (ps) => {
|
||||
return await networkChart.getChart(ps.span as any, ps.limit!, ps.offset ? new Date(ps.offset) : null);
|
||||
return await apRequestChart.getChart(ps.span as any, ps.limit!, ps.offset ? new Date(ps.offset) : null);
|
||||
});
|
@ -22,7 +22,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(driveChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -22,7 +22,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(federationChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -26,7 +26,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(hashtagChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -26,7 +26,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(instanceChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -22,7 +22,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(notesChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -27,7 +27,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(perUserDriveChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -27,7 +27,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(perUserFollowingChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -27,7 +27,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(perUserNotesChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -27,7 +27,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(perUserReactionsChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -22,7 +22,7 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
|
||||
res: convertLog(usersChart.schema),
|
||||
// TODO: response definition
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -66,8 +66,8 @@ export default define(meta, async () => {
|
||||
NoteReactions.count({ cache: 3600000 }), // 1 hour
|
||||
//NoteReactions.count({ where: { userHost: null }, cache: 3600000 }),
|
||||
federationChart.getChart('hour', 1, null).then(chart => chart.instance.total[0]),
|
||||
driveChart.getChart('hour', 1, null).then(chart => chart.local.totalSize[0]),
|
||||
driveChart.getChart('hour', 1, null).then(chart => chart.remote.totalSize[0]),
|
||||
driveChart.getChart('hour', 1, null).then(chart => chart.local.totalSize[0] * 1000),
|
||||
driveChart.getChart('hour', 1, null).then(chart => chart.remote.totalSize[0] * 1000),
|
||||
]);
|
||||
|
||||
return {
|
||||
|
@ -10,7 +10,6 @@ import * as Koa from 'koa';
|
||||
import * as Router from '@koa/router';
|
||||
import * as mount from 'koa-mount';
|
||||
import * as koaLogger from 'koa-logger';
|
||||
import * as requestStats from 'request-stats';
|
||||
import * as slow from 'koa-slow';
|
||||
|
||||
import activityPub from './activitypub';
|
||||
@ -18,11 +17,9 @@ import nodeinfo from './nodeinfo';
|
||||
import wellKnown from './well-known';
|
||||
import config from '@/config/index';
|
||||
import apiServer from './api/index';
|
||||
import { sum } from '@/prelude/array';
|
||||
import Logger from '@/services/logger';
|
||||
import { envOption } from '../env';
|
||||
import { UserProfiles, Users } from '@/models/index';
|
||||
import { networkChart } from '@/services/chart/index';
|
||||
import { genIdenticon } from '@/misc/gen-identicon';
|
||||
import { createTemp } from '@/misc/create-temp';
|
||||
import { publishMainStream } from '@/services/stream';
|
||||
@ -153,27 +150,4 @@ export default () => new Promise(resolve => {
|
||||
|
||||
// Listen
|
||||
server.listen(config.port, resolve);
|
||||
|
||||
//#region Network stats
|
||||
let queue: any[] = [];
|
||||
|
||||
requestStats(server, (stats: any) => {
|
||||
if (stats.ok) {
|
||||
queue.push(stats);
|
||||
}
|
||||
});
|
||||
|
||||
// Bulk write
|
||||
setInterval(() => {
|
||||
if (queue.length === 0) return;
|
||||
|
||||
const requests = queue.length;
|
||||
const time = sum(queue.map(x => x.time));
|
||||
const incomingBytes = sum(queue.map(x => x.req.byets));
|
||||
const outgoingBytes = sum(queue.map(x => x.res.byets));
|
||||
queue = [];
|
||||
|
||||
networkChart.update(requests, time, incomingBytes, outgoingBytes);
|
||||
}, 5000);
|
||||
//#endregion
|
||||
});
|
||||
|
Reference in New Issue
Block a user