Skip to content

Instantly share code, notes, and snippets.

@xyntrix
Last active June 11, 2020 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyntrix/5d7ce4e0b20afb05a67fdfc2ae12607e to your computer and use it in GitHub Desktop.
Save xyntrix/5d7ce4e0b20afb05a67fdfc2ae12607e to your computer and use it in GitHub Desktop.
Openshift application state snapshot
#!/bin/sh
DT=`date +%s`
#NS="quay"
spec="all"
LOGLIMIT="3000"
if [ ! -z "${NS}" ]; then
NS="-n ${NS}"
else
NS=""
fi
mkdir -p logs.${DT}
oc get nodes | tee logs.${DT}/nodes.log
oc get pods --all-namespaces | tee logs.${DT}/pods.log
oc ${NS} get ${spec} | tee logs.${DT}/all.log
oc ${NS} get events | tee logs.${DT}/events.log
oc get pods --all-namespaces -owide | tee logs.${DT}/pods-wide.log
oc adm top pods | tee logs.${DT}/pods-top.log
oc adm top pods --containers=true | tee logs.${DT}/pods-top-containers.log
# oc get Tuned/default -o yaml -n openshift-cluster-node-tuning-operator
for item in $(oc get nodes -oname); do
mkdir -p logs.${DT}/${item%/*}
oc describe ${item} | tee logs.${DT}/${item}.describe.log
done
for item in $(oc ${NS} get ${spec} -oname); do
mkdir -p logs.${DT}/${item%/*}
oc ${NS} describe ${item} | tee logs.${DT}/${item}.describe.log
done
for item in $(oc ${NS} get pods -oname); do
mkdir -p logs.${DT}/${item%/*}
for container in $(oc ${NS} get ${item} --no-headers -o custom-columns='CONTAINERS:.spec.containers[*].name'|tr ',' ' '); do
if [ -z "${LOGLIMIT}" ]; then
oc ${NS} logs ${item} -c ${container} | tee logs.${DT}/${item}.${container}.logs.log
else
oc ${NS} logs ${item} -c ${container} | tail -n ${LOGLIMIT} | tee logs.${DT}/${item}.${container}.logs.log
fi
done
done
echo "# Creating (probably) safe-content tarball: logs.${DT}/logs.${DT}.tgz"
cd logs.${DT}
tar cvf logs.${DT}.tar *.log node pod
gzip -9 logs.${DT}.tar
cd ..
@xyntrix
Copy link
Author

xyntrix commented Jun 11, 2020

May-11, example run
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment