mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-13 23:11:07 +00:00
Only update hardware stats when necessary (#73)
This commit is contained in:
@@ -44,6 +44,7 @@ export default class Chain {
|
||||
|
||||
node.events.on('block', () => this.updateBlock(node));
|
||||
node.events.on('stats', () => this.feeds.broadcast(Feed.stats(node)));
|
||||
node.events.on('hardware', () => this.feeds.broadcast(Feed.hardware(node)));
|
||||
node.events.on('location', (location) => this.feeds.broadcast(Feed.locatedNode(node, location)));
|
||||
|
||||
this.updateBlock(node);
|
||||
|
||||
@@ -45,7 +45,7 @@ export default class Feed {
|
||||
public static addedNode(node: Node): FeedMessage.Message {
|
||||
return {
|
||||
action: Actions.AddedNode,
|
||||
payload: [node.id, node.nodeDetails(), node.nodeStats(), node.blockDetails(), node.nodeLocation()]
|
||||
payload: [node.id, node.nodeDetails(), node.nodeStats(), node.nodeHardware(), node.blockDetails(), node.nodeLocation()]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,6 +77,13 @@ export default class Feed {
|
||||
};
|
||||
}
|
||||
|
||||
public static hardware(node: Node): FeedMessage.Message {
|
||||
return {
|
||||
action: Actions.NodeHardware,
|
||||
payload: [node.id, node.nodeHardware()]
|
||||
};
|
||||
}
|
||||
|
||||
public static timeSync(): FeedMessage.Message {
|
||||
return {
|
||||
action: Actions.TimeSync,
|
||||
|
||||
@@ -7,12 +7,22 @@ export class MeanList<T extends number> {
|
||||
private means = Array<T>(20).fill(0 as T);
|
||||
private ticksPerMean = 1;
|
||||
|
||||
public push(val: T) {
|
||||
/**
|
||||
* Push a new value, returns true if a new mean value was produced
|
||||
*
|
||||
* @param {T} value
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
public push(val: T): boolean {
|
||||
this.period[this.periodIndex++] = val;
|
||||
|
||||
if (this.periodIndex === this.ticksPerMean) {
|
||||
this.pushMean();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public get(): Array<T> {
|
||||
|
||||
@@ -179,7 +179,11 @@ export default class Node {
|
||||
}
|
||||
|
||||
public nodeStats(): Types.NodeStats {
|
||||
return [this.peers, this.txcount, this.memory.get(), this.cpu.get(), this.chartstamps.get()];
|
||||
return [this.peers, this.txcount];
|
||||
}
|
||||
|
||||
public nodeHardware(): Types.NodeHardware {
|
||||
return [this.memory.get(), this.cpu.get(), this.chartstamps.get()];
|
||||
}
|
||||
|
||||
public blockDetails(): Types.BlockDetails {
|
||||
@@ -231,16 +235,22 @@ export default class Node {
|
||||
private onSystemInterval(message: SystemInterval) {
|
||||
const { peers, txcount, cpu, memory } = message;
|
||||
|
||||
this.peers = peers;
|
||||
this.txcount = txcount;
|
||||
if (this.peers !== peers || this.txcount !== txcount) {
|
||||
this.peers = peers;
|
||||
this.txcount = txcount;
|
||||
|
||||
if (cpu != null && memory != null) {
|
||||
this.cpu.push(cpu);
|
||||
this.memory.push(memory);
|
||||
this.chartstamps.push(timestamp());
|
||||
this.events.emit('stats');
|
||||
}
|
||||
|
||||
this.events.emit('stats');
|
||||
if (cpu != null && memory != null) {
|
||||
const cpuChange = this.cpu.push(cpu);
|
||||
const memChange = this.memory.push(memory);
|
||||
const stampChange = this.chartstamps.push(timestamp());
|
||||
|
||||
if (cpuChange || memChange || stampChange) {
|
||||
this.events.emit('hardware');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private updateLatency(now: Types.Timestamp) {
|
||||
|
||||
Reference in New Issue
Block a user