mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Merge pull request #1227 from bbassie/fix/machine-details-on-start
Collect system info on start and when a host connects
This commit is contained in:
4 files changed
+85
-2
No files matched your search
@@ -2,6 +2,7 @@ import type winston from "winston";
|
||||
import { BlockList, type AddressInfo, isIPv4, isIPv6 } from "net";
|
||||
import type { ControllerArgs } from "../controller.js";
|
||||
import type ControlConnection from "./ControlConnection.js";
|
||||
import type HostConnection from "./HostConnection.js";
|
||||
import express, { type Request, type Response, type NextFunction, type Application } from "express";
|
||||
import type { Static } from "@sinclair/typebox";
|
||||
import finalhandler from "finalhandler";
|
||||
@@ -508,11 +509,11 @@ export default class Controller {
|
||||
}
|
||||
|
||||
this.hostPairing.start();
|
||||
this.onAutosaveIntervalChanged();
|
||||
this.onSystemMetricsIntervalChanged();
|
||||
|
||||
logger.info("Started controller");
|
||||
this.startedAtMs = Date.now();
|
||||
this.onAutosaveIntervalChanged();
|
||||
this.onSystemMetricsIntervalChanged();
|
||||
this._state = "running";
|
||||
}
|
||||
|
||||
@@ -669,6 +670,7 @@ export default class Controller {
|
||||
this.updateSystems.bind(this),
|
||||
systemMetricsIntervalSeconds * 1000
|
||||
);
|
||||
this.updateSystems();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,6 +696,20 @@ export default class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
/** Fetch system info from a host that just connected instead of waiting for the next interval */
|
||||
async updateHostSystem(hostConnection: HostConnection) {
|
||||
if (!(this.config.get("controller.system_metrics_interval") > 0)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.systems.set(await hostConnection.send(new lib.SystemInfoRequest()));
|
||||
} catch (err: any) {
|
||||
logger.error(
|
||||
`Unexpected error updating system info of host ${hostConnection.id}:\n${err.stack ?? err.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** Plugins on the controller, including those installed or updated since it started */
|
||||
async listPlugins() {
|
||||
return await lib.listPluginDetails(
|
||||
|
||||
@@ -51,6 +51,7 @@ export default class HostConnection extends BaseConnection {
|
||||
for (let event of ["connect", "drop", "resume", "close"] as const) {
|
||||
this.connector.on(event, () => this._controller.hooks.hostConnectionEvent.invoke(this, event));
|
||||
}
|
||||
this.connector.on("connect", () => { this._controller.updateHostSystem(this); });
|
||||
|
||||
this.connector.on("close", () => {
|
||||
// Update status to unknown for instances on this host.
|
||||
|
||||
Reference in new issue
Block a user