Monitoring Hyperledger Fabric

Pouya
3 min readSep 29, 2020

--

Overview

As time goes by, blockchain technology is getting more popular and people knowledge is getting deep and deeper. Hyperledger Fabric is one of the most popular private blockchains. implementing it is some how easy but maintaining is a bit difficult so monitoring can be a great help for it’s maintenance.

Setup

We will use fabric samples with some changes. first install Hyperledger Fabric using this link and then go through steps.

Monitoring is always easy and simple, just try following this article:

Step 1 : make some changes

go to the First Network directory and open the base/peer-base.yaml then add this to the Environment section as below:

orderer-base:
environment:
- ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:8443
- ORDERER_METRICS_PROVIDER=prometheus
peer-base:
environment:
- CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:8443
- CORE_METRICS_PROVIDER=prometheus

your final base/peer-base.yaml should be like this:

version: '2'services:
peer-base:
image: hyperledger/fabric-peer:$IMAGE_TAG
environment:
- CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:8443
- CORE_METRICS_PROVIDER=prometheus
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_GOSSIP_USELEADERELECTION=true
- CORE_PEER_GOSSIP_ORGLEADER=false
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
orderer-base:
image: hyperledger/fabric-orderer:$IMAGE_TAG
environment:
- ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:8443
- ORDERER_METRICS_PROVIDER=prometheus
- FABRIC_LOGGING_SPEC=INFO
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
- ORDERER_KAFKA_TOPIC_REPLICATIONFACTOR=1
- ORDERER_KAFKA_VERBOSE=true
- ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer

step 2 : clone the configs

clone this repository in your current directory:

git clone https://github.com/s-pouya-sh/monitoring_Fabric

step 3 : start the network

now you just need to run the following commands:

./byfn.sh upcd ./monitoring_Fabric
docker-compose -f docker-monitoring.yaml up -d

step 4: connect Prometheus to your Fabric network

as prometheus needs to communicate with the peers and the orderer, they should be connected together. run the below command to connect your prometheus to the fabric network:

docker network connect net_byfn prometheus

step 5: check the availability of your services

open your web browser and check the services:

your Prometheus:
http://YOUR_SERVER_IP_ADDRESS:9090/
your CAdvisor:
http://YOUR_SERVER_IP_ADDRESS:8080/
your Grafana:
http://YOUR_SERVER_IP_ADDRESS:3000/
your Grafana username: “admin and password: “adminPW

5.1: what you’ll see in your Prometheus:

your Prometheus

5.2: what you’ll see in your CAdvisor:

5.2.1: your server metrics:

server metrics

5.2.2: your containers metrics:

containers metrics

step 6: connect Prometheus to Grafana

6.1: go to setting and click on Data Sources

6.2: click on add data source

add data source

6.3: select Prometheus

Prometheus

6.4: in the HTTP.URL section, type: http://prometheus:9090

http://prometheus:9090

6.5: save the settings

step 7: import Grafana dashboards

search the web for good and desired dashboards for monitoring your server and the network or create one by your own.

Hope you like this article.

--

--