fabric提供了完善的监控数据。并且在orderer和peer中内置了http server, 通过RESTful的方式对外发布服务,叫做 Operations Service
fabric种可监控的数据指标为:
用户可以直接访问RESTful接口获取数据,但往往通过和第三方监控平台集成。
本文讨利用和Prometheus+Grafana工具,来实现fabric的监控。
其中Prometheus主要完成对宿主机、容器、区块链数据指标的收集,Grafana主要完成对数据的展示和告警
基本步骤为:
- 开启对Prometheus支持
- 启动Prometheus
- 启动Grafana
1. 开启对Prometheus支持
首先要打开orderer和peer的封印,使其支持Prometheus。
在orderer容器的yaml配置中添加以下环境变量:[单向碑~~~>]():
ORDERER_METRICS_PROVIDER=prometheus ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:17050
在peer容器的yaml配置中添加以下环境变量:[单向碑~~~>]():
CORE_METRICS_PROVIDER=prometheus CORE_OPERATIONS_LISTENADDRESS=0.0.0.0:18050
修改完成后重启orderer和peer
2. 启动Prometheus
先安装相关镜像
# prometheus镜像 docker pull prom/prometheus # grafana镜像,供展示 docker pull grafana/grafana
用docker方式运行Prometheus,yaml文件详见:[神秘的传送门]()
配置prometheus容器中的/etc/prometheus/prometheus.yml文件,连接到orderer和peer端口:
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: "prometheus" # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ["192.168.101.23:9090"] - job_name: 'fabric' static_configs: - targets: ['192.168.101.23:18050'] - targets: ['192.168.101.23:18051'] - targets: ['192.168.101.23:17050'] - targets: ['192.168.101.23:17051'] - targets: ['192.168.101.23:17052']
- 由于docker奇葩的网络设置,注意target里面的地址要写外网真实地址,不要写localhost或者127.0.0.1,尤其是在mac或者windows环境中,否则prometheus会替换成docker里面的主机名,在页面上访问不了
启动Prometheus
docker-compose -f prometheus.yaml up
打开网页看看效果:
http://localhost:9090/targets
3. 启动Grafana
准备grafana配置文件,详见:[不起眼的传送门]()
docker-compose -f grafana.yaml up
打开网页看看效果:
http://localhost:3000
初始登陆账号为admin/admin,然后添加data source,添加Dash board, 添加Pannel一系列操作了
至于Prometheus和grafana一系列华丽的操作,就不展开讲了,感兴趣的可以查看官方文档:
- https://grafana.com/docs/grafana/v7.5/
- https://prometheus.io/docs/introduction/overview/
基本思路是,grafana属于页面展示,数据来源是Prometheus, 简单的把Prometheus当作一个数据库看待 ,Prometheus提供了一种查询语言叫做PromQL,通过PromQL查询Prometheus的数据,在grafana中展示。
展示一下本项目中简单的grafana页面吧:
Ref
- https://hyperledger-fabric.readthedocs.io/en/release-2.2/operations_service.html
- https://hyperledger-fabric.readthedocs.io/en/release-2.2/metrics_reference.html#orderer-metrics
- https://juejin.cn/post/6956839519257624613
- https://www.cnblogs.com/xiao987334176/p/9930517.html
回复 agodelo 取消回复