2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-16 15:09:41 +01:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-09-17 20:27:08 +02:00
|
|
|
|
2023-01-01 09:45:49 +01:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import FederationChart from './charts/federation.js';
|
|
|
|
import NotesChart from './charts/notes.js';
|
|
|
|
import UsersChart from './charts/users.js';
|
|
|
|
import ActiveUsersChart from './charts/active-users.js';
|
|
|
|
import InstanceChart from './charts/instance.js';
|
|
|
|
import PerUserNotesChart from './charts/per-user-notes.js';
|
2023-01-01 09:45:49 +01:00
|
|
|
import PerUserPvChart from './charts/per-user-pv.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import DriveChart from './charts/drive.js';
|
|
|
|
import PerUserReactionsChart from './charts/per-user-reactions.js';
|
|
|
|
import PerUserFollowingChart from './charts/per-user-following.js';
|
|
|
|
import PerUserDriveChart from './charts/per-user-drive.js';
|
|
|
|
import ApRequestChart from './charts/ap-request.js';
|
2022-09-19 22:19:37 +02:00
|
|
|
import type { OnApplicationShutdown } from '@nestjs/common';
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
@Injectable()
|
2022-09-19 22:19:37 +02:00
|
|
|
export class ChartManagementService implements OnApplicationShutdown {
|
|
|
|
private charts;
|
2023-09-04 06:33:38 +02:00
|
|
|
private saveIntervalId: NodeJS.Timeout;
|
2022-09-19 22:19:37 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
constructor(
|
|
|
|
private federationChart: FederationChart,
|
|
|
|
private notesChart: NotesChart,
|
|
|
|
private usersChart: UsersChart,
|
|
|
|
private activeUsersChart: ActiveUsersChart,
|
|
|
|
private instanceChart: InstanceChart,
|
|
|
|
private perUserNotesChart: PerUserNotesChart,
|
2023-01-01 09:45:49 +01:00
|
|
|
private perUserPvChart: PerUserPvChart,
|
2022-09-17 20:27:08 +02:00
|
|
|
private driveChart: DriveChart,
|
|
|
|
private perUserReactionsChart: PerUserReactionsChart,
|
|
|
|
private perUserFollowingChart: PerUserFollowingChart,
|
|
|
|
private perUserDriveChart: PerUserDriveChart,
|
|
|
|
private apRequestChart: ApRequestChart,
|
2022-09-19 22:19:37 +02:00
|
|
|
) {
|
|
|
|
this.charts = [
|
2022-09-17 20:27:08 +02:00
|
|
|
this.federationChart,
|
|
|
|
this.notesChart,
|
|
|
|
this.usersChart,
|
|
|
|
this.activeUsersChart,
|
|
|
|
this.instanceChart,
|
|
|
|
this.perUserNotesChart,
|
2023-01-01 09:45:49 +01:00
|
|
|
this.perUserPvChart,
|
2022-09-17 20:27:08 +02:00
|
|
|
this.driveChart,
|
|
|
|
this.perUserReactionsChart,
|
|
|
|
this.perUserFollowingChart,
|
|
|
|
this.perUserDriveChart,
|
|
|
|
this.apRequestChart,
|
|
|
|
];
|
2022-09-19 22:19:37 +02:00
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2023-01-21 06:09:01 +01:00
|
|
|
public async start() {
|
2022-09-17 20:27:08 +02:00
|
|
|
// 20分おきにメモリ情報をDBに書き込み
|
2022-09-19 22:19:37 +02:00
|
|
|
this.saveIntervalId = setInterval(() => {
|
|
|
|
for (const chart of this.charts) {
|
2022-09-17 20:27:08 +02:00
|
|
|
chart.save();
|
|
|
|
}
|
|
|
|
}, 1000 * 60 * 20);
|
2022-09-19 22:19:37 +02:00
|
|
|
}
|
|
|
|
|
2023-05-29 06:21:26 +02:00
|
|
|
@bindThis
|
|
|
|
public async dispose(): Promise<void> {
|
2022-09-19 22:19:37 +02:00
|
|
|
clearInterval(this.saveIntervalId);
|
2023-03-03 03:13:12 +01:00
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
await Promise.all(
|
|
|
|
this.charts.map(chart => chart.save()),
|
|
|
|
);
|
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
2023-05-29 06:21:26 +02:00
|
|
|
|
|
|
|
@bindThis
|
|
|
|
async onApplicationShutdown(signal: string): Promise<void> {
|
|
|
|
await this.dispose();
|
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|