0% found this document useful (0 votes)
262 views

Metrics Commands

The document provides instructions for starting Zookeeper, running multiple Kafka brokers with JMX exporters, creating a Kafka topic, starting a Kafka producer and consumer, and expanding the Kafka cluster by reassigning partitions across brokers. It also discusses running Prometheus and CMAK and provides examples of Prometheus queries for monitoring Kafka metrics.

Uploaded by

test account
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
262 views

Metrics Commands

The document provides instructions for starting Zookeeper, running multiple Kafka brokers with JMX exporters, creating a Kafka topic, starting a Kafka producer and consumer, and expanding the Kafka cluster by reassigning partitions across brokers. It also discusses running Prometheus and CMAK and provides examples of Prometheus queries for monitoring Kafka metrics.

Uploaded by

test account
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Starting Zookeeper

bin/zookeeper-server-start.sh config/zookeeper.properties

EXPORT KAFKAOPTS and RUN a BROKER

export KAFKA_OPTS="-javaagent:$PWD/jmx_exporter/jmx_prometheus_javaagent-
0.13.0.jar=8080:$PWD/kafka-metrics.yml"

bin/kafka-server-start.sh config/server.properties

EXPORT KAFKAOPTS and RUN a SECOND BROKER

export KAFKA_OPTS="-javaagent:$PWD/jmx_exporter/jmx_prometheus_javaagent-
0.13.0.jar=8081:$PWD/kafka-metrics.yml"

bin/kafka-server-start.sh config/server-1.properties

EXPORT KAFKAOPTS and RUN a THIRD BROKER

export KAFKA_OPTS="-javaagent:$PWD/jmx_exporter/jmx_prometheus_javaagent-
0.13.0.jar=8082:$PWD/kafka-metrics.yml"

bin/kafka-server-start.sh config/server-2.properties

CREATE a TOPIC

bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor


1 --partitions 1 --topic test

bin/kafka-topics.sh --list --bootstrap-server localhost:9092

start a PRODUCER

bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test

start a CONSUMER

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test


--from-beginning

HOW to START PROMETHEUS


./prometheus --config.file=prometheus.yml

HOW to START CMAK


# default port 9000
bin/cmak

wtfffff:
curl -X POST localhost:9000/clusters/kafka/topics/create -H 'Content-Type:
application/json' -d '{ "topic": "yesssss", "partitions": 5, "replication": 2 }'

EXPANDING THE CLUSTER

-input all list of topics

echo '{"topics": [' > topics-to-move.json && bin/kafka-topics.sh --zookeeper


localhost:2181 --list | perl -ne 'chomp;print "{\"topic\": \"$_\"},\n"' >> topics-
to-move.json && truncate --size=-2 topics-to-move.json && echo '],"version":1}' >>
topics-to-move.json

-In this mode, given a list of topics and a list of brokers, the tool generates a
candidate reassignment to move all partitions of the specified topics to the new
brokers.

-set of brokers

brokers=$(./bin/zookeeper-shell.sh localhost:2181 ls /brokers/ids | tail -n 1 | tr


'[' ' ' | tr ']' ' ')
brokers=${brokers// /}

bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --broker-list $brokers


--topics-to-move-json-file topics-to-move.json --generate > full-reassignment-
file.json

cat full-reassignment-file.json | grep version | head -n 1 > rollback.json

cat full-reassignment-file.json | grep version | tail -n 1 > reassignment.json

bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-


file reassignment.json --execute

bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-


file reassignment.json --verify

JAVA VERSION

sudo update-alternatives --config java


DOCKER

docker run -d --net=kafka_docker_kafka_network --name broker1 -e


KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://broker0:19093,CONNECTIONS_FROM_HOST://localh
ost:9093 -e KAFKA_BROKER_ID=2 -e KAFKA_OPTS=-
javaagent:/usr/app/jmx_prometheus_javaagent.jar=7072:/usr/app/prom-jmx-agent-
config.yml -e
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,CONNECTIONS_FROM_HOST:PLAI
NTEXT -p 9093:9093 -p 7072:7072 mykafka

RUNS GOODDDDDDDD

export BROKER=1 PLISTENER=19093 ALISTENER=9093 KAFKA_ID=2 AGENT=7072

docker run -d --net=kafka_docker_kafka_network --name broker$BROKER -e


KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://broker0:$PLISTENER,CONNECTIONS_FROM_HOST://l
ocalhost:$ALISTENER -e KAFKA_BROKER_ID=$KAFKA_ID -e KAFKA_OPTS=-
javaagent:/usr/app/jmx_prometheus_javaagent.jar=$AGENT:/usr/app/prom-jmx-agent-
config.yml -e
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,CONNECTIONS_FROM_HOST:PLAI
NTEXT -p $ALISTENER:$ALISTENER -p $AGENT:$AGENT mykafka

Arithmetic Expression: Inside double-parens, a series of comma-separated arithmetic


calculations may be performed.

((BROKER++, PLISTENER++, ALISTENER++, KAFKA_ID++, AGENT++))

docker run -d --net=kafka_docker_kafka_network --name broker$1 -e


KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://broker0:$2,CONNECTIONS_FROM_HOST://localhost
:$3 -e KAFKA_BROKER_ID=$4 -e KAFKA_OPTS=-
javaagent:/usr/app/jmx_prometheus_javaagent.jar=$5:/usr/app/prom-jmx-agent-
config.yml -e
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,CONNECTIONS_FROM_HOST:PLAI
NTEXT -p $3:$3 -p $5:$5 mykafka

bin/kafka-console-consumer.sh --topic producer0topic --from-beginning


----bootstrap-server localhost:9092

-----------------------------
PROMQL-----------------------------------------------------------------------------
-----
Cpu time

avg without(instance)(rate(process_cpu_seconds_total[1m])) #average cpu time


quantile without(instance) (0.95, rate(process_cpu_seconds_total[1m])) # 95 percent
quantile

Bytes in

avg without(instance,topic)
(rate(kafka_server_brokertopicmetrics_bytesin_total{topic!=""}[1m])) #average bytes
per sec
quantile without(instance,topic) (0.95,
rate(kafka_server_brokertopicmetrics_bytesin_total{topic!=""}[1m]))

Bytes out

avg without(instance,topic)
(rate(kafka_server_brokertopicmetrics_bytesout_total{topic!=""}[1m]))
quantile without(instance,topic) (0.95,
rate(kafka_server_brokertopicmetrics_bytesout_total{topic!=""}[1m]))

Messages per sec

avg without(instance,topic)
(rate(kafka_server_brokertopicmetrics_messagesin_total{topic!=""}[1m]))
quantile without(instance,topic) (0.95,
rate(kafka_server_brokertopicmetrics_messagesin_total{topic!=""}[1m]))

Total Time

avg by(request)
(rate(kafka_network_requestmetrics_totaltimems_count{request=~"Produce|
FetchConsumer|FetchFollower"}[1m]))
quantile by(request)(0.95,
(rate(kafka_network_requestmetrics_totaltimems_count{request=~"Produce|
FetchConsumer|FetchFollower"}[1m])))

Request Queue Time

avg by(request)
(rate(kafka_network_requestmetrics_requestqueuetimems_count{request=~"Produce|
FetchConsumer|FetchFollower"}[1m]))
quantile by(request)(0.95,
rate(kafka_network_requestmetrics_requestqueuetimems_count{request=~"Produce|
FetchConsumer|FetchFollower"}[1m]))

Response Queue Time

avg by(request)
(rate(kafka_network_requestmetrics_responsequeuetimems_count{request=~"Produce|
FetchConsumer|FetchFollower"}[1m]))
quantile by(request)(0.95,
rate(kafka_network_requestmetrics_responsequeuetimems_count{request=~"Produce|
FetchConsumer|FetchFollower"}[1m]))

Request per sec

avg by(request)(rate(kafka_network_requestmetrics_requests_total{request=~"Produce|
FetchConsumer|FetchFollower"}[1m]))
quantile by(request)(0.95,
rate(kafka_network_requestmetrics_requests_total{request=~"Produce|FetchConsumer|
FetchFollower"}[1m]))

Delayed Operation Purgatory

avg by(delayedOperation)
(rate(kafka_server_delayedoperationpurgatory_purgatorysize{delayedOperation=~"Produ
ce|Fetch"}[1m]))
quantile by(delayedOperation)(0.95,
rate(kafka_server_delayedoperationpurgatory_purgatorysize{delayedOperation=~"Produc
e|Fetch"}[1m]))

You might also like