Skip to content

Instantly share code, notes, and snippets.

@1977er
Created March 1, 2017 12:55
Show Gist options
  • Save 1977er/b0f0ae5ba983120e38b121d1d74c9889 to your computer and use it in GitHub Desktop.
Save 1977er/b0f0ae5ba983120e38b121d1d74c9889 to your computer and use it in GitHub Desktop.
Sends ping telemetry to server
#!/bin/sh
descr=$(uname -n)
job=$(uname -n | cut -d"-" -f3)
dest="fdca:ffee:8::2001"
count=5
# do not change below here
result=$(ping $dest -c $count)
package_loss=$(echo "$result" | tail -2 | head -1 | cut -d" " -f 7 | tr -d "%")
roundtrip=$(echo "$result" | tail -1 | cut -d " " -f 4 | cut -d "/" -f 2)
data () {
echo ping_package_loss{descr=\"$descr\"} $package_loss
if [ "$roundtrip" != '' ] ; then echo "ping_roundtrip{descr=\"$descr\"} $roundtrip"; fi
}
request () {
# http header
echo "POST /metrics/job/$job HTTP/1.0"
echo "Content-Length: $(data|wc -c)"
echo "Lifetime: 2m"
echo
data
}
request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment