Last active
January 23, 2021 16:46
-
-
Save maricalucian/5b643f7c5b7c92546dbfc129ff545ae4 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 | |
#USAGE | |
#pass variables to script | |
# IURL - influx server address | |
# ICRED - influx connection string query | |
# IHOST - host to be sent | |
# | |
#start it as a service or in background, eg: | |
#IURL="http://192.168.0.1:8086" ICRED="db=dbname&u=influxuser&p=influxpass" IHOST="host-for-grafana" nohup sh -c "$(curl -sSfL https://gist.github.com/maricalucian/5b643f7c5b7c92546dbfc129ff545ae4/raw/)" & | |
# | |
sleep=3 | |
if [ "$ICRED" = "" ] || [ "$IURL" = "" ] || [ "$IHOST" = "" ]; then | |
cat << EOF | |
Variables needed: | |
IURL - influx server url | |
ICRED - influx connection info in query string format (db=database&u=user&p=pass) | |
IHOST - host to be passed along the metrics | |
EOF | |
exit 1 | |
fi | |
while true; | |
do | |
result=$(curl http://localhost:8899 -X POST -H "Content-Type: application/json" -s -d '{"jsonrpc":"2.0","id":1, "method":"getHealth"}') | |
res=$? | |
if [ "$res" = "0" ]; then | |
blocks=$(printf "$result" | jq 'if .result == "ok" then 0 elif .error.data.numSlotsBehind? then .error.data.numSlotsBehind else 999 end') | |
else | |
blocks="999" | |
fi | |
data="slots_behind,host=$IHOST value=$blocks $(date +%s)" | |
echo $data | |
curl -X POST "$IURL/write?$ICRED&precision=s" --data-binary "$data" | |
sleep $(($sleep)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment