Blockchain NodeJS Server Monitoring

Ferry Djaja
Coinmonks
3 min readSep 10, 2018

--

I would like to walk through how to build a simple server monitoring with Blockchain. We will write a NodeJS client app that will submit the transaction to the Fabric with the server parameters like number of active memory, hardware model, number of installed CPU and RAM, server model and data center ID.

We need to have two machines running on Ubuntu. We will install NodeJS client and Hyperledger Fabric component on each machine.

The high-level architecture would be like this:

Hyperledger Fabric Server

Follow my below post to setting up the server. Install and configure Hyperledger Fabric on the first machine.

You don’t need to install and configure the REST server. Take note the IP address of this machine.

NodeJS Client App

On the second machine, install the composer-client and composer-cli:

npm install --save composer-client@0.20npm install --save composer-admin@0.20

We need to copy the admin@tutorial-network that we created on the Fabric side to the client side. Logon to the first machine and copy the admin@tutorial-network folder located $HOME/.composer/cards and $HOME/.composer/client-data.

Logon to the client machine and paste those files to the client machine.

Open the connection.json from $HOME\.composer\cards\admin@tutorial-network and update the connection string from localhost to the server IP address (for my case is 192.168.0.109):

Execute the Script

We will execute the NodeJS app on the client side:

  • To create the participant and asset, execute:
node cli serverregistry bootstrap

The script will populate the participant and asset with the predefined value:

Participant Registry
Asset Registry
  • To get the list of the asset, execute:
node cli serverregistry list

As you can see in the above screenshot, the value of Active_Memory, HW_Model, etc is still empty because we haven’t submitted the transaction.

  • To submit the transaction, execute:
node cli serverregistry submit 64 "Model A" 8 4 "Server A" ADM

with parameters:

· Active_Memory: 64

· HW_Model: Model A

· Installed_CPUs: 8

· Installed_RAM: 4

· Server_Model: Server A

· datacenterid: ADM

Try to execute the previous command: node cli serverregistry listand you will see the transaction has been populated:

  • To listen to the event, execute:
node cli serverregistry listen

Event will be emitted once you submit the transaction. You will see the console log printed out.

All codes can be found on my Git repo: https://github.com/ferrygun/NodeJS-Blockchain

Get Best Software Deals Directly In Your Inbox

--

--