Skip to content

Instantly share code, notes, and snippets.

@futeng
Created January 14, 2021 01:21
Show Gist options
  • Save futeng/c8e61cb8bb6634b0d9aec23c309a377a to your computer and use it in GitHub Desktop.
Save futeng/c8e61cb8bb6634b0d9aec23c309a377a to your computer and use it in GitHub Desktop.
[Get all objects list in Pulsar] Get tanents, ns, topics and topic stats in Pulsar. #pulsar #shellfor
#!/usr/bin/env bash
#
# Copyright futeng@tydic.com
# May 7, 2020
#
# 脚本:get-all.sh
# 功能:获取 Pulsar 集群所有租户、命名空间、topic 和 topics stats 信息
# 位置:Pulsar安装主目录子目录执行,或者配置 PULSAR_ADMIN 变量
# 执行:sh get-all.sh
PULSAR_ADMIN="../bin/pulsar-admin"
all_topics_arr=""
all_partitioned_topics_arr=""
function get_topic_stats(){
echo
for t in ${all_topics_arr[@]}
do
echo "========= topics stats > $t"
echo $($PULSAR_ADMIN topics stats $t)
done
}
function get_partitioned_topic_stats(){
echo
for t in ${all_partitioned_topics_arr[@]}
do
echo "========= partitioned_topics stats > $t"
echo $($PULSAR_ADMIN topics partitioned-stats $t)
done
}
# 获取所有租户
tenants_arr=$($PULSAR_ADMIN tenants list)
for tenant in ${tenants_arr[@]}
do
echo
echo $tenant
# 获取租户的namespaces
ns_arr=$($PULSAR_ADMIN namespaces list $tenant)
if [[ -n $ns_arr ]]; then
#echo $ns_arr
for ns in ${ns_arr[@]}
do
echo "├── $ns"
#获取 NS 的 Topic
topic_arr=$($PULSAR_ADMIN topics list $ns)
all_topics_arr=( "${all_topics_arr[@]}" "${topic_arr[@]}" )
#echo $topic_arr
if [[ -n $topic_arr ]]; then
for topic in ${topic_arr[@]}
do
echo " ├── $topic"
subscriptions_arr=$($PULSAR_ADMIN topics subscriptions $topic)
if [[ -n $subscriptions_arr ]]; then
echo -e " ├── $subscriptions_arr"
fi
#topic_stats=$($PULSAR_ADMIN topics stats $topic)
#echo $topic_stats
done
fi
#获取 NS 的 partitioned-topics
p_topic_arr=$($PULSAR_ADMIN topics list-partitioned-topics $ns)
all_partitioned_topics_arr=( "${all_partitioned_topics_arr[@]}" "${p_topic_arr[@]}" )
if [[ -n $p_topic_arr ]]; then
#echo $p_topic_arr
for partitioned_topic in ${p_topic_arr[@]}
do
echo " ├── $partitioned_topic"
subscriptions_arr=$($PULSAR_ADMIN topics subscriptions $partitioned_topic)
if [[ -n $subscriptions_arr ]]; then
echo " ├── $subscriptions_arr"
fi
#p_topic_stats=$($PULSAR_ADMIN topics partitioned-stats $partitioned_topic)
#echo $p_topic_stats
done
fi
done
fi
done
get_topic_stats
get_partitioned_topic_stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment