Created
October 3, 2020 18:52
-
-
Save mhewedy/1dad5dce09ebb1cd450e76185f30bd1e to your computer and use it in GitHub Desktop.
Report k8s jobs running for long time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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