首页 > 其他分享 >查看某个topic 消费速率

查看某个topic 消费速率

时间:2022-12-09 14:31:28浏览次数:38  
标签:-% date -- kafka topic 某个 速率 now

在没有监控的情况下可以这么看

查看topic 一天的消费速率

#!/bin/sh

brokers="ip:port"
topic="CMP_RADUIS_OLL_TOPIC"
path="/app/ctgkafka/ctg_kafka_instance/13/icc-5gcmp-kafka/1/bin"

y1=`date -d "24 hour ago" +"%Y-%m-%d %H:%M:%S"`
y2=`date "+%Y-%m-%d %H:%M:%S"`
yesterday1=`date -d "${y1}" +%s000`
yesterday2=`date -d "${y2}" +%s000`

last=0
now=0
speed=0

echo "【-------开始统计,当前统计时间为`date`----】"
last=$(${path}/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list ${brokers} --topic ${topic} --time ${yesterday1} | awk -F ":" '{sum1+=$NF} END {print sum1}')
now=$(${path}/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list ${brokers} --topic ${topic} --time ${yesterday2} | awk -F ":" '{sum+=$NF} END {print sum}')
let speed=(now-last)/86400

echo "昨日1天总计消费:`expr $now - $last`张,平均 TPS= $speed 张/秒"


查看一小时的消费速率

#!/bin/sh

brokers="ip:port"
topic="CMP_RADUIS_OLL_TOPIC"
path="/app/ctgkafka/ctg_kafka_instance/13/icc-5gcmp-kafka/1/bin"

#y1=`date -d "1 hour ago" +"%Y-%m-%d %H:%M:%S"`
#y2=`date "+%Y-%m-%d %H:%M:%S"`
y1="2022-06-12 09:12:00"
y2="2022-06-12 10:12:00"
yesterday1=`date -d "${y1}" +%s000`
# 转换时间戳
yesterday2=`date -d "${y2}" +%s000`
echo "$old date:${y1},now day:${y2} ; old yest:${yesterday1},now yest:${yesterday2}"
#打印时间戳

last=0
now=0
speed=0
#hourago=`date -d "1 hour ago" +"%T"`
#nowtime=`date +"%T"`
hourago=`date -d "${y1}" +"%T"`
nowtime=`date -d "${y2}" +"%T"`
echo "【-------开始统计,当前统计时间为 ${nowtime}----】" >>/app/ctgpaas/kafka_count_log.log

echo "${path}/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list ${brokers} --topic ${topic} --time ${yesterday1}"
echo "${path}/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list ${brokers} --topic ${topic} --time ${yesterday2}"

last=$(${path}/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list ${brokers} --topic ${topic} --time ${yesterday1} | awk -F ":" '{sum1+=$NF} END {print sum1}')
now=$(${path}/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list ${brokers} --topic ${topic} --time ${yesterday2} | awk -F ":" '{sum+=$NF} END {print sum}')
let speed=(now-last)/3600
echo " ${hourago}到 ${nowtime} 总计消费:`expr $now - $last`张,平均 TPS= $speed 张/秒" >>/app/ctgpaas/kafka_count_log.log




标签:-%,date,--,kafka,topic,某个,速率,now
From: https://blog.51cto.com/zhaochengsheng/5925195

相关文章