Boohyung's Gitbook
  • Introduction
  • Research
    • Byzantine Generals' Problem
    • Bitcoin P2P Network
    • Chapter 10. Networking
    • Hyperledger Caliper
    • The Operations Service
    • Project DYOR with Notion
    • zkSync 2.0 퍼블릭 테스트넷 사용해보기
  • Development
    • Building Your First Network: first-network
    • Building Your First Network: Run the tools
    • Writing Your First Application(fabcar)
    • Hyperledger Caliper Sample(caliper-benchmarks)
    • Hyperledger Fabric Operations Service Tutorial
    • Hyperledger Fabric Monitoring with Prometheus
Powered by GitBook
On this page
  • Goal: prometheus server를 byfn network과 연동하여 블록체인 모니터링을 체험해보자!
  • 개발 환경
  • 진행
  • byfn 네트워크 연동을 위한 프로메테우스 설정
  • byfn 및 prometheus-server 구동
  • byfn과 prometheus-server 연결
  1. Development

Hyperledger Fabric Monitoring with Prometheus

source: https://medium.com/@jushuspace/hyperledger-fabric-monitoring-with-prometheus-and-statsd-f43ef0ab110e

PreviousHyperledger Fabric Operations Service Tutorial

Last updated 5 years ago

Goal: prometheus server를 byfn network과 연동하여 블록체인 모니터링을 체험해보자!

이번 포스팅에서는 fabric-sample의 byfn 네트워크를 프로메테우스와 연동하여 블록체인 모니터링을 제공하는 방법을 설명한다.

개발 환경

  • Ubuntu 18.04 LTS

  • Hyperledger Fabric v2.0.0

  • prometheus 2.16.0.linux-amd64

진행

에 접속하여 자신의 운영체제에 맞는 최신 버전의 프로메테우스를 다운로드 받는다. 필자는 다운로드 경로를 ~/fabric-samples로 설정하고 진행하였다.

byfn 네트워크 연동을 위한 프로메테우스 설정

다운로드받은 파일의 압축을 풀고 프로메테우스 설정 파일을 모니터링할 네트워크에 맞게 수정한다.

cd ~/fabric-samples
tar -xzvf prometheus-2.16.0.linux-amd64.tar.gz
cd prometheus-2.16.0.linux-amd64
vi prometheus.yml

설정 파일에서는 블록체인에서 데이터를 가져올 주기와 웹 서버 접속 주소를 확인하고 변경할 수 있다. byfn 네트워크 모니터링을 위해 scrape_configs의 job_name과 targets 속성을 아래와 같이 수정한다.

  • targets: 모니터링할 피어와 오더러 정보를 입력. 예제에서는 4개의 peer와 1개의 orderer를 대상으로 모니터링을 진행

# file: prometheus.yml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    scrape_interval: 10s

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'hyperledger_metrics'
    scrape_interval: 10s
    static_configs:
      - targets: [‘peer0.org1.example.com:9443’, ‘peer1.org1.example.com:9443’, ‘peer0.org2.example.com:9443’, ‘peer1.org2.example.com:9443’, ‘orderer.example.com:8443’]

byfn 및 prometheus-server 구동

prometheus.yml 수정이 완료되면 byfn network와 prometheus-server를 docker에 올려서 동작시킨다.

cd ..
cd first-network
# Bring up the byfn network
./byfn up
# Run the prometheus-server container
sudo docker run -d --name prometheus-server -p 9090:9090 --restart always -v /home/bhlee/my_github/fabric_samples/prometheus-2.16.0.linux-amd64/prometheus.yml:/prometheus.yml prom/prometheus --config.file=/prometheus.yml
docker ps

byfn과 prometheus-server 연결

프로메테우스와 byfn을 연결하기 위해서 아래와 같은 형식의 docker network connect 명령어를 이용한다. 네트워크의 이름은 docker inspect 명령을 통해 찾을 수 있다.

  • docker network connect <network_name> <container ID of prometheus-server>

docker inspect orderer.example.com
sudo docker network connect net_byfn 08580879c247

프로메테우스와 byfn을 연결되면 http:///localhost:9090에 접속하여 프로메테우스 서버 웹 UI를 이용할 수 있다. 연결이 잘 되었는지 Target 탭에서 State/Labels를 반드시 확인한다.

orderer와 peer에서 프로메테우스를 통해 모니터링할 수 있는 메트릭 리스트는 에서 확인할 수 있다. (해당 링크는 v2.0 기준)

https://hyperledger-fabric.readthedocs.io/en/release-2.0/metrics_reference.htm
https://prometheus.io/download/
https://prometheus.io/download/
docker ps 명령어 실행 화면
모니터링 중인 타겟 확인
metric 확인: endorser_successful_proposals(Graph)
metric 확인: endorser_successful_proposals(Console)