Skip to content

Instantly share code, notes, and snippets.

@lijunle
Last active August 29, 2019 16:28
Show Gist options
  • Save lijunle/c19e7ea10ea5d7775e5f2f13e00d11c5 to your computer and use it in GitHub Desktop.
Save lijunle/c19e7ea10ea5d7775e5f2f13e00d11c5 to your computer and use it in GitHub Desktop.
Performance to ping Google
#!/bin/sh
IKEY='<Instrumentation-Key-Here>'
while true
do
TIME=$(date +%Y-%m-%dT%H:%M:%S%z)
PING_OUTPUT=$(ping -q -c 1 -w 3 www.google.com)
PING_RESULT=$?
DELAY=$(echo $PING_OUTPUT | sed -r -n 's/^.+ rtt .+ = (.+) ms$/\1/p' | cut -d '/' -f 1)
METRICS=$([ $PING_RESULT -eq 0 ] \
&& echo '{"name":"ping-success","value":1},{"name":"ping-time","value":'$DELAY'}' \
|| echo '{"name":"ping-success","value":0}')
echo "[$TIME] $METRICS"
curl --silent -d \
'{"name":"MetricData",
"time":"'$TIME'",
"iKey":"'$IKEY'",
"data":{"baseType":"MetricData","baseData":{"metrics":['$METRICS']}}}
' https://dc.services.visualstudio.com/v2/track
# Wait one minute
echo ''
sleep 60s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment