In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you how to achieve Fabric blockchain based on Prometheus and StatsD operation and maintenance monitoring, I believe most people do not know much, so share this article for your reference, I hope you have a lot of harvest after reading this article, let us go to understand it together!
1. Configure OPS services for Hyperledger Fabric nodes
Hyperledger Fabric 1.4 provides the following features for the Operations Services API for peer and order nodes:
Log level management: /logspec
Node Health Check: /healthz
Operation monitoring indicators: /metrics
Configuring the operation and maintenance services of Fabric blockchain nodes is not cutting-edge rocket technology, but it will not be easy if you miss some details.
First, modify core.yaml to configure the peer node's OPS services, mainly including the configuration of listening addresses and TLS (we will temporarily disable this part).
Open core.yaml in an editor:
$ vi ~/fabric-samples/config/core.yaml
The following figure shows the default value of the peer node's O & M service listening address listeAddress:
Now let's start the BYFN network and try to access the log level api.
$ cd ~/fabric-samples/first-network$ ./ byfn.sh -m up$ docker exec -it cli bash# curl peer0.org1.example.com:9443/logspec
Unfortunately, the curl command returns the following error:
curl: (7) Failed to connect to peer0.org1.example.com port 9443: Connection refused
Let's see what the reason is.
First check our OPS configuration and open the core.yaml file:
# vi /etc/hyperledger/fabric/core.yaml
As you may recall, we used 127.0.0.1 as the value for listenAddress, which means that the operations api cannot be accessed from the outside.
Let's do what is necessary inside the peer container to check again. This time we'll use wget instead of curl because curl is not installed inside the container.
$ docker exec -it peer0.org1.example.com bash# wget peer0.org1.example.com:9443/logspec
As expected, the error message appears again:
Connecting to peer0.org1.example.com (peer0.org1.example.com)… failed: Connection refused
But if you connect with 127.0.0.1, it will succeed:
# wget 127.0.0.1:9443/logspec
The results were as follows:
This indicates that we need to set the listening address for operations.
To do this, modify the docker-compose file to specify the CORE_OPERATIONS_LISTENADDRESS environment variable for each peer.
$ vi ~/fabric-samples/first-network/base/docker-compose-base.yaml
Refer to the figure below for modifications:
Now let's try accessing the/logspec API again, and don't forget to restart the BYFN network.
$ docker exec -it cli bash# curl peer0.org1.example.com:9443/logspec
The output is as follows:
Similarly, we can check node health:
# curl peer1.org1.example.com:9443/healthz
The output is as follows:
Finally, let's set ORE_METRICS_PROVIDER=prometheus for each peer in docker-compose-base.yaml to enable the prometheus metric and modify core.yaml to declare the metric provider prometheus:
If configured correctly, executing the following command in the cli container will output the current values of a set of monitoring metrics:
2. Monitor Hyperledger Fabric network performance metrics with Prometheus
First download the latest version of Prometheus and extract:
$ curl -LO https://github.com/prometheus/prometheus/releases/download/v2.7.1/prometheus-2.7.1.linux-amd64.tar.gz \$ tar -xvzf prometheus-2.7.1.linux-amd64.tar.gz
The prometheus.yml file can be found in the prometheus folder. We need to modify this file to grab Hyperledger Fabric metrics: add job_name and targets to the scrape_configs section.
Now we can run prometheus with docker:
$ sudo docker run -d --name prometheus-server -p 9090:9090 \ --restart always \ -v /home/mccdev/prometheus/prometheus/prometheus.yml:/prometheus.yml \ prom/prometheus \ --config.file=/prometheus.yml
Note that since docker always starts containers on private networks, we need to add prometheus containers to the fabric network. View fabric networks with the following command:
$ docker inspect peer1.org1.example.com
Connect the prometheus container to the fabric network:
$ sudo docker network connect net_byfn 5b8cbf9d8fa6
Statistics can be accessed at http://localhost:9090/
To check whether the running metrics of peer have been successfully captured, enter scrape_samples_scraped to view the result table, which should not be empty.
3. Monitor Hyperledger Fabric network performance metrics with StatsD/Graphite
Now we change StatsD to visually monitor Fabric network performance metrics, Prometheus is pull, StatsD is push.
First, we need to get docker images of Graphite and StatsD from here.
Then, start the Graphite container:
$ docker run -d\ --name graphite\ --restart=always\ -p 80:80\ -p 2003-2004:2003-2004\ -p 2023-2024:2023-2024\ -p 8125:8125/udp\ -p 8126:8126\ graphiteapp/graphite-statsd
Now it's time to modify docker-copy-base.yaml. Each peer should set the following environment variables:
CORE_OPERATIONS_LISTENADDRESSCORE_METRICS_PROVIDERCORE_METRICS_STATSD_ADDRESSCORE_METRICS_STATSD_NETWORKCORE_METRICS_STATSD_PREFIX
We should also make sure to specify port 8125. An example of a peer configuration is as follows:
peer0.org1.example.com: container_name: peer0.org1.example.com extends: file: peer-base.yaml service: peer-base environment: - CORE_PEER_ID=peer0.org1.example.com - CORE_PEER_ADDRESS=peer0.org1.example.com:7051 - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051 - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051 - CORE_PEER_LOCALMSPID=Org1MSP # metrics - CORE_OPERATIONS_LISTENADDRESS=peer0.org1.example.com:8125 - CORE_METRICS_PROVIDER=statsd - CORE_METRICS_STATSD_ADDRESS=graphite:8125 - CORE_METRICS_STATSD_NETWORK=udp - CORE_METRICS_STATSD_PREFIX=PEER_01 volumes: - /var/run/:/host/var/run/ - ../ crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp - ../ crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls - peer0.org1.example.com:/var/hyperledger/production ports: - 7051:7051 - 7053:7053 - 8125:8125
Note the ports used: for peer0, the ports should be 8125:8125, peer1 should be 9125:8125, and so on.
Orderers should be configured as follows:
- ORDERER_OPERATIONS_LISTENADDRESS=orderer.example.com:8125- ORDERER_METRICS_PROVIDER=statsd- ORDERER_METRICS_STATSD_ADDRESS=graphite:8125- ORDERER_METRICS_STATSD_NETWORK=udp- ORDERER_METRICS_STATSD_PREFIX=ORDERERports: - 7125:8125
Now let's start BYFN network.
Remember to connect the Graphite container to the BYFN network, otherwise you will see the following error:
Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.example.com:7051: failed to create new connection: context deadline exceeded
The peer container log will show that no graphite was found in the network:
Error: failed to initialize operations subystems: dial udp: lookup graphite on 127.0.0.11:53: no such host
Connect the graphite container to the fabric network using the following command:
$ sudo docker network connect net_byfn graphite
If everything is OK, you should be able to see operating indicators at the following address:
http://localhost/metrics/index.json
The results were as follows:
Visit the following address to view the visualized data:
http://localhost/
The results page is as follows:
The above is all the content of this article "How to implement operation and maintenance monitoring of Fabric blockchain based on Prometheus and StatsD". Thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.