mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-14 11:51:01 +00:00
Only update hardware stats when necessary (#73)
This commit is contained in:
@@ -174,9 +174,9 @@ export class Connection {
|
||||
}
|
||||
|
||||
case Actions.AddedNode: {
|
||||
const [id, nodeDetails, nodeStats, blockDetails, location] = message.payload;
|
||||
const [id, nodeDetails, nodeStats, nodeHardware, blockDetails, location] = message.payload;
|
||||
const pinned = this.pins.has(nodeDetails[0]);
|
||||
const node = new Node(pinned, id, nodeDetails, nodeStats, blockDetails, location);
|
||||
const node = new Node(pinned, id, nodeDetails, nodeStats, nodeHardware, blockDetails, location);
|
||||
|
||||
nodes.set(id, node);
|
||||
sortedInsert(node, sortedNodes, Node.compare);
|
||||
@@ -251,6 +251,19 @@ export class Connection {
|
||||
break;
|
||||
}
|
||||
|
||||
case Actions.NodeHardware: {
|
||||
const [id, nodeHardware] = message.payload;
|
||||
const node = nodes.get(id);
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.updateHardware(nodeHardware);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Actions.TimeSync: {
|
||||
this.state = this.update({
|
||||
timeDiff: (timestamp() - message.payload) as Types.Milliseconds
|
||||
|
||||
@@ -58,8 +58,8 @@ function Truncate(props: { text: string, position?: 'left' | 'right' | 'center'
|
||||
function formatStamp(stamp: Types.Timestamp): string {
|
||||
const passed = (timestamp() - stamp) / 1000 | 0;
|
||||
|
||||
const hours = Math.round(passed / 3600);
|
||||
const minutes = Math.round((passed % 3600) / 60);
|
||||
const hours = passed / 3600 | 0;
|
||||
const minutes = (passed % 3600) / 60 | 0;
|
||||
const seconds = (passed % 60) | 0;
|
||||
|
||||
return hours ? `${hours}h ago`
|
||||
|
||||
@@ -46,6 +46,7 @@ export class Node {
|
||||
id: Types.NodeId,
|
||||
nodeDetails: Types.NodeDetails,
|
||||
nodeStats: Types.NodeStats,
|
||||
nodeHardware: Types.NodeHardware,
|
||||
blockDetails: Types.BlockDetails,
|
||||
location: Maybe<Types.NodeLocation>
|
||||
) {
|
||||
@@ -60,6 +61,7 @@ export class Node {
|
||||
this.validator = validator;
|
||||
|
||||
this.updateStats(nodeStats);
|
||||
this.updateHardware(nodeHardware);
|
||||
this.updateBlock(blockDetails);
|
||||
|
||||
if (location) {
|
||||
@@ -68,10 +70,15 @@ export class Node {
|
||||
}
|
||||
|
||||
public updateStats(stats: Types.NodeStats) {
|
||||
const [peers, txs, mem, cpu, chartstamps] = stats;
|
||||
const [peers, txs] = stats;
|
||||
|
||||
this.peers = peers;
|
||||
this.txs = txs;
|
||||
}
|
||||
|
||||
public updateHardware(hardware: Types.NodeHardware) {
|
||||
const [mem, cpu, chartstamps] = hardware;
|
||||
|
||||
this.mem = mem;
|
||||
this.cpu = cpu;
|
||||
this.chartstamps = chartstamps;
|
||||
|
||||
Reference in New Issue
Block a user