kafka 獲取topic每個分區的數據條數


執行命令

[hduser@hadoop4 bin]$ kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 192.168.43.15:9092 --topic test  --time -1
test:0:992786
test:1:1001516
test:2:1000773
test:3:1000894
test:4:1004034
[hduser@hadoop4 bin]$ kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 192.168.43.15:9092 --topic test  --time -2
test:0:0
test:1:0
test:2:0
test:3:0
test:4:0
[hduser@hadoop4 bin]$ kafka-run-class.sh kafka.tools.GetOffsetShell 
An interactive shell for getting topic offsets.
Option                                 Description                            
------                                 -----------                            
--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)>                            [Note: No offset is returned, if the 
                                         timestamp greater than recently      
                                         commited record timestamp is given.] 
                                         (default: -1)                        
--topic <String: topic>                REQUIRED: The topic to get offset from.

2、獲取條數

從上述的命令解析可以看到,
--time -1 表示獲取的最新位移值
--time -2 表示獲取的最早的位移值,可能由於最早的數據由於過期被刪除,所以最早的位移不一定是0
通過兩數相減,就可以知道當前分區的數據條數。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM