Created
February 12, 2025 00:43
-
-
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
This file contains hidden or 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
| #!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to use this: