|
|
@@ -1,11 +1,18 @@
|
|
|
|
|
|
import $ from "jquery"
|
|
|
-import { SystemInfoDescription, SystemInfo as ModelSystemInfo } from "../../src/models/systemInfo";
|
|
|
+import { SystemInfoDescription, SystemInfo as ModelSystemInfo, HostnameLiveSystemInfoDescription } from "../../src/models/systemInfo";
|
|
|
import { HostnameServiceDescription } from "../../src/models/service";
|
|
|
|
|
|
+export interface TimedLiveSystemInfo {
|
|
|
+ time: Date;
|
|
|
+ data: HostnameLiveSystemInfoDescription;
|
|
|
+}
|
|
|
+
|
|
|
export namespace DAL {
|
|
|
export class SystemInfo {
|
|
|
private static lastCachedData: SystemInfoDescription|null = null;
|
|
|
+ private static liveData: TimedLiveSystemInfo[] = [];
|
|
|
+ private static liveHandler: ReturnType<typeof setTimeout>|boolean = false;
|
|
|
|
|
|
private static getData(): Promise<void> {
|
|
|
return new Promise(ok => {
|
|
|
@@ -32,6 +39,38 @@ export namespace DAL {
|
|
|
return Object.keys(this.lastCachedData?.systemInfo ?? {});
|
|
|
}
|
|
|
|
|
|
+ private static pushLiveData(data: HostnameLiveSystemInfoDescription): TimedLiveSystemInfo {
|
|
|
+ let result: TimedLiveSystemInfo = { data: data, time: new Date() };
|
|
|
+ this.liveData.push(result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static pollNow(): Promise<TimedLiveSystemInfo> {
|
|
|
+ return new Promise(ok => {
|
|
|
+ $.get("/api/sysinfo/live", response => {
|
|
|
+ ok(this.pushLiveData(response.liveSystemInfo));
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private static async pollTick(): Promise<TimedLiveSystemInfo> {
|
|
|
+ let result = await this.pollNow();
|
|
|
+ this.liveHandler = setTimeout(this.pollTick.bind(this), 10000);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async startLivePolling(): Promise<TimedLiveSystemInfo> {
|
|
|
+ if (this.liveHandler !== false)
|
|
|
+ return this.liveData[this.liveData.length-1]!;
|
|
|
+ this.liveHandler = true;
|
|
|
+ await this.getDataWithCache();
|
|
|
+ return await this.pollTick();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async getLive(): Promise<TimedLiveSystemInfo> {
|
|
|
+ return await this.startLivePolling();
|
|
|
+ }
|
|
|
+
|
|
|
public static async getServices(): Promise<HostnameServiceDescription> {
|
|
|
return new Promise(ok => {
|
|
|
$.get("/api/services/list", response => {
|