diff --git a/packages/backend/src/Node.ts b/packages/backend/src/Node.ts index 9c9d4e6..aa073ef 100644 --- a/packages/backend/src/Node.ts +++ b/packages/backend/src/Node.ts @@ -37,6 +37,8 @@ export default class Node { private peers = 0 as Types.PeerCount; private txcount = 0 as Types.TransactionCount; + private memory = null as Maybe; + private cpu = null as Maybe; private readonly ip: string; private readonly socket: WebSocket; @@ -173,7 +175,7 @@ export default class Node { } public nodeStats(): Types.NodeStats { - return [this.peers, this.txcount]; + return [this.peers, this.txcount, this.memory, this.cpu]; } public blockDetails(): Types.BlockDetails { @@ -223,11 +225,13 @@ export default class Node { } private onSystemInterval(message: SystemInterval) { - const { peers, txcount } = message; + const { peers, txcount, cpu, memory } = message; - if (this.peers !== peers || this.txcount !== txcount) { + if (this.peers !== peers || this.txcount !== txcount || this.cpu !== cpu || this.memory !== memory) { this.peers = peers; this.txcount = txcount; + this.cpu = cpu; + this.memory = memory; this.events.emit('stats'); } diff --git a/packages/backend/src/message.ts b/packages/backend/src/message.ts index 906cbb8..7237039 100644 --- a/packages/backend/src/message.ts +++ b/packages/backend/src/message.ts @@ -54,6 +54,8 @@ export interface SystemInterval extends BestBlock { msg: 'system.interval'; txcount: Types.TransactionCount; peers: Types.PeerCount; + memory: Maybe; + cpu: Maybe; status: 'Idle' | string; // TODO: 'Idle' | ...? } diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index bf10430..45c491d 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -8,4 +8,4 @@ import * as FeedMessage from './feed'; export { Types, FeedMessage }; // Increment this if breaking changes were made to types in `feed.ts` -export const VERSION: Types.FeedVersion = 10 as Types.FeedVersion; +export const VERSION: Types.FeedVersion = 11 as Types.FeedVersion; diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index d330b0d..d237511 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -20,8 +20,10 @@ export type TransactionCount = Opaque; export type Latitude = Opaque; export type Longitude = Opaque; export type City = Opaque; +export type MemoryUse = Opaque; +export type CPUUse = Opaque; export type BlockDetails = [BlockNumber, BlockHash, Milliseconds, Timestamp, Maybe]; export type NodeDetails = [NodeName, NodeImplementation, NodeVersion, Maybe
]; -export type NodeStats = [PeerCount, TransactionCount]; +export type NodeStats = [PeerCount, TransactionCount, Maybe, Maybe]; export type NodeLocation = [Latitude, Longitude, City]; diff --git a/packages/frontend/src/components/Node/Row.tsx b/packages/frontend/src/components/Node/Row.tsx index b702a98..c2fec68 100644 --- a/packages/frontend/src/components/Node/Row.tsx +++ b/packages/frontend/src/components/Node/Row.tsx @@ -3,7 +3,7 @@ import Identicon from 'polkadot-identicon'; import { formatNumber, trimHash, milliOrSecond, secondsWithPrecision } from '../../utils'; import { State as AppState } from '../../state'; import { SEMVER_PATTERN } from './'; -import { Ago, Icon } from '../'; +import { /*Ago,*/ Icon } from '../'; import nodeIcon from '../../icons/server.svg'; import nodeValidatorIcon from '../../icons/shield.svg'; @@ -14,7 +14,9 @@ import blockIcon from '../../icons/package.svg'; import blockHashIcon from '../../icons/file-binary.svg'; import blockTimeIcon from '../../icons/history.svg'; import propagationTimeIcon from '../../icons/dashboard.svg'; -import lastTimeIcon from '../../icons/watch.svg'; +// import lastTimeIcon from '../../icons/watch.svg'; +import cpuIcon from '../../icons/microchip-solid.svg'; +import memoryIcon from '../../icons/memory-solid.svg'; import './Row.css'; @@ -28,11 +30,13 @@ export default class Row extends React.Component { + + - + {/* */} ) @@ -42,8 +46,8 @@ export default class Row extends React.Component { const { nodeDetails, blockDetails, nodeStats } = this.props; const [name, implementation, version, validator] = nodeDetails; - const [height, hash, blockTime, blockTimestamp, propagationTime] = blockDetails; - const [peers, txcount] = nodeStats; + const [height, hash, blockTime, /*blockTimestamp*/, propagationTime] = blockDetails; + const [peers, txcount, memory, cpu] = nodeStats; const [semver] = version.match(SEMVER_PATTERN) || [version]; let className = 'Node-Row'; @@ -59,11 +63,13 @@ export default class Row extends React.Component { {implementation} v{semver} {peers} {txcount} + {cpu ? `${(cpu * 100).toFixed(1)}%` : '-'} + {memory ? {memory / 1024 | 0}mb : '-'} #{formatNumber(height)} {trimHash(hash, 16)} {secondsWithPrecision(blockTime/1000)} {propagationTime === null ? '∞' : milliOrSecond(propagationTime as number)} - + {/* */} ); } diff --git a/packages/frontend/src/icons/memory-solid.svg b/packages/frontend/src/icons/memory-solid.svg new file mode 100644 index 0000000..00d18a8 --- /dev/null +++ b/packages/frontend/src/icons/memory-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/frontend/src/icons/microchip-solid.svg b/packages/frontend/src/icons/microchip-solid.svg new file mode 100644 index 0000000..8b5f050 --- /dev/null +++ b/packages/frontend/src/icons/microchip-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file