Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
feat: display cluster node count (requires solana v0.14.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 24, 2019
1 parent 16990ca commit 958220b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import _ from 'lodash';
import {matchPath, Route} from 'react-router';
import './App.css';
import createBrowserHistory from 'history/createBrowserHistory';
import {Connection} from '@solana/web3.js';

import EndpointConfig from './EndpointConfig';
import BxDataTable from './BxDataTable';
Expand Down Expand Up @@ -129,14 +130,20 @@ class App extends Component {
super(props);

this.ws = null;
this.connection = new Connection(EndpointConfig.BLOCK_EXPLORER_RPC_URL);

this.state = {
enabled: true,
dialogOpen: false,
selectedValue: null,
currentMatch: null,
stateLoading: false,
globalStats: {},
globalStats: {
'node-count': 0,
'!blk-last-slot': 0,
'!txn-count': 0,
'!txn-per-sec-max': 0,
},
txnStats: {},
users: [],
userState: {},
Expand Down Expand Up @@ -201,11 +208,19 @@ class App extends Component {
});
}

updateGlobalStats() {
async updateGlobalStats() {
this.getRemoteState(
'globalStats',
`http:${BLOCK_EXPLORER_API_BASE}/global-stats`,
);

try {
const nodes = await this.connection.getClusterNodes();
this.updateSpecificGlobalStateAttribute('node-count', nodes.length);
} catch (err) {
this.updateSpecificGlobalStateAttribute('node-count', '?');
console.log(err);
}
}

updateTxnStats() {
Expand Down
17 changes: 15 additions & 2 deletions src/BxStatsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BxStatsTable extends React.Component {
<Card>
<CardContent onClick={() => this.copyLeaderPublickey()}>
<Typography variant="h5" component="h2" align="center">
Current Leader
Leader
<BxHelpLink text="Leader" term="leader"/>
</Typography>
<Typography component="p" align="center">
Expand All @@ -44,6 +44,19 @@ class BxStatsTable extends React.Component {
</CardContent>
</Card>
</Grid>
<Grid item>
<Card>
<CardContent>
<Typography variant="h5" component="h2">
Node Count
<BxHelpLink text="Node Count" term="node-count"/>
</Typography>
<Typography component="p" align="center">
{globalStats['node-count']}
</Typography>
</CardContent>
</Card>
</Grid>
<Grid item>
<Card>
<CardContent>
Expand Down Expand Up @@ -87,7 +100,7 @@ class BxStatsTable extends React.Component {
<Card>
<CardContent>
<Typography variant="h5" component="h2">
Total Transactions
Transactions
<BxHelpLink text="All-Time Total Transactions" term="transaction"/>
</Typography>
<Typography component="p" align="center">
Expand Down
1 change: 1 addition & 0 deletions src/EndpointConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let EndpointConfig = {
BLOCK_EXPLORER_API_BASE: `//${window.location.hostname}:3001`,
BLOCK_EXPLORER_RPC_URL: `http://${window.location.hostname}:8899`,
};

export default EndpointConfig;

0 comments on commit 958220b

Please sign in to comment.