From 1d30530199bec3cc3b195ff62795b8610d84370e Mon Sep 17 00:00:00 2001 From: Patrick Stadler Date: Sat, 14 Mar 2015 18:31:35 +0100 Subject: [PATCH] influxdb now sends hostname per default --- reporters/influxdb.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/reporters/influxdb.sh b/reporters/influxdb.sh index a14d0df..a7ecfe7 100644 --- a/reporters/influxdb.sh +++ b/reporters/influxdb.sh @@ -5,16 +5,32 @@ init () { echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be set" exit 1 fi + + if [ -z $INFLUXDB_SEND_HOSTNAME ]; then + INFLUXDB_SEND_HOSTNAME=true + fi + + if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then + __influxdb_columns="[\"value\",\"host\"]" + else + __influxdb_columns="[\"value\"]" + fi } report () { local METRIC=$1 local VALUE=$2 + if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then + local POINTS="[$VALUE,\"$HOSTNAME\"]" + else + local POINTS="[$VALUE]" + fi curl -X POST $INFLUXDB_API_ENDPOINT \ - -d "[{\"name\":\"$METRIC\",\"columns\":[\"value\"],\"points\":[[$VALUE]]}]" + -d "[{\"name\":\"$METRIC\",\"columns\":$__influxdb_columns,\"points\":[$POINTS]}]" } docs () { echo "Send data to InfluxDB." echo "\$INFLUXDB_API_ENDPOINT=" + echo "\$INFLUXDB_SEND_HOSTNAME=$INFLUXDB_SEND_HOSTNAME" } \ No newline at end of file