fabric网络状态监控
(一)基础概念
1.为什么要对区块链网络进行监控?
可视化界面的提供,让外部人员了解到区块链网络的运行细节,增加对区块链网络的认识。
2.采用什么手段对区块链网络进行监控?
采用WEB平台可视化界面的区块链浏览器,提供对网络的监控。
3.网络中的哪些细节需要被监控?
总体运行概况,节点,区块、交易、链码、通道等
(二)区块链浏览器部署
1.导入镜像
区块链浏览器部署需要如下镜像:
hyperledger/explorer-db 1.1.4 7d14fd39c018 2 months ago 97.7MB
hyperledger/explorer 1.1.4 805e35d5dd8f 2 months ago 187M
2.启动容器
目录 /root/11-blockchain-explorer/2-explorer 下执行,启动区块链浏览器
docker-compose up
注意根据错误提示,修改私钥文件的名字。
提示:
Ctrl + C 强制终止
3.启动服务
使用上步的命令调试通过后,后台服务方式启动程序
docker-compose up -d
4.日志分析
更新客户端网络和其他信息到数据库
explorer.mynetwork.com | [2021-04-09T05:33:11.296] [INFO] SyncPlatform - Updating the client network and other details to DB
explorer.mynetwork.com | [2021-04-09T05:33:11.309] [INFO] SyncServices - SyncServices.synchNetworkConfigToDB client first-network channel_name mychannel
explorer.mynetwork.com | [2021-04-09T05:33:11.326] [INFO] FabricUtils - generateBlockHash 0
网关,发送发现请求
explorer.mynetwork.com | [2021-04-09T05:33:11.330] [INFO] FabricGateway - Sending discovery request...
连接失败 orderer.example.com:7050
explorer.mynetwork.com | 2021-04-09T05:33:14.338Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:14.339Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer.example.com:7050 url:grpcs://localhost:7050 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:14.339Z - error: [DiscoveryService]: _buildOrderer[be discovery service] - Unable to connect to the discovered orderer orderer.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | [2021-04-09T05:33:16.391] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.439] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.441] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.455] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.458] [INFO] Platform - getClient (id:first-network)
explorer.mynetwork.com | [2021-04-09T05:33:16.462] [INFO] FabricGateway - Sending discovery request...
explorer.mynetwork.com | [2021-04-09T05:33:16.464] [INFO] FabricGateway - Have already been sending a request
explorer.mynetwork.com | 2021-04-09T05:33:17.340Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:17.341Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://localhost:7051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:17.341Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:19.470Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:19.470Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer.example.com:7050 url:grpcs://localhost:7050 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:19.470Z - error: [DiscoveryService]: _buildOrderer[be discovery service] - Unable to connect to the discovered orderer orderer.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050, url:grpcs://localhost:7050, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:20.345Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051, url:grpcs://localhost:9051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:20.345Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org2.example.com:9051 url:grpcs://localhost:9051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:20.345Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org2.example.com:9051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051, url:grpcs://localhost:9051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:22.473Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:22.473Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://localhost:7051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:22.473Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051, url:grpcs://localhost:7051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:23.348Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org3.example.com:11051, url:grpcs://localhost:11051, connected:false, connectAttempted:true
explorer.mynetwork.com | 2021-04-09T05:33:23.348Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org3.example.com:11051 url:grpcs://localhost:11051 timeout:3000
explorer.mynetwork.com | 2021-04-09T05:33:23.348Z - error: [DiscoveryService]: _buildPeer[be discovery service] - Unable to connect to the discovered peer peer0.org3.example.com:11051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org3.example.com:11051, url:grpcs://localhost:11051, connected:false, connectAttempted:true
explorer.mynetwork.com | [2021-04-09T05:33:23.348] [INFO] FabricGateway - Succeeded to send discovery request
发现组织1
explorer.mynetwork.com | [2021-04-09T05:33:23.349] [INFO] FabricClient - Discovered Org1MSP [ { mspid: 'Org1MSP',
explorer.mynetwork.com | endpoint: 'peer0.org1.example.com:7051',
explorer.mynetwork.com | name: 'peer0.org1.example.com:7051',
explorer.mynetwork.com | ledgerHeight: Long { low: 4, high: 0, unsigned: true },
explorer.mynetwork.com | chaincodes: [ [Object] ] } ]
发现组织2
explorer.mynetwork.com | [2021-04-09T05:33:23.349] [INFO] FabricClient - Discovered Org2MSP [ { mspid: 'Org2MSP',
explorer.mynetwork.com | endpoint: 'peer0.org2.example.com:9051',
explorer.mynetwork.com | name: 'peer0.org2.example.com:9051',
explorer.mynetwork.com | ledgerHeight: Long { low: 4, high: 0, unsigned: true },
explorer.mynetwork.com | chaincodes: [ [Object] ] } ]
发现组织3
explorer.mynetwork.com | [2021-04-09T05:33:23.349] [INFO] FabricClient - Discovered Org3MSP [ { mspid: 'Org3MSP',
explorer.mynetwork.com | endpoint: 'peer0.org3.example.com:11051',
explorer.mynetwork.com | name: 'peer0.org3.example.com:11051',
explorer.mynetwork.com | ledgerHeight: Long { low: 4, high: 0, unsigned: true },
explorer.mynetwork.com | chaincodes: [ [Object] ] } ]
(三)界面展示
1.仪表盘
2.网络
区块链网络是分布式网络,具有多台服务器,多个节点。要了解网络的整体运行状况不是一件容易的事情。下图展示的就是区块链网络中的节点。
字段含义:
Ledger Height 账本高度
High
Low
Unsigned 连接状态,true连接成功
3.区块
多笔交易形成一个区块,写入到区块链网络各个对等节点的磁盘上。区块打包的规则可以进行配置。
区块详情
4.交易
对世界状态的一次变更就是一次交易。物理上体现为新增一笔交易记录。交易记录最终打包为一个区块。
交易详情
5.链码
6.通道
展示当前网路上具有的应用通道,也就是链码通道
(四)监控技术
Fabric提供了SDK作为访问区块链网络的接口,提供有node,java,go,python,其中node功能最完整。这里以node为例进行介绍。
采用typescript开发,建议使用vscode作为开发工具,具有自动语法提示。
1.监控指标
大类 |
项目 |
状态 |
接口测试通过 |
仪表盘 |
区块数量 |
|
|
交易数量 |
|
|
|
节点数量 |
|
|
|
链码数量 |
|
|
|
节点名字和端口 |
|
|
|
网络 |
节点名字 |
|
可行 |
请求地址 |
|
|
|
节点类型 |
|
|
|
成员ID |
|
可行 |
|
区块高度 |
|
|
|
|
签到状态 |
|
可行 |
区块 |
区块编号 |
|
可行 |
通道名称 |
|
可行 |
|
交易编号 |
|
可行 |
|
数据哈希 |
|
可行 |
|
区块哈希 |
|
可行 |
|
之前哈希 |
|
可行 |
|
交易 |
|
|
|
交易 |
创建者 |
|
|
通道名称 |
|
|
|
交易ID |
|
|
|
类型 |
|
|
|
链码 |
|
|
|
时间戳 |
|
|
|
链码 |
链码名称 |
|
可行 |
通道名称 |
|
可行 |
|
路径 --没有 |
|
|
|
交易数量 |
|
|
|
版本 |
|
可行 |
|
|
|
|
|
通道 |
|
|
|
通道名称 |
|
可行 |
|
区块个数 |
|
|
|
交易个数 |
|
|
|
时间戳 |
|
|
2.SDK文档
https://hyperledger.github.io/fabric-sdk-node/
https://github.com/hyperledger/fabric-sdk-node
The Hyperledger Fabric Client SDK makes it possible to use APIs to interact with a Hyperledger Fabric blockchain. This readme is directed towards a current or future contributor to this project, and gives an overview of setting up the project locally and running tests. For more information on the SDK, including features and an API reference, please visit the SDK documentation.
This project publishes the following npm packages:
fabric-ca-client - client for the optional component in Hyperledger Fabric, fabric-ca. The fabric-ca component allows applications to enroll Peers and application users to establish trusted identities on the blockchain network. It also provides support for pseudonymous transaction submissions with Transaction Certificates. If the target blockchain network is configured with standard Certificate Authorities for trust anchors, the application does not need to use this package.
fabric-common - encapsulates the common code used by all fabric-sdk-node packages supporting fine grain interactions with the Fabric network to send transaction invocations
fabric-network - This package encapsulates the APIs to connect to a Fabric network, submit transactions and perform queries against the ledger at a higher level of abstraction than through the fabric-common.
fabric-protos - This package encapsulates the protobuffers that are used to communicate over gRPC
3.SDK和网络交互
应用程序通过sdk和区块链网络进行交互,需要连接的节点包括排序节点、对等节点。
4.SDK组成
名称 |
作用 |
备注 |
fabric-ca-client |
CA模块的客户端 |
|
fabric-common |
通用代码封装,工具模块 |
|
fabric-network |
网络连接,提交交易,执行查询比fabric-common提供的更高级 |
|
fabric-protos |
封装gRPC协议 |
|
参考文章:
https://www.jianshu.com/p/1224f504bf9e?appinstall=0
SDK接口,使用SDK完成对区块链网络运行概况的监控,需要用到系统链码,系统链码包如下五大类型。
系统链码名称 |
功能 |
备注 |
cscc |
配置管理 |
账本和链 |
escc |
背书签名过程 |
|
lscc |
链码生命周期管理 |
|
qscc |
账本和链码的信息查询 |
|
vscc |
验证系统链码 |
|
cscc
----------------------
GetChannels 通道
qscc
-------------
GetBlockByNumber 区块
GetChainInfo 链信息
lscc
------------
GetChaincodes 链码
5.SDK使用
Sdk使用前需要准备以下材料:
(1) 连接配置文件
(2) 身份信息(证书,私钥)
注意事项:
调用时配置参数,自动发现为真,作为本地主机为假。
2.2版本的SDK去掉了queryInfo接口
6.常见问题
接入节点peer0.org1.example.com出现如下错误:
TLS handshake failed with error EOF server=PeerServer remoteaddress=192.168.60.26:50800
原因:
Sdk调用代码中,自动发现需要设置为真