Add address host connected from to the host info

Provide an easy way to see where a host is connecting from in the web UI
and clusterioctl list.
This commit is contained in:
Hornwitser committed 2024-01-16 21:27:02 +01:00
1 parent de47989527
commit b5ed0800cf
5 files changed
+16 -4

No files matched your search

@@ -23,6 +23,7 @@ export default class HostConnection extends BaseConnection {
registerData: lib.RegisterHostData, registerData: lib.RegisterHostData,
connector: WsServerConnector, connector: WsServerConnector,
controller: Controller, controller: Controller,
remoteAddress: string,
) { ) {
super(connector, controller); super(connector, controller);
@@ -35,6 +36,7 @@ export default class HostConnection extends BaseConnection {
registerData.version, registerData.version,
this.plugins, this.plugins,
true, true,
remoteAddress,
previousHostInfo?.publicAddress, previousHostInfo?.publicAddress,
previousHostInfo?.tokenValidAfter, previousHostInfo?.tokenValidAfter,
0, 0,
+7 -1
View File
@@ -16,9 +16,11 @@ export default class HostInfo {
public plugins: Map<string, string>, public plugins: Map<string, string>,
/** True if this host is currently connected to controller */ /** True if this host is currently connected to controller */
public connected: boolean = false, public connected: boolean = false,
/** IP this host last connected from */
public remoteAddress: string = "",
/** Value of host.public_address configured for this host */ /** Value of host.public_address configured for this host */
public publicAddress: string = "", public publicAddress: string = "",
/** Unix timestamp in seconds host token must be issued afterto be valid */ /** Unix timestamp in seconds host token must be issued after to be valid */
public tokenValidAfter: number = 0, public tokenValidAfter: number = 0,
/** Millisecond Unix timestamp this entry was last updated at */ /** Millisecond Unix timestamp this entry was last updated at */
public updatedAt: number = 0, public updatedAt: number = 0,
@@ -32,6 +34,7 @@ export default class HostInfo {
"version": Type.String(), "version": Type.String(),
"plugins": Type.Record(Type.String(), Type.String()), "plugins": Type.Record(Type.String(), Type.String()),
"connected": Type.Boolean(), "connected": Type.Boolean(),
"remote_address": Type.String(),
"public_address": Type.String(), "public_address": Type.String(),
"token_valid_after": Type.Number(), "token_valid_after": Type.Number(),
"updated_at": Type.Number(), "updated_at": Type.Number(),
@@ -45,6 +48,7 @@ export default class HostInfo {
json.version, json.version,
new Map(Object.entries(json.plugins)), new Map(Object.entries(json.plugins)),
json.connected, json.connected,
json.remote_address,
json.public_address, json.public_address,
json.token_valid_after, json.token_valid_after,
json.updated_at, json.updated_at,
@@ -59,6 +63,7 @@ export default class HostInfo {
version: this.version, version: this.version,
plugins: Object.fromEntries(this.plugins), plugins: Object.fromEntries(this.plugins),
connected: this.connected, connected: this.connected,
remote_address: this.remoteAddress,
public_address: this.publicAddress, public_address: this.publicAddress,
token_valid_after: this.tokenValidAfter, token_valid_after: this.tokenValidAfter,
updated_at: this.updatedAt, updated_at: this.updatedAt,
@@ -72,6 +77,7 @@ export default class HostInfo {
this.name, this.name,
this.id, this.id,
this.connected, this.connected,
this.remoteAddress,
this.publicAddress, this.publicAddress,
this.tokenValidAfter, this.tokenValidAfter,
this.updatedAt, this.updatedAt,
+1 -1
View File
@@ -284,7 +284,7 @@ ${err.stack}`
); );
} }
connection = new HostConnection(data, connector, this.controller); connection = new HostConnection(data, connector, this.controller, this.remoteAddr(req));
connector.on("close", () => { connector.on("close", () => {
if (this.hostConnections.get(data.id) === connection) { if (this.hostConnections.get(data.id) === connection) {
this.hostConnections.delete(data.id); this.hostConnections.delete(data.id);
+5 -2
View File
@@ -64,8 +64,9 @@ export class HostDetails {
public name: string, public name: string,
public id: number, public id: number,
public connected: boolean, public connected: boolean,
public publicAddress?: string, public remoteAddress = "",
public tokenValidAfter?: number, public publicAddress: string = "",
public tokenValidAfter: number = 0,
/** Millisecond Unix timestamp this entry was last updated at */ /** Millisecond Unix timestamp this entry was last updated at */
public updatedAt = 0, public updatedAt = 0,
public isDeleted = false, public isDeleted = false,
@@ -76,6 +77,7 @@ export class HostDetails {
"name": Type.String(), "name": Type.String(),
"id": Type.Integer(), "id": Type.Integer(),
"connected": Type.Boolean(), "connected": Type.Boolean(),
"remoteAddress": Type.Optional(Type.String()),
"publicAddress": Type.Optional(Type.String()), "publicAddress": Type.Optional(Type.String()),
"tokenValidAfter": Type.Optional(Type.Number()), "tokenValidAfter": Type.Optional(Type.Number()),
"updatedAt": Type.Optional(Type.Number()), "updatedAt": Type.Optional(Type.Number()),
@@ -88,6 +90,7 @@ export class HostDetails {
json.name, json.name,
json.id, json.id,
json.connected, json.connected,
json.remoteAddress,
json.publicAddress, json.publicAddress,
json.tokenValidAfter, json.tokenValidAfter,
json.updatedAt, json.updatedAt,
@@ -83,6 +83,7 @@ export default function HostViewPage() {
<Descriptions.Item label="OS Kernel">{system?.kernel}</Descriptions.Item> <Descriptions.Item label="OS Kernel">{system?.kernel}</Descriptions.Item>
<Descriptions.Item label="Machine">{system?.machine}</Descriptions.Item> <Descriptions.Item label="Machine">{system?.machine}</Descriptions.Item>
<Descriptions.Item label="Hostname" span={2}>{system?.hostname}</Descriptions.Item> <Descriptions.Item label="Hostname" span={2}>{system?.hostname}</Descriptions.Item>
<Descriptions.Item label="Connected From" span={2}>{host.remoteAddress}</Descriptions.Item>
<Descriptions.Item label="CPU Model" span={2}>{system?.cpuModel}</Descriptions.Item> <Descriptions.Item label="CPU Model" span={2}>{system?.cpuModel}</Descriptions.Item>
<Descriptions.Item label="CPU Usage"><MetricCpuRatio system={system} /></Descriptions.Item> <Descriptions.Item label="CPU Usage"><MetricCpuRatio system={system} /></Descriptions.Item>
<Descriptions.Item label="Cores"><MetricCpuUsed system={system} /></Descriptions.Item> <Descriptions.Item label="Cores"><MetricCpuUsed system={system} /></Descriptions.Item>