forked from TencentBlueKing/bk-install
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatus.sh
More file actions
executable file
·245 lines (232 loc) · 8.62 KB
/
Copy pathstatus.sh
File metadata and controls
executable file
·245 lines (232 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env bash
# 组件运行状态查看脚本 只能中控机执行
SELF_DIR=$(dirname "$(readlink -f "$0")")
source "${SELF_DIR}"/functions
source "${SELF_DIR}"/tools.sh
# set -e
module=$1
project=$2
# 支持判断一下target
target=$3
if ! [ -z ${target} ]; then
if ! grep "[0-9]" <<<${target} >/dev/null; then
err "不支持多project"
else
module_ip=BK_${module^^}_IP${target}
if [[ -z ${!module_ip} ]]; then
err "${module_ip} 不存在"
else
target=${!module_ip}
fi
fi
else
if ! [ -z ${project} ]; then
if grep "[0-9]" <<<${project} >/dev/null; then
module_ip=BK_${module^^}_IP${project}
if [[ -z ${!module_ip} ]]; then
err "${module_ip} 不存在"
else
target=${!module_ip}
project=""
fi
else
target=${module}
fi
else
target=${module}
fi
fi
declare -a THIRD_PARTY_SVC=(
consul
consul-template
mysql@[a-z]+
redis@[a-z]+
openresty
rabbitmq-server
zookeeper
mongod
kafka
elasticsearch
influxdb
beanstalkd
)
TMP_PTN=$(printf "%s|" "${THIRD_PARTY_SVC[@]}")
THIRD_PARTY_SVC_PTN="^(${TMP_PTN%|})\.service$"
declare -A SERVICE=(
["mysql"]=mysql@default
['redis']=redis@default
["es7"]=elasticsearch
["nodeman"]=bk-nodeman
["consul"]=consul
["kafka"]=kafka
["usermgr"]=bk-usermgr
["redis_sentinel"]=redis-sentinel@default
["rabbitmq"]=rabbitmq-server
["zk"]=zookeeper
["mongodb"]=mongod
["influxdb"]=influxdb
["nginx"]=openresty
["beanstalk"]=beanstalkd
["yum"]=bk-yum
["fta"]=bk-fta
["iam"]=bk-iam
["ssm"]=bk-ssm
["license"]=bk-license
["appo"]=bk-paasagent
["appt"]=bk-paasagent
["nfs"]=nfs-server
['consul-template']=consul-template
['lesscode']=bk-lesscode
['iam_search_engine']=bk-iam-search-engine
['apigw']=bk-apigw
['auth']=bk-auth
['etcd']=etcd
['apisix']=apisix
)
declare -A BCS_SERVICE=(
['bcs']=bcs-[a-z].*
['zk']=zookeeper
['etcd']=etcd
['harbor_api']=harbor_api
['devops']=devops
['redis']=redis@bcs
['zk']=zookeeper
['mongodb']=mongod
['mysql']=mysql@bcs
)
case $module in
paas|cmdb|gse|job)
module=${module#bk}
target_name=$(map_module_name "${module}")
source <(/opt/py36/bin/python ${SELF_DIR}/qq.py -p ${BK_PKG_SRC_PATH}/${target_name}/projects.yaml -P ${SELF_DIR}/bin/default/port.yaml)
if [[ -z ${project} ]]; then
projects=${_projects["${module}"]}
pcmdrc "${target}" "get_common_bk_service_status ${module} ${projects[*]}"
else
if [[ ${module} == 'paas' ]];then
pcmdrc "${target}" "get_spic_bk_service_status ${module} ${project}"
else
pcmdrc "${target}" "get_common_bk_service_status ${module} ${project}"
fi
fi
;;
monitorv3|bkmonitorv3|log|bklog)
module=${module#bk*}
target_name=$(map_module_name "$module")
source <(/opt/py36/bin/python ${SELF_DIR}/qq.py -p ${BK_PKG_SRC_PATH}/${target_name}/projects.yaml -P ${SELF_DIR}/bin/default/port.yaml)
if [ -z "${project}" ];then
for project in ${_projects[${module}]};do
emphasize "status ${module} ${project} on host: ${_project_ip["${target_name},${project}"]}"
if [[ "${module}" =~ "log" ]]; then
pcmdrc "${_project_ip["${target_name},${project}"]}" "get_service_status bk-${module}-${project}"
else
pcmdrc "${_project_ip["${target_name},${project}"]}" "get_service_status bk-${project}"
fi
done
else
emphasize "status ${module} ${project} on host: ${_project_ip["${target_name},${project}"]}"
if [[ "${module}" =~ "log" ]]; then
pcmdrc "${_project_ip["${target_name},${project}"]}" "get_service_status bk-${module}-${project}"
else
pcmdrc "${_project_ip["${target_name},${project}"]}" "get_service_status bk-${project}"
fi
fi
;;
nginx)
pcmdrc "${target}" "get_service_status ${SERVICE[$module]} ${SERVICE["consul-template"]}"
;;
yum)
# 中控机安装模块
pcmdrc "$LAN_IP" "get_service_status ${SERVICE[$module]}"
;;
bkiam|bkssm|bkiam_search_engine|bkauth)
target_name=${module#bk}
pcmdrc "${target_name}" "get_service_status ${SERVICE[${target_name}]}"
;;
apigw|bkapigw)
target_name=${module#bk}
pcmdrc "${target_name}" "get_service_status ${SERVICE[${target_name}]}"
;;
apisix)
target_name=apigw
pcmdrc "${target_name}" "get_service_status apisix"
;;
etcd)
target_name=${module#bk}
pcmdrc "${target_name}" "get_service_status ${SERVICE[${target_name}]}"
;;
bknodeman|nodeman)
target_name=${module#bk}
pcmdrc "${target_name}" "get_service_status ${SERVICE[${target_name}]} ${SERVICE["consul-template"]} ${SERVICE["nginx"]}"
;;
paas_plugins|paas_plugin)
pcmdrc "${BK_PAAS_IP0}" "get_service_status bk-paas-plugins-log-alert"
pcmdrc paas "get_service_status bk-logstash-paas-app-log bk-logstash-apigw-log bk-filebeat@paas_esb_api bk-filebeat@bkapigateway_apigateway_api bk-filebeat@bkapigateway_esb_api"
if ! [ -z "${BK_APPT_IP_COMMA}" ]; then
pcmdrc appt "get_service_status bk-filebeat@celery bk-filebeat@component bk-filebeat@django bk-filebeat@java bk-filebeat@uwsgi"
fi
pcmdrc appo "get_service_status bk-filebeat@celery bk-filebeat@component bk-filebeat@django bk-filebeat@java bk-filebeat@uwsgi"
;;
bkall)
pcmdrc all "FORCE_TTY=1 $CTRL_DIR/bin/bks.sh ^bk-"
;;
tpall)
pcmdrc all "FORCE_TTY=1 $CTRL_DIR/bin/bks.sh \"$THIRD_PARTY_SVC_PTN\" "
;;
all)
echo "Status of all blueking components: "
pcmdrc all "FORCE_TTY=1 $CTRL_DIR/bin/bks.sh ^bk-"
echo
echo "Status of all third-party components: "
pcmdrc all "FORCE_TTY=1 $CTRL_DIR/bin/bks.sh \"$THIRD_PARTY_SVC_PTN\" "
;;
bcs)
if [[ -n ${project} ]]; then
if [[ "${project}" == "redis" || "${project}" == "zk" || "${project}" == "mongodb" || "${project}" == "mysql" || "${project}" == "harbor_api" || "${project}" == "devops" || "${project}" == "etcd" ]]; then
bcs_module_ip="BK_${project^^}_${module^^}_IP_COMMA"
IFS="," read -r -a target_server<<<"${!bcs_module_ip}"
for ip in ${target_server[@]}; do
project=${project//_/-}
emphasize "status ${module} ${project} on host: ${ip}"
pcmdrc "${ip}" "get_service_status ${BCS_SERVICE[$project]}"
done
else
bcs_module_ip="BK_${module^^}_${project^^}_IP_COMMA"
IFS="," read -r -a target_server<<<"${!bcs_module_ip}"
for ip in ${target_server[@]}; do
project=${project//_/-}
emphasize "status ${module} ${project} on host: ${ip}"
pcmdrc "${ip}" "get_service_status bcs-${project}"
done
fi
else
pcmdrc "bcs" "get_service_status ${BCS_SERVICE[$module]}"
pcmdrc "etcd" "get_service_status ${BCS_SERVICE[etcd]}"
pcmdrc "devops" "get_service_status ${BCS_SERVICE[devops]}"
pcmdrc "harbor_api" "get_service_status ${BCS_SERVICE[harbor_api]}"
IFS="," read -r -a target_ips<<<"${BK_REDIS_BCS_IP_COMMA}"
for ip in ${target_ips[@]}; do
pcmdrc "$ip" "get_service_status ${BCS_SERVICE[redis]}"
done
IFS="," read -r -a target_ips<<<"${BK_ZK_BCS_IP_COMMA}"
for ip in ${target_ips[@]}; do
pcmdrc "$ip" "get_service_status ${BCS_SERVICE[zk]}"
done
IFS="," read -r -a target_ips<<<"${BK_MONGODB_BCS_IP_COMMA}"
for ip in ${target_ips[@]}; do
pcmdrc "$ip" "get_service_status ${BCS_SERVICE[mongodb]}"
done
IFS="," read -r -a target_ips<<<"${BK_MYSQL_BCS_IP_COMMA}"
for ip in ${target_ips[@]}; do
pcmdrc "$ip" "get_service_status ${BCS_SERVICE[mysql]}"
done
fi
;;
*)
if [[ -z ${SERVICE[$module]} ]]; then
echo "当前不支持 '${module}' 的状态检测."
exit 1
fi
pcmdrc "${target}" "get_service_status ${SERVICE[$module]}"
;;
esac