clean up code. load all reporters on init

This commit is contained in:
Patrick Stadler
2015-03-14 21:44:06 +01:00
parent 1d30530199
commit ca25c6d7fe
7 changed files with 62 additions and 37 deletions

View File

@@ -2,7 +2,7 @@
init () {
if [ -z $FILE_LOCATION ]; then
echo "Missing configuration: \$FILE_LOCATION"
echo "Error: file reporter requires \$FILE_LOCATION to be specified"
exit 1
fi
@@ -12,10 +12,10 @@ init () {
}
report () {
local METRIC=$1
local VALUE=$2
local DATE=$(iso_date)
echo "$DATE $METRIC: $VALUE" >> $FILE_LOCATION
local metric=$1
local value=$2
local datetime=$(iso_date)
echo "$datetime $metric: $value" >> $FILE_LOCATION
}
docs () {

View File

@@ -2,7 +2,7 @@
init () {
if [ -z $INFLUXDB_API_ENDPOINT ]; then
echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be set"
echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be specified"
exit 1
fi
@@ -18,15 +18,17 @@ init () {
}
report () {
local METRIC=$1
local VALUE=$2
local metric=$1
local value=$2
local points
if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then
local POINTS="[$VALUE,\"$HOSTNAME\"]"
points="[$value,\"$HOSTNAME\"]"
else
local POINTS="[$VALUE]"
points="[$value]"
fi
curl -X POST $INFLUXDB_API_ENDPOINT \
-d "[{\"name\":\"$METRIC\",\"columns\":$__influxdb_columns,\"points\":[$POINTS]}]"
-d "[{\"name\":\"$metric\",\"columns\":$__influxdb_columns,\"points\":[$points]}]"
}
docs () {

View File

@@ -2,12 +2,12 @@
init() {
if [ -z $KEEN_IO_PROJECT_ID ]; then
echo "Error: keen_io requires \$KEEN_IO_PROJECT_ID to be set"
echo "Error: keen_io requires \$KEEN_IO_PROJECT_ID to be specified"
exit 1
fi
if [ -z $KEEN_IO_WRITE_KEY ]; then
echo "Error: keen_io requires \$KEEN_IO_WRITE_KEY to be set"
echo "Error: keen_io requires \$KEEN_IO_WRITE_KEY to be specified"
exit 1
fi
@@ -22,10 +22,11 @@ init() {
}
report () {
local METRIC=$1
local 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
-d "{\"metric\":\"$metric\",\"value\":$value}" > /dev/null
}
docs () {

View File

@@ -2,15 +2,16 @@
init () {
if [ -z $STATHAT_API_KEY ]; then
echo "Error: stathat requires \$STATHAT_API_KEY to be set"
echo "Error: stathat requires \$STATHAT_API_KEY to be specified"
exit 1
fi
}
report () {
local METRIC=$1
local VALUE=$2
curl -s -d "stat=$METRIC&ezkey=$STATHAT_API_KEY&value=$VALUE" \
local metric=$1
local value=$2
curl -s -d "ezkey=$STATHAT_API_KEY&stat=$metric&value=$value" \
http://api.stathat.com/ez > /dev/null
}

View File

@@ -1,9 +1,10 @@
#!/bin/sh
report () {
local METRIC=$1
local VALUE=$2
echo $METRIC: $VALUE
local metric=$1
local value=$2
echo $metric: $value
}
docs () {