Created
May 18, 2019 09:12
-
-
Save maesoser/fd0232ab372003c2bc892ae39ea249f6 to your computer and use it in GitHub Desktop.
Simple ping exporter that makes uses of prometheus node_exporter textfile collector
This file contains 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
#!/usr/bin/env bash | |
do_ping () { | |
local EXPORT_FILE="/tmp/ping_$1.prom" | |
local OUT=$(ping -nq -c $2 $1) | |
local ICMP_SENT=$(echo "$OUT" | grep "packets" | awk '{print $1}') | |
local ICMP_RECV=$(echo "$OUT" | grep "packets" | awk '{print $4}') | |
local ICMP_MIN=$(echo "$OUT" | grep "avg" | awk '{print $4}' | cut -d/ -f1) | |
local ICMP_AVG=$(echo "$OUT" | grep "avg" | awk '{print $4}' | cut -d/ -f2) | |
local ICMP_MAX=$(echo "$OUT" | grep "avg" | awk '{print $4}' | cut -d/ -f3) | |
echo "# HELP icmp_sent ICMP Requests Sent" > "$EXPORT_FILE.$$" | |
echo "icmp_sent{host=\"$1\"} $ICMP_SENT" >> "$EXPORT_FILE.$$" | |
echo "# HELP icmp_recv ICMP Replies Received" >> "$EXPORT_FILE.$$" | |
echo "icmp_recv{host=\"$1\"} $ICMP_RECV" >> "$EXPORT_FILE.$$" | |
echo "# HELP icmp_min_rtt_sec Minimum RTT" >> "$EXPORT_FILE.$$" | |
echo "icmp_min_rtt_sec{host=\"$1\"} $ICMP_MIN" >> "$EXPORT_FILE.$$" | |
echo "# HELP icmp_avg_rtt_sec Average RTT" >> "$EXPORT_FILE.$$" | |
echo "icmp_avg_rtt_sec{host=\"$1\"} $ICMP_AVG" >> "$EXPORT_FILE.$$" | |
echo "# HELP icmp_max_rtt_sec Maximum RTT" >> "$EXPORT_FILE.$$" | |
echo "icmp_max_rtt_sec{host=\"$1\"} $ICMP_MAX" >> "$EXPORT_FILE.$$" | |
mv "$EXPORT_FILE.$$" "$EXPORT_FILE" | |
} | |
if [ -z "$1" ]; then | |
echo -e "Usage:\n\t$0 [target] [target] [target] ..." | |
exit | |
fi | |
COUNT=5 | |
for target in "$@" | |
do | |
do_ping $target $COUNT | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment