Skip to content

Instantly share code, notes, and snippets.

@sylr
Forked from SuperQ/internet_check.sh
Last active September 23, 2020 09:24
Show Gist options
  • Save sylr/87de3c9f3bb23e037a1aa5c9640bdda0 to your computer and use it in GitHub Desktop.
Save sylr/87de3c9f3bb23e037a1aa5c9640bdda0 to your computer and use it in GitHub Desktop.
A script to check internet connectivity with the node_exporter textfile
#!/usr/bin/env sh
URLS[0]="https://www.google.com"
URLS[1]="http://169.254.169.254/metadata/instance?api-version=2020-06-01" # azure internal endpoint
HEADERS[O]=""
HEADERS[1]="-H 'Metadata: true'"
OUTPUT=${OUTPUT:-/tmp/curl.prom}
SLEEP=${SLEEP:-10}
while [ true ]; do
{
for i in $(seq 0 $((${#URLS[@]} - 1))); do
if curl -s -f --connect-timeout 4 -o /dev/null ${HEADERS[$i]} ${URLS[$i]}; then
echo "node_http_url_reached{url=\"${URLS[$i]}\"} 1"
else
echo "node_http_url_reached{url=\"${URLS[$i]}\"} 0"
fi
done
} > ${OUTPUT}
sleep ${SLEEP}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment