获取多个pod的错误日志及数量统计
#!/bin/sh
if [ $1 ];then
if [ $2 ];then
if [ $3 ];then
for i in `kubectl get po -n $1 | grep -i $2 | awk 'NR>=2 {print $1}'`
do
printf "%-40s Exception:%-10s Error:%-10s\n" $i `kubectl logs -n $1 $i -c $3 | grep -i Exception|wc -l` `kubectl logs -n $1 $i -c $3 | grep -i error |wc -l`
done
else
echo "please input the container name"
fi
else
echo "please input the pod name"
fi
else
echo "please input the namespace"
fi
在docker容器中获取一些java运行时信息
#!/bin/bash
pid=`jps | grep my-app |awk '{print $1}'`
for i in $(seq 10)
do
top -Hp $pid -n 2 > /app/top_$i.log;
/usr/lib/java/latest/bin/jstack -l $pid > /home/jeeapp/stack$i.log
if [ `expr $i % 5` -eq 0 ]
then
/usr/lib/java/latest/bin/jmap -dump:format=b,file=/app/$pid_$i.hprof $pid
fi
sleep 60
echo "please waiting for completed.... $i minute passed"
done