summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/admin/server-info.ts
blob: 1373802f3ed2fe72bee0f8c81ee1e63659113ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import * as os from 'os';
import * as si from 'systeminformation';
import { getConnection } from 'typeorm';
import define from '../../define';
import { redisClient } from '../../../../db/redis';

export const meta = {
	requireCredential: true as const,
	requireModerator: true,

	tags: ['admin', 'meta'],

	params: {
	},

	res: {
		type: 'object' as const,
		optional: false as const, nullable: false as const,
		properties: {
			machine: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'The name of the running server'
			},
			os: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'OS used by the server',
				example: 'linux'
			},
			node: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'Version of Node.js'
			},
			psql: {
				type: 'string' as const,
				optional: false as const, nullable: false as const,
				description: 'Version of Postgresql'
			},
			cpu: {
				type: 'object' as const,
				optional: false as const, nullable: false as const,
				properties: {
					model: {
						type: 'string' as const,
						optional: false as const, nullable: false as const,
						description: 'The name of the CPU you are using'
					},
					cores: {
						type: 'number' as const,
						optional: false as const, nullable: false as const,
						description: 'Number of CPU cores used (number of logical processors)'
					}
				}
			},
			mem: {
				type: 'object' as const,
				optional: false as const, nullable: false as const,
				properties: {
					total: {
						type: 'number' as const,
						optional: false as const, nullable: false as const,
						format: 'bytes',
						description: 'RAM capacity.'
					}
				}
			},
			fs: {
				type: 'object' as const,
				optional: false as const, nullable: false as const,
				properties: {
					total: {
						type: 'number' as const,
						optional: false as const, nullable: false as const,
						format: 'bytes',
						description: 'Total storage capacity.'
					},
					used: {
						type: 'number' as const,
						optional: false as const, nullable: false as const,
						format: 'bytes',
						description: 'Amount of storage used'
					}
				}
			},
			net: {
				type: 'object' as const,
				optional: false as const, nullable: false as const,
				properties: {
					interface: {
						type: 'string' as const,
						optional: false as const, nullable: false as const,
						description: 'The interface name of your network.',
						example: 'eth0'
					}
				}
			}
		}
	}
};

export default define(meta, async () => {
	const memStats = await si.mem();
	const fsStats = await si.fsSize();
	const netInterface = await si.networkInterfaceDefault();

	return {
		machine: os.hostname(),
		os: os.platform(),
		node: process.version,
		psql: await getConnection().query('SHOW server_version').then(x => x[0].server_version),
		redis: redisClient.server_info.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
		}
	};
});