Created
August 20, 2015 08:46
-
-
Save itxx00/b64fac44375bae1be66b to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# send named metrics to falcon-agent | |
RNDC_BIN=/usr/sbin/rndc | |
STATS='/var/named/data/named_stats.txt' | |
rm -f $STATS | |
if ! $RNDC_BIN stats; then | |
exit 1 | |
fi | |
if ! [ -s ${STATS} ]; then | |
echo "${STATS} does not exist!" >&2 | |
exit 1 | |
fi | |
named_total_query=$(awk '/ QUERY/ {print $1}' $STATS) | |
named_tcp_request=$(awk '/ TCP requests received/ {print $1}' $STATS) | |
named_total_response=$(awk '/[0-9] responses sent/ {print $1}' $STATS) | |
named_success_query=$(awk '/queries resulted in successful/ {print $1}' $STATS) | |
named_dropped_query=$(awk '/ queries dropped/ {print $1}' $STATS) | |
[[ -n $named_total_query ]] || named_total_query=0 | |
[[ -n $named_tcp_request ]] || named_tcp_request=0 | |
[[ -n $named_total_response ]] || named_total_response=0 | |
[[ -n $named_success_query ]] || named_success_query=0 | |
[[ -n $named_dropped_query ]] || named_dropped_query=0 | |
endpoint=$(hostname) | |
timestamp=$(date '+%s') | |
data="[{\"endpoint\":\"$endpoint\",\"tags\":\"\",\"timestamp\":$timestamp,\"metric\":\"named.total_query\",\"value\":$named_total_query,\"counterType\":\"COUNTER\",\"step\":60},{\"endpoint\":\"$endpoint\",\"tags\":\"\",\"timestamp\":$timestamp,\"metric\":\"named.tcp_request\",\"value\":$named_tcp_request,\"counterType\":\"COUNTER\",\"step\":60},{\"endpoint\":\"$endpoint\",\"tags\":\"\",\"timestamp\":$timestamp,\"metric\":\"named.total_response\",\"value\":$named_total_response,\"counterType\":\"COUNTER\",\"step\":60},{\"endpoint\":\"$endpoint\",\"tags\":\"\",\"timestamp\":$timestamp,\"metric\":\"named.success_query\",\"value\":$named_success_query,\"counterType\":\"COUNTER\",\"step\":60},{\"endpoint\":\"$endpoint\",\"tags\":\"\",\"timestamp\":$timestamp,\"metric\":\"named.dropped_query\",\"value\":$named_dropped_query,\"counterType\":\"COUNTER\",\"step\":60}]" | |
curl -X POST -H "Content-Type: application/json" -d "$data" http://127.0.0.1:1988/v1/push >/dev/null 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment