Only update hardware stats when necessary (#73)

This commit is contained in:
Maciej Hirsz
2018-10-01 14:10:54 +02:00
committed by GitHub
parent 76e9155823
commit 717c5a3ac9
10 changed files with 81 additions and 24 deletions
+15 -2
View File
@@ -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`
+8 -1
View File
@@ -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;