2022-05-11 03:41:53 +00:00
#!/bin/bash
namespace = 'default'
log_path = './milvus-log'
2022-06-29 07:06:18 +00:00
etcd = "false"
minio = "false"
pulsar = "false"
kafka = "false"
2022-09-14 08:04:30 +00:00
since_args = ""
2022-05-11 03:41:53 +00:00
#-n namespace: The namespace that Milvus is installed in.
#-i milvus_instance: The name of milvus instance.
#-p log_path: Log storage path.
2022-06-29 07:06:18 +00:00
#-e export etcd logs
#-m export minio logs
#-u export pulsar logs
#-k export kafka logs
2022-09-14 08:04:30 +00:00
#-s 24h: export logs since 24h
while getopts "n:i:p:s:emuk" opt_name
2022-05-11 03:41:53 +00:00
do
case $opt_name in
2022-06-29 07:06:18 +00:00
n) namespace = $OPTARG ; ;
i) instance_name = $OPTARG ; ;
p) log_path = $OPTARG ; ;
e) etcd = "true" ; ;
m) minio = "true" ; ;
u) pulsar = "true" ; ;
k) kafka = "true" ; ;
2022-09-14 08:04:30 +00:00
s) since = $OPTARG ; ;
2022-06-29 07:06:18 +00:00
*) echo "Unkonwen parameters" ; ;
2022-05-11 03:41:53 +00:00
esac
done
if [ ! $instance_name ] ;
then
echo "Missing argument instance_name, please add it. For example:'./export-milvus-log.sh -i milvus-instance-name'"
exit 1
fi
2022-06-29 07:06:18 +00:00
if [ ! -d $log_path ] ;
then
mkdir -p $log_path
fi
2022-09-14 08:04:30 +00:00
if [ $since ] ;
then
since_args = " --since= $since "
fi
2022-06-29 07:06:18 +00:00
echo " The log files will be stored $( readlink -f $log_path ) "
2022-05-11 03:41:53 +00:00
2022-06-29 07:06:18 +00:00
function export_log( ) {
# export pod logs
for pod in $1 ;
do
# Check if the pod has been restarted
if [ $( kubectl get pod $pod -n $namespace --output= jsonpath = { .status.containerStatuses[ 0] .restartCount} ) = = 0 ] ;
then
echo " Export log of $pod "
2022-09-14 08:04:30 +00:00
kubectl logs $pod -n $namespace ${ since_args } > $log_path /$pod .log
2022-06-29 07:06:18 +00:00
else
echo " Export log of $pod "
2022-09-14 08:04:30 +00:00
kubectl logs $pod -n $namespace -p ${ since_args } > $log_path /$pod -pre.log
kubectl logs $pod -n $namespace ${ since_args } > $log_path /$pod .log
2022-06-29 07:06:18 +00:00
fi
done
}
# export milvus component log
pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= $instance_name ,app.kubernetes.io/name= milvus --output= jsonpath = { .items..metadata.name} )
2022-05-11 03:41:53 +00:00
if [ ${# pods } = = 0 ] ;
then
echo " There is no Milvus instance $instance_name in the namespace $namespace "
2022-06-29 07:06:18 +00:00
else
export_log " ${ pods [*] } "
2022-05-11 03:41:53 +00:00
fi
2022-06-29 07:06:18 +00:00
# export etcd component log
if $etcd ;
2022-05-11 03:41:53 +00:00
then
2022-06-29 07:06:18 +00:00
etcd_pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= $instance_name ,app.kubernetes.io/name= etcd --output= jsonpath = { .items..metadata.name} )
if [ ${# etcd_pods } = = 0 ] ;
then
echo " There is no etcd component for Milvus instance $instance_name in the namespace $namespace "
else
export_log " ${ etcd_pods [*] } "
fi
2022-05-11 03:41:53 +00:00
fi
2022-06-29 07:06:18 +00:00
# export minio component log
if $minio ;
then
minio_pods = $( kubectl get pod -n $namespace -l release = $instance_name ,app= minio --output= jsonpath = { .items..metadata.name} )
if [ ${# minio_pods } = = 0 ] ;
then
echo " There is no minio component for Milvus instance $instance_name in the namespace $namespace "
else
export_log " ${ minio_pods [*] } "
fi
fi
2022-05-11 03:41:53 +00:00
2022-06-29 07:06:18 +00:00
# export pulsar component log
if $pulsar ;
then
pulsar_pods = $( kubectl get pod -n $namespace -l cluster = $instance_name -pulsar,app= pulsar --output= jsonpath = { .items..metadata.name} )
if [ ${# pulsar_pods } = = 0 ] ;
2022-05-11 03:41:53 +00:00
then
2022-06-29 07:06:18 +00:00
echo " There is no pulsar component for Milvus instance $instance_name in the namespace $namespace "
2022-05-11 03:41:53 +00:00
else
2022-06-29 07:06:18 +00:00
export_log " ${ pulsar_pods [*] } "
2022-05-11 03:41:53 +00:00
fi
2022-06-29 07:06:18 +00:00
fi
# export kafka component log
if $kafka ;
then
kafka_pods = $( kubectl get pod -n $namespace -l app.kubernetes.io/instance= $instance_name ,app.kubernetes.io/component= kafka --output= jsonpath = { .items..metadata.name} )
if [ ${# kafka_pods } = = 0 ] ;
then
echo " There is no kafka component for Milvus instance $instance_name in the namespace $namespace "
else
export_log " ${ kafka_pods [*] } "
fi
fi
2022-05-11 03:41:53 +00:00
tar zcf $log_path .tar.gz $log_path
echo " The compressed logs are stored in $( readlink -f $log_path .tar.gz) "