2022-02-27 11:07:39 +09:00
|
|
|
import * as os from 'node:os';
|
|
|
|
import si from 'systeminformation';
|
|
|
|
import define from '../../define.js';
|
|
|
|
import { redisClient } from '../../../../db/redis.js';
|
2022-03-26 15:34:00 +09:00
|
|
|
import { db } from '@/db/postgre.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-02-19 14:05:32 +09:00
|
|
|
export default define(meta, paramDef, async () => {
|
2020-01-30 04:37:25 +09:00
|
|
|
const memStats = await si.mem();
|
|
|
|
const fsStats = await si.fsSize();
|
|
|
|
const netInterface = await si.networkInterfaceDefault();
|
|
|
|
|
2022-06-24 19:22:19 +09:00
|
|
|
const redisServerInfo = await redisClient.info('Server');
|
|
|
|
const m = redisServerInfo.match(new RegExp('^redis_version:(.*)', 'm'));
|
|
|
|
const redis_version = m?.[1];
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
return {
|
|
|
|
machine: os.hostname(),
|
|
|
|
os: os.platform(),
|
|
|
|
node: process.version,
|
2022-03-26 15:34:00 +09:00
|
|
|
psql: await db.query('SHOW server_version').then(x => x[0].server_version),
|
2022-06-24 19:22:19 +09:00
|
|
|
redis: redis_version,
|
2020-01-30 04:37:25 +09:00
|
|
|
cpu: {
|
|
|
|
model: os.cpus()[0].model,
|
2021-12-09 23:58:30 +09:00
|
|
|
cores: os.cpus().length,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
mem: {
|
2021-12-09 23:58:30 +09:00
|
|
|
total: memStats.total,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
fs: {
|
|
|
|
total: fsStats[0].size,
|
|
|
|
used: fsStats[0].used,
|
|
|
|
},
|
|
|
|
net: {
|
2021-12-09 23:58:30 +09:00
|
|
|
interface: netInterface,
|
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
};
|
|
|
|
});
|