Aim: Setup a monitoring website for your local ethereum chain using eth-netstats.
Prerequisites
- RPC of a running ethereum blockchain.
- git
- node
- npm
First of all, you need to get one RPC running somewhere. Let’s suppose, you got it running on port 8545 and are allowed to access it using localhost.
Second step would be to setup a monitoring site similar to https://ethstats.net
1. Setting up monitoring site
This will be the site where all the information is displayed. And your blockchain server should be able to access the port at which this site is requesting data. The default one present at cubedro is a bit outdated, and I am going to use my branch which has some updates in regard to displaying geographical location of servers.
https://github.com/AyushyaChitransh/eth-netstats.git
cd eth-netstats
git fetch -va
git checkout patch-1
npm install
sudo npm install -g grunt-cli
grunt all
These commands will install the required things. Now we are ready to spin up our site. I generally use this inside a screen:
# create a new screen named ethstat screen -S ethstat PORT=3000 WS_SECRET="apple" npm start # press ctrl+A+D to come out of screen # to reattach to screen, use this command: # screen -dr ethstat
Now we are having an empty site. No data is being displayed yet. Let’s get to data part.
2. Start the blockchain client
You can start blockchain client and you need to take a note of the RPC port and the network port at which peers are communicating. By default, RPC port is 8545
and network port is 30303
. If we have left these things to default, we can now proceed to next step.
3. Sending data to the site
We are going to use https://github.com/cubedro/eth-net-intelligence-api.git to send data to the site that we spun up in Step 1. Let’s set this up:
git clone https://github.com/cubedro/eth-net-intelligence-api.git cd eth-net-intelligence-api npm install -g pm2
Now we need to edit the eth-net-intelligence-api/app.json
file.
It looks like this:
[ { "name" : "node-app", "script" : "app.js", "log_date_format" : "YYYY-MM-DD HH:mm Z", "merge_logs" : false, "watch" : false, "max_restarts" : 10, "exec_interpreter" : "node", "exec_mode" : "fork_mode", "env": { "NODE_ENV" : "production", "RPC_HOST" : "localhost", "RPC_PORT" : "8545", "LISTENING_PORT" : "30303", "INSTANCE_NAME" : "", "CONTACT_DETAILS" : "", "WS_SERVER" : "wss://rpc.ethstats.net", "WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic", "VERBOSITY" : 2 } } ]
We need to update few fields here:
- RPC_PORT, LISTENING_PORT: If you are not using default, then you can customize it here.
- INSTANCE_NAME: This would be the name which we want to be displayed as the name of our blockchain server. For example, you can name it
Personal Blockchain 1
- WS_SERVER: This will be the details of the server we setup in Step 1. If you are using the same system, then you can write here
localhost
. If you have set your monitoring site anywhere else, you need to provide that address. Some of the example values are as follows:- wss://localhost:3000 This is a socket address, but similar to
https
- ws://localhost:3000
- http://localhost:3000
- https://localhost:3000
- https://ethstats.net
- http://123.123.123.123:3000
- wss://localhost:3000 This is a socket address, but similar to
- WS_SECRET: This shall be the password we set while starting our monitoring site in Step 1. Here we had set as
apple
Once all the configurations are done in app.json
, we need to start the process which shall send the data to our monitoring site.
cd eth-net-intelligence-api pm2 start app.json
Some points to take a note of:
Q: Why did we perform step 2 and 3 on the same server?
A: This is to enable proper scaling in future. We could have done step 3 on the same server as of monitoring site of step 1, but in that case, every time we started a new blockchain server, we would require to modify our configurations of Step3. Moreover, the load on our monitoring site would increase when we added more blockchain servers to our monitoring list. So it would be better to club together step 2 and 3 on same server.
Q: Okay, but what if we wanted to keep our blockchain client free from any other stuff? Can we do that?
A: Totally. All we would be required to do is to setup step 3 on a different server and in the config parameter RPC_HOST
we would give the address of our blockchain server.
Feel free to ask any other question which comes to your mind. Hope this help you.