diff --git a/metrics.sh b/metrics.sh index 811e436..58e0ef0 100755 --- a/metrics.sh +++ b/metrics.sh @@ -5,9 +5,9 @@ INTERVAL=1 REPORTER=stdout # TODO: handle multiple reporters # env -export LC_ALL=en_US.UTF-8 -export LANG=en_US.UTF-8 -export LANGUAGE=en_US.UTF-8 +LC_ALL=en_US.UTF-8 +LANG=en_US.UTF-8 +LANGUAGE=en_US.UTF-8 # handle opts opts_spec=":dhvr:" diff --git a/reporters/file.sh b/reporters/file.sh index 39a2c09..0991c99 100644 --- a/reporters/file.sh +++ b/reporters/file.sh @@ -1,12 +1,5 @@ #!/bin/sh -report () { - local METRIC=$1 - local VALUE=$2 - local DATE=$(iso_date) - echo "$DATE $METRIC: $VALUE" >> $FILE_LOCATION -} - init () { if [ -z $FILE_LOCATION ]; then echo "Missing configuration: \$FILE_LOCATION" @@ -18,6 +11,13 @@ init () { fi } +report () { + local METRIC=$1 + local VALUE=$2 + local DATE=$(iso_date) + echo "$DATE $METRIC: $VALUE" >> $FILE_LOCATION +} + docs () { echo "Write to a file or named pipe." echo "\$FILE_LOCATION=$FILE_LOCATION" diff --git a/reporters/influxdb.sh b/reporters/influxdb.sh new file mode 100644 index 0000000..b7583ad --- /dev/null +++ b/reporters/influxdb.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +init () { + if [ -z $INFLUXDB_API_ENDPOINT ]; then + echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be set" + exit 1 + fi +} + +report () { + local METRIC=$1 + local VALUE=$2 + curl -X POST -d "[{\"name\":\"$METRIC\",\"columns\":[\"value\"],\"points\":[[$VALUE]]}]" $INFLUXDB_API_ENDPOINT +} + +docs () { + echo "Send data to InfluxDB." + echo "\$INFLUXDB_API_ENDPOINT=" +} \ No newline at end of file diff --git a/reporters/keen_io.sh b/reporters/keen_io.sh index 65016fb..2068e16 100644 --- a/reporters/keen_io.sh +++ b/reporters/keen_io.sh @@ -22,8 +22,8 @@ init() { } report () { - METRIC=$1 - VALUE=$2 + local METRIC=$1 + local VALUE=$2 curl -s $__keen_io_api_url -H "Content-Type: application/json" \ -d "{\"metric\": \"$METRIC\", \"value\": $VALUE}" > /dev/null } diff --git a/reporters/stathat.sh b/reporters/stathat.sh index 677467a..c7859ae 100644 --- a/reporters/stathat.sh +++ b/reporters/stathat.sh @@ -8,8 +8,8 @@ init () { } report () { - METRIC=$1 - VALUE=$2 + local METRIC=$1 + local VALUE=$2 curl -s -d "stat=$METRIC&ezkey=$STATHAT_API_KEY&value=$VALUE" \ http://api.stathat.com/ez > /dev/null } diff --git a/reporters/stdout.sh b/reporters/stdout.sh index d292643..c1f8eb7 100644 --- a/reporters/stdout.sh +++ b/reporters/stdout.sh @@ -1,8 +1,8 @@ #!/bin/sh report () { - METRIC=$1 - VALUE=$2 + local METRIC=$1 + local VALUE=$2 echo $METRIC: $VALUE }