Skip to content

Instantly share code, notes, and snippets.

@mhewedy
Created October 3, 2020 18:52
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 mhewedy/1dad5dce09ebb1cd450e76185f30bd1e to your computer and use it in GitHub Desktop.
Save mhewedy/1dad5dce09ebb1cd450e76185f30bd1e to your computer and use it in GitHub Desktop.
Report k8s jobs running for long time
# report jobs is running for more than 60 minutes
sudo kubectl get pods -l job-name -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.phase}{" "}{.status.startTime}{"\n"}{end}' | while read line; do
name=$(echo $line | awk '{print $1}')
phase=$(echo $line | awk '{print $2}')
startTime=$(echo $line | awk '{print $3}')
now=$(date +%s)
start=$(date -d $startTime +"%s")
diff=$(( ($now - $start)/60 ))
if [ "$phase" = "Running" ] && [ "$diff" -gt 60 ]; then
# see https://github.com/fabianonline/telegram.sh to know about telegram command and how to obtain token and chatid
telegram -t <token> -c <chatid> "Job $name is still running for more than an hour now"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment