Skip to content

Instantly share code, notes, and snippets.

@rajeshpv
Created February 12, 2025 00:43
Show Gist options
  • Save rajeshpv/369d7a6b1c7d4988cc498e067678f03d to your computer and use it in GitHub Desktop.
Save rajeshpv/369d7a6b1c7d4988cc498e067678f03d to your computer and use it in GitHub Desktop.
Pings every 10 secs with 1 sec timeout to simulate k8 live probe test
#!/bin/bash
# have export APP_URL="http://service.com/"
LOG_FILE="output-k8-ping.log"
while true; do
# Run curl and capture output + exit code
# note: curl is given 1 sec of timeout else to error out (the -m 1)
OUTPUT=$(curl -m 1 -o /dev/null -s -w "{ DNS_Lookup: %{time_namelookup}, TCP_Connect: %{time_connect}, SSL_Handshake: %{time_appconnect}, TTFB: %{time_starttransfer}, Total_Time: %{time_total} }s\n" "$APP_URL")
EXIT_CODE=$?
# Log with timestamp
if [ $EXIT_CODE -eq 0 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - $OUTPUT" >> "$LOG_FILE"
else
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR: Curl failed with exit code $EXIT_CODE" >> "$LOG_FILE"
fi
sleep 10
done
@rajeshpv
Copy link
Author

rajeshpv commented Feb 12, 2025

Steps to use this:

cd ~/
wget  https://gist.github.com/rajeshpv/369d7a6b1c7d4988cc498e067678f03d/raw/29b569fc44da7dc840c319bab2d2d4b1b542dc1c/k8-ping.sh 

chmod u+x ./k8-ping.sh 

export APP_URL="http://service.com/"

# launch it
./k8-ping.sh 

# from other terminal tail log
tail -f ~/output-k8-ping.log

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