관리 메뉴

피터의 개발이야기

[kafka] kafka 모니터링 docker 환경 세팅 본문

DevOps/kafka

[kafka] kafka 모니터링 docker 환경 세팅

기록하는 백앤드개발자 2024. 3. 17. 13:00
반응형

ㅁ 들어가며

ㅇ [kafka] docker compose로  kafka cluster 구성 및 kafka-ui 모니터링 작성 후 Grafana를 이용한 모니터링 방법에 대해서 공부하였다.

 Kafka Monitoring Stack for Docker Compose (Prometheus / Grafana)의 내용을 바탕으로 docker kafka 모니터링 환경을 세팅해 보았다.

ㅇ 작업하면서 환경 세팅 트러블 슈팅은 [kafka] kafka 모니터링 방법 공부 (docker 컨테이너 생성, M1 칩 no specific platform 오류를 colima로 해결) 에 정리하다.

 

ㅁ git clone

$ git clone https://github.com/streamthoughts/kafka-monitoring-stack-docker-compose.git
Cloning into 'kafka-monitoring-stack-docker-compose'...
remote: Enumerating objects: 248, done.
remote: Counting objects: 100% (125/125), done.
remote: Compressing objects: 100% (51/51), done.
remote: Total 248 (delta 91), reused 96 (delta 72), pack-reused 123
Receiving objects: 100% (248/248), 487.17 KiB | 8.86 MiB/s, done.
Resolving deltas: 100% (149/149), done.

ㅁ docker-compose 생성 및 실행

version: '3.8'
services:
  grafana:
    image: "grafana/grafana:${GRAFANA_VERSION}"
    ports:
     - "3000:3000"
    environment:
      GF_PATHS_DATA : /var/lib/grafana
      GF_SECURITY_ADMIN_PASSWORD : kafka
    volumes:
     - ./grafana/provisioning:/etc/grafana/provisioning
     - ./grafana/dashboards:/var/lib/grafana/dashboards
    container_name: grafana
    depends_on:
     - prometheus
    networks:
      - kafka-platform

  prometheus:
    image: "prom/prometheus:${PROMETHEUS_VERSION}"
    ports:
     - "9090:9090"
    volumes:
     - ./etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command: "--config.file=/etc/prometheus/prometheus.yml"
    container_name: prometheus
    networks:
      - kafka-platform

  jmx-kafka101:
    image: "sscaling/jmx-prometheus-exporter"
    platform: "linux/amd64"
    ports:
     - "5556:5556"
    environment:
     CONFIG_YML : "/etc/jmx_exporter/config.yml"
    volumes:
     - ./etc/jmx_exporter/config_kafka101.yml:/etc/jmx_exporter/config.yml
    container_name: jmx-kafka101
    depends_on:
     - kafka101
    networks:
      - kafka-platform

  zk1:
    image: confluentinc/cp-zookeeper:${CONFLUENT_VERSION}
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
      ZOOKEEPER_INIT_LIMIT: 5
      ZOOKEEPER_SYNC_LIMIT: 2
    ports:
     - "2181:2181"
    container_name: zookeeper1
    networks:
      - kafka-platform

  kafka101:
    image: confluentinc/cp-kafka:${CONFLUENT_VERSION}
    depends_on:
      - zk1
    ports:
      - "9092:9092"
      - "9991:9991"
    container_name: kafka101
    environment:
      KAFKA_BROKER_ID: 101
      KAFKA_JMX_PORT: 9991
      KAFKA_ZOOKEEPER_CONNECT: zookeeper1:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka101:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_LOG_RETENTION_MS: 60000
      CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: kafka101:29092
      CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper1:2181
      CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
      CONFLUENT_METRICS_ENABLE: 'true'
      KAFKA_HEAP_OPTS: ${KAFKA_HEAP_OPTS}
    networks:
      - kafka-platform

  kafka-ui:
    image: provectuslabs/kafka-ui:latest
    container_name: kafka-ui
    depends_on:
      - kafka101
    ports:
      - 8080:8080
    environment:
      - DYNAMIC_CONFIG_ENABLED=true
      - KAFKA_CLUSTERS_0_NAME=peters_kafka
      - KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka101:29092
    networks:
      - kafka-platform

networks:
  kafka-platform:
    name: kafka-platform
    driver: bridge

 ㅇ kafka-monitor.yml 생성한다.

 

docker-compose -f kafka-monitor.yml up -d

ㅇ Single Zookeeper/Kafka with Prometheus/Grafana버젼으로 실행하였다.

ㅇ 코어: kafka + zookeeper(분산데이터 저장소)

ㅇ 모니터링: prometheus(시스템 정보의 시간 별 메타정보 저장) + grafana(시간별 정보를 UI로 표출) 

 

ㅁ Grafana 접속

ㅇ 로그인 => localhost:3000, id: admin, pwd: kafka

ㅇ 기본적으로 Datasource와 Dashboard가 설정되어 있다.

 

ㅁ Topic 생성

$ docker exec -it kafka101 \
kafka-topics \
--create \
--partitions 3 \
--replication-factor 1 \
--topic demo-topic \
--bootstrap-server kafka101:29092

ㅇ 토픽은 생성되었고, 토픽에 테스트 트래픽을 위해 Produce와 Consume를 설정한다.

 

ㅁ Produce messages

$ docker exec -it kafka101 \
kafka-producer-perf-test \
--throughput 500 \
--num-records 100000000 \
--topic demo-topic \
--record-size 100 \
--producer-props bootstrap.servers=kafka101:29092

ㅇ 메시지를 500개씩 발행한다.

ㅁ Consume messages

$ docker exec -it kafka101 \
kafka-consumer-perf-test \
--messages 100000000 \
--timeout 1000000 \
--topic demo-topic \
--reporting-interval 1000 \
--show-detailed-stats \
--bootstrap-server kafka101:29092

ㅇ 메시지를 소비하고 있다.

ㅇ 구체적으로 모니터링 지표를 위해 Grafana Dashboard를 확인해 보자.

 

ㅁ Grafana Dashboard 목록

 

ㅁ Kafka Cluster / Global HealthCheck

 

ㅁ Kafka Broker / Performance & Latency

 

ㅁ Kafka / Brokers JVM & OS

 

ㅁ Kafka / Hard Disk Usage

 

ㅁ Kafka Broker / Zookeeper Connection

 

 

ㅁ Kafka Cluster / Replication

 

ㅁ Kafka Topics / Logs

 

ㅁ Grafana Dashboard 참조 검색 방법

ㅇ 참고로 Dashborads로 이동하여 kafka cluster로 검색하면, 다양한 grafana dashboard 샘플을 얻을 수 있다.

반응형
Comments