2022-02-27 11:07:39 +09:00
|
|
|
import * as os from 'node:os';
|
|
|
|
import si from 'systeminformation';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DataSource } from 'typeorm';
|
|
|
|
import Redis from 'ioredis';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
export const meta = {
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2020-10-17 20:12:00 +09:00
|
|
|
requireModerator: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-04-03 22:42:29 +09:00
|
|
|
tags: ['admin', 'meta'],
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2021-03-06 22:34:11 +09:00
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
properties: {
|
|
|
|
machine: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
os: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 23:58:30 +09:00
|
|
|
example: 'linux',
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
node: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
psql: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
cpu: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
properties: {
|
|
|
|
model: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
cores: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
|
|
|
},
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
mem: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
properties: {
|
|
|
|
total: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
format: 'bytes',
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
|
|
|
},
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
fs: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
properties: {
|
|
|
|
total: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
format: 'bytes',
|
|
|
|
},
|
|
|
|
used: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
format: 'bytes',
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
|
|
|
},
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
net: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
properties: {
|
|
|
|
interface: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 23:58:30 +09:00
|
|
|
example: 'eth0',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
properties: {},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.db)
|
|
|
|
private db: DataSource,
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Inject(DI.redis)
|
|
|
|
private redisClient: Redis.Redis,
|
2022-06-24 19:22:19 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
) {
|
|
|
|
super(meta, paramDef, async () => {
|
|
|
|
const memStats = await si.mem();
|
|
|
|
const fsStats = await si.fsSize();
|
|
|
|
const netInterface = await si.networkInterfaceDefault();
|
|
|
|
|
|
|
|
const redisServerInfo = await this.redisClient.info('Server');
|
|
|
|
const m = redisServerInfo.match(new RegExp('^redis_version:(.*)', 'm'));
|
|
|
|
const redis_version = m?.[1];
|
|
|
|
|
|
|
|
return {
|
|
|
|
machine: os.hostname(),
|
|
|
|
os: os.platform(),
|
|
|
|
node: process.version,
|
|
|
|
psql: await this.db.query('SHOW server_version').then(x => x[0].server_version),
|
|
|
|
redis: redis_version,
|
|
|
|
cpu: {
|
|
|
|
model: os.cpus()[0].model,
|
|
|
|
cores: os.cpus().length,
|
|
|
|
},
|
|
|
|
mem: {
|
|
|
|
total: memStats.total,
|
|
|
|
},
|
|
|
|
fs: {
|
|
|
|
total: fsStats[0].size,
|
|
|
|
used: fsStats[0].used,
|
|
|
|
},
|
|
|
|
net: {
|
|
|
|
interface: netInterface,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|