Better Sparklines (#72)

* Cleaner renders
* Add timestamps to Sparklines
* Keep track of chart history up to 1h in the past
This commit is contained in:
Maciej Hirsz
2018-10-01 11:41:40 +02:00
committed by GitHub
parent 58e19a7c58
commit 76e9155823
8 changed files with 110 additions and 37 deletions
+9 -19
View File
@@ -5,6 +5,7 @@ import { noop, timestamp, Maybe, Types, NumStats } from '@dotstats/common';
import { parseMessage, getBestBlock, Message, BestBlock, SystemInterval } from './message';
import { locate, Location } from './location';
import { getId, refreshId } from './nodeId';
import { MeanList } from './MeanList';
const BLOCK_TIME_HISTORY = 10;
const MEMORY_RECORDS = 20;
@@ -39,8 +40,9 @@ export default class Node {
private peers = 0 as Types.PeerCount;
private txcount = 0 as Types.TransactionCount;
private memory = Array<Types.MemoryUse>();
private cpu = Array<Types.CPUUse>();
private memory = new MeanList<Types.MemoryUse>();
private cpu = new MeanList<Types.CPUUse>();
private chartstamps = new MeanList<Types.Timestamp>();
private readonly ip: string;
private readonly socket: WebSocket;
@@ -177,7 +179,7 @@ export default class Node {
}
public nodeStats(): Types.NodeStats {
return [this.peers, this.txcount, this.memory, this.cpu];
return [this.peers, this.txcount, this.memory.get(), this.cpu.get(), this.chartstamps.get()];
}
public blockDetails(): Types.BlockDetails {
@@ -232,22 +234,10 @@ export default class Node {
this.peers = peers;
this.txcount = txcount;
if (cpu) {
if (this.cpu.length === CPU_RECORDS) {
this.cpu.copyWithin(0, 1);
this.cpu[CPU_RECORDS-1] = cpu;
} else {
this.cpu.push(cpu);
}
}
if (memory) {
if (this.memory.length === MEMORY_RECORDS) {
this.memory.copyWithin(0, 1);
this.memory[MEMORY_RECORDS-1] = memory;
} else {
this.memory.push(memory);
}
if (cpu != null && memory != null) {
this.cpu.push(cpu);
this.memory.push(memory);
this.chartstamps.push(timestamp());
}
this.events.emit('stats');