前置条件

kafka版本:2.2.1

jmeter版本:5.3

插件:ApacheJMeter_ssh-1.2.0.jar

1.拷贝 ApacheJMeter_ssh-1.2.0.jar 到/lib/ext目录下
2.拷贝 jsch-0.1.55.jar 到/lib目录下
3.启动jmeter后,在Sampler下找到SSH Command和SSH SFTP进行配置后,可以让jmeter与linux进行交互

kafka 常用指令:

  • 查看offset

使用kafka bin路径下kafka-run-class.sh可实现topic 偏移量查看,需要填写的参数如下:

--broker-list <String: hostname: REQUIRED: The list of hostname and port,...,hostname:port> port of the server to connect to.
--max-wait-ms <Integer: ms> DEPRECATED AND IGNORED: The max amount of time each fetch request waits. (default: 1000)
--offsets <Integer: count> DEPRECATED AND IGNORED: number of offsets returned (default: 1)
--partitions <String: partition ids> comma separated list of partition ids. If not specified, it will find offsets for all partitions (default:)
--time  <Long: timestamp/-1(latest)/-2 timestamp of the offsets before that (earliest)> (default: -1)
--topic    <String: topic> REQUIRED: The topic to get offset from.

查看指定topic偏移量—— --time=-1

./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list service-kafka-admin-broker-0:9092 -topic test_by_cheliang --time -1
test_by_cheliang:0:0
test_by_cheliang:1:2
test_by_cheliang:2:0
test_by_cheliang:3:0
test_by_cheliang:4:0
test_by_cheliang:5:0
test_by_cheliang:6:0
test_by_cheliang:7:0
test_by_cheliang:8:0
test_by_cheliang:9:0

返回kafka topic所有分区的最大偏移量值

查看指定分区topic偏移量—— --time=-1

./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list service-kafka-admin-broker-0:9092 --partitions 1 -topic test_by_cheliang -time -1

test_by_cheliang:1:2

返回kafka topic指定分区的最大偏移量值

查看topic偏移量—— --time=-2

./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list service-kafka-admin-broker-0:9092 --topic test_by_cheliang --time -2
test_by_cheliang:0:0
test_by_cheliang:1:0
test_by_cheliang:2:0
test_by_cheliang:3:0
test_by_cheliang:4:0
test_by_cheliang:5:0
test_by_cheliang:6:0
test_by_cheliang:7:0
test_by_cheliang:8:0
test_by_cheliang:9:0

返回kafka topic指定分区的最小偏移量值

查看topic偏移量——不指定time参数

./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list service-kafka-admin-broker-0:9092 --topic test_by_cheliang
test_by_cheliang:0:0
test_by_cheliang:1:2
test_by_cheliang:2:0
test_by_cheliang:3:0
test_by_cheliang:4:0
test_by_cheliang:5:0
test_by_cheliang:6:0
test_by_cheliang:7:0
test_by_cheliang:8:0
test_by_cheliang:9:0

不指定time参数,默认返回所有topic分区最大偏移量

./kafka-topic.sh相关

--alter

Alter the number of partitions,replica assignment, and/orconfiguration for the topic.

--bootstrap-server <String: server to connect to> 

kafka连接信息

--command-config <String: command config property file>

Property file containing configs to be passed to Admin Client. This is vused only with --bootstrap-server option for describing  nd altering broker configs.
--config <String: name=value> 

A topic configuration override for the topic being created or altered.The following is a list of valid configurations:cleanup.policy compression.type delete.retention.ms
file.delete.delay.ms flush.messages flush.ms follower.replication.throttled. replicas
index.interval.bytes leader.replication.throttled.replicas max.message.bytes message.downconversion.enable message.format.version message.timestamp.difference.max.ms
message.timestamp.type min.cleanable.dirty.ratio min.compaction.lag.ms min.insync.replicas preallocate retention.bytes retention.ms segment.bytes
segment.index.bytes segment.jitter.ms segment.ms unclean.leader.election.enable See the Kafka documentation for full details on the topic configs.It is
supported only in combination with -- create if --bootstrap-server option is used.

 --create Create a new topic.
 --delete  Delete a topic.
 --delete-config <String: name>

A topic configuration override to be removed for an existing topic (see the list of configurations under the --config option). Not supported with the --bootstrap-server option.

 --describe  List details for the given topics.
 --disable-rack-aware  Disable rack aware replica assignment
 --exclude-internal

exclude internal topics when running list or describe command. The internal topics will be listed by default

 --force Suppress console prompts 
 --help  Print usage information.
 --if-exists

if set when altering or deleting or describing topics, the action will only execute if the topic exists. Not supported with the --bootstrap- server option.

 --if-not-exists

if set when creating topics, the action will only execute if the topic does not already exist. Not supported with the --bootstrap- server option.

 --list  List all available topics.

--replica-assignment <String:  
broker_id_for_part1_replica1 : 
broker_id_for_part1_replica2 , 
broker_id_for_part2_replica1 :
broker_id_for_part2_replica2 , ...>

 A list of manual partition-to-broker assignments for the topic being created or altered. 

--replication-factor <Integer: 
replication factor> created.

 The replication factor for each partition in the topic being 
 --topic <String: topic>

The topic to create, alter, describe or delete. It also accepts a regular expression, except for --create option. Put topic name in double quotes and use the '\' prefix to escape regular expression symbols; e.g. "test\.topic".

 --topics-with-overrides

if set when describing topics, only show topics that have overridden configs

 --unavailable-partitions

if set when describing topics, only show partitions whose leader is not available

 --under-replicated-partitions

if set when describing topics, only show under replicated partitions

 --zookeeper <String: hosts>

DEPRECATED, The connection string for the zookeeper connection in the form host:port. Multiple hosts can be given to allow fail-over.

--partitions <Integer: # of partitions>

The number of partitions for the topic being created or altered (WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected



  • 查看kafka topic

  返回所有kafka topic  

  # ./kafka-topics.sh --bootstrap-server service-kafka-admin-broker-0:9092 --list
  test_by_cheliang_mutil
  test_by_cheliang_single
  __consumer_offsets

  返回用户手动创建topic  

  # ./kafka-topics.sh --bootstrap-server service-kafka-admin-broker-0:9092 --list --exclude-internal
  test_by_cheliang_mutil
  test_by_cheliang_single

  • 创建kafka topic

  ./kafka-topics.sh --create --bootstrap-server service-kafka-admin-broker-0:9092 --topic hxf_test --replication-factor 1 --partitions 1
  WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.

  • 查看topic情况

  ./kafka-topics.sh --bootstrap-server service-kafka-hxfaaa-broker-0:9092 --describe --topic hxf_test
  Topic:hxf_test    PartitionCount:1    ReplicationFactor:1    Configs:min.insync.replicas=1,segment.bytes=1073741824,max.message.bytes=1000000
  Topic: hxf_test   Partition: 0       Leader: 0          Replicas: 0 Isr: 0

  • 修改kafka topic属性
# ./kafka-topics.sh --bootstrap-server service-kafka-admin-broker-0:9092 --alter --partitions 10 --topic hxf_test

./kafka-topics.sh --bootstrap-server service-kafka-admin-broker-0:9092 --describe --topic hxf_test
Topic:hxf_test    PartitionCount:10    ReplicationFactor:1    Configs:min.insync.replicas=1,segment.bytes=1073741824,max.message.bytes=1000000
Topic: hxf_test   Partition: 0         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 1         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 2         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 3         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 4         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 5         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 6         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 7         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 8         Leader: 0          Replicas: 0 Isr: 0
Topic: hxf_test   Partition: 9         Leader: 0          Replicas: 0 Isr: 0

consumer-group相关

# 查看某消费组(consumer_group)具体消费情况(活跃的消费者以及lag情况等等)
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group test_group --describe # 列出当前所有的消费组
bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list # 旧版
bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --group test_group --describe

consumer相关

# 消费数据(从latest消费)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic # 消费数据(从头开始消费)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --from-beginning # 消费数据(最多消费多少条就自动退出消费)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --max-messages 1 # 消费数据(同时把key打印出来)
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test_topic --property print.key=true # 旧版
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test_topic

producer相关

# 生产数据
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic # 生产数据(写入带有key的message)
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic --property "parse.key=true" --property "key.separator=:"

jmeter中执行kafka topic指令的更多相关文章

  1. 如何在 ubuntu linux 一行中执行多条指令

    cd /my_folder rm *.jar svn co path to repo mvn compile package install 使用&& 运算符连接指令 cd /my_f ...

  2. 使用JMeter进行Apache Kafka负载测试

    1.卡夫卡负载测试 在这个Apache Kafka教程中,我们将了解如何使用Apache JMeter,如何在Apache Kafka上执行Kafka负载测试.此外,这个Kafka负载测试教程教我们如 ...

  3. JMeter进行Apache Kafka负载测试

    1.卡夫卡负载测试 在这个Apache Kafka教程中,我们将了解如何使用Apache JMeter,如何在Apache Kafka上执行Kafka负载测试.此外,这个Kafka负载测试教程教我们如 ...

  4. JMeter 中的如何区分 Server Time 和 Network Time

    在 LR 中是有一个“网页细分图”的,通过这个图,你可以比较容易的区分哪些请求的响应时间最长,如果响应时间过程,是消耗在server处理的时候,还是消耗在网络传输过程中——也就是所谓的 Server ...

  5. 【转】Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍

    Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍 要求: 今天要测试上千条数据,且每条数据要求执行多次,(模拟多用户多次抽奖) 1.用户id有175个,且没有任何排序规 ...

  6. 浏览器中调用PHP在执行linux sudo指令时报sudo: sorry, you must have a tty to run sudo

    在php程序中使用了exec函数调用sudo指令,在浏览器中访问后,报sudo: sorry, you must have a tty to run sudo错误. 按照网上搜到的方法,修改/etc/ ...

  7. Jmeter===Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍(转)

    Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍 要求: 今天要测试上千条数据,且每条数据要求执行多次,(模拟多用户多次抽奖) 1.用户id有175个,且没有任何排序规 ...

  8. jmeter中重要组件及其执行顺序

    jmeter中重要组件有:Sampler,计时器,前置处理器和后置处理器,断言,Controller,Listener和配置原件. 同类组件之间是从上到下的顺序执行,不同组件之间是按照以下的顺序执行的 ...

  9. Jmeter中的几个重要测试指标释义

    一.基本概念 1.测试计划是使用 JMeter 进行测试的起点,它是其它 JMeter 测试元件的容器. 2.线程组:代表一定数量的并发用户,它可以用来模拟并发用户发送请求.实际的请求内容在Sampl ...

随机推荐

  1. Sentinel-Go 源码系列(一)|开篇

    大家好呀,打算写一个 Go 语言组件源码分析系列,一是为了能学习下 Go 语言,看下别人是怎么写 Go 的,二是也掌握一个组件. 本次选择了 Sentinel-Go,一是对 Java 版本的 Sent ...

  2. CSS引入字体文件

    在css引入字体文件可以直接把以下代码复制到css文件中 /* 字体声明 */ @font-face {font-family: 'icomoon';src: url('fonts/icomoon.e ...

  3. 树链剖分好(du)题(liu)选做

    1.luogu P4315 月下"毛景树" 题目链接 前言: 这大概是本蒟蒻A掉的题里面码量最大的一道题了.我自认为码风比较紧凑,但还是写了175行. 从下午2点多调到晚上8点.中 ...

  4. Java:检查异常与未检查异常

    一.异常的介绍 Throwable 是 Java 中所有错误和异常的超类.Java 虚拟机仅抛出属于此类(或其子类之一)的实例对象,或者是 throw 语句也可以抛出该对象.同样,catch 子句中的 ...

  5. 同人逼死官方系列!基于sddc 协议的SDK框架 sddc_sdk_lib 解析

    基于sddc 协议的SDK框架 sddc_sdk_lib 解析 之前在移植 libsddc 库的时候感觉官方 demo 太低效了( ̄. ̄),复制粘贴代码好累,而且写出一个BUG,其他复制的代码整个就裂 ...

  6. Python3 TypeError: initial_value must be str or None, not bytes

    response.read() returns an instance of bytes while StringIO is an in-memory stream for text only. Us ...

  7. hdu 1847 Good Luck in CET-4 Everybody! (简单博弈)

    题意: n张牌,双方轮流抓取.每人每次抓取的牌数必须是2的幂次(1,2,4,8...). 最后抓完的人胜. 思路 : 考虑剩3张牌,后手胜. 考虑3的倍数.假设先抓者当轮抓2x 张,2x %3等于1或 ...

  8. 安装与卸载JDK8

    前言:学习Java的第一步需要先配置好JDK环境,而JDK8是目前使用最广泛的JDK版本.本文讲解了如何下载安装和卸载JDK8.以下环境为Windows10 下载JDK安装包 Oracle官网 所有J ...

  9. uni-app(Vue)中(picker)用联动(关联)选择以至于完成某些功能

    如下图所示,在项目中需求是通过首先选择学生的专业,选好之后在每个专业下面选择对应的学期,每个学期有对应的学费,因此就需要联动选择来实现这一功能. 以下仅展示此功能主要代码: <div class ...

  10. 2021.11.2-测试T1数独

    痛苦 题目 数 独 [问题描述] 给定一个9*9矩阵,对其进行几种操作,分别是插入,删除,合并,查询,输出 主要学到了一些特别的操作. (1)备份( 本蒟蒻第一次了解到) (2)对与数据的一些特别的改 ...