|
|
@@ -3,10 +3,11 @@ import {
|
|
|
Get,
|
|
|
Route
|
|
|
} from "tsoa";
|
|
|
-import {CpuInfo, DriveInfo, LiveSystemInfo, NetworkInfo, SystemInfo} from "../models/systemInfo";
|
|
|
+import {CpuInfo, DriveInfo, LiveSystemInfoDescription, NetworkInfo, SystemInfoDescription} from "../models/systemInfo";
|
|
|
import os from 'os';
|
|
|
import dns from 'dns';
|
|
|
import si from 'systeminformation';
|
|
|
+import ConfigurationManager from "../config";
|
|
|
|
|
|
@Route("/api/sysinfo")
|
|
|
export class SystemdInfoController extends Controller {
|
|
|
@@ -59,9 +60,10 @@ export class SystemdInfoController extends Controller {
|
|
|
}
|
|
|
|
|
|
@Get("/")
|
|
|
- public async getInfo(): Promise<SystemInfo> {
|
|
|
+ public async getInfo(): Promise<SystemInfoDescription> {
|
|
|
const system = await si.system();
|
|
|
- return {
|
|
|
+ let result: SystemInfoDescription = { systemInfo: {}};
|
|
|
+ result.systemInfo[ConfigurationManager.hostname] = {
|
|
|
platform: os.platform(),
|
|
|
osVersion: os.release(),
|
|
|
arch: os.machine(),
|
|
|
@@ -78,8 +80,9 @@ export class SystemdInfoController extends Controller {
|
|
|
manufacturer: system.manufacturer,
|
|
|
model: system.model,
|
|
|
drives: (await this.readDriveInfo())
|
|
|
- }
|
|
|
- };
|
|
|
+ };
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
private getCpuUsage(): Promise<Array<number>> {
|
|
|
return new Promise(ok => {
|
|
|
@@ -100,15 +103,16 @@ export class SystemdInfoController extends Controller {
|
|
|
}
|
|
|
|
|
|
@Get("/live")
|
|
|
- public async getLiveInfo(): Promise<LiveSystemInfo> {
|
|
|
+ public async getLiveInfo(): Promise<LiveSystemInfoDescription> {
|
|
|
const memInfo = await si.mem();
|
|
|
const cpuSpeed = await this.getCpuUsage();
|
|
|
-
|
|
|
- return <LiveSystemInfo> {
|
|
|
+ let result: LiveSystemInfoDescription = { liveSystemInfo: {}};
|
|
|
+ result.liveSystemInfo[ConfigurationManager.hostname] = {
|
|
|
totalMemoryUsed: memInfo.used,
|
|
|
activeMemory: memInfo.active,
|
|
|
currentCpuUsed: cpuSpeed.reduce((a, b) => a +b, 0) /cpuSpeed.length,
|
|
|
cpuByCore: cpuSpeed
|
|
|
- }
|
|
|
+ };
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|