2015-03-14 08:32:26 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-03-21 16:19:08 -04:00
|
|
|
defaults () {
|
|
|
|
if [ -z $INFLUXDB_SEND_HOSTNAME ]; then
|
|
|
|
INFLUXDB_SEND_HOSTNAME=true
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
start () {
|
2015-03-14 08:32:26 -04:00
|
|
|
if [ -z $INFLUXDB_API_ENDPOINT ]; then
|
2015-03-14 16:44:06 -04:00
|
|
|
echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be specified"
|
2015-03-22 13:01:27 -04:00
|
|
|
return 1
|
2015-03-14 08:32:26 -04:00
|
|
|
fi
|
2015-03-14 13:31:35 -04:00
|
|
|
|
|
|
|
if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then
|
|
|
|
__influxdb_columns="[\"value\",\"host\"]"
|
2015-03-15 09:55:36 -04:00
|
|
|
__influxdb_hostname=$(hostname)
|
2015-03-14 13:31:35 -04:00
|
|
|
else
|
|
|
|
__influxdb_columns="[\"value\"]"
|
|
|
|
fi
|
2015-03-14 08:32:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
report () {
|
2015-03-14 16:44:06 -04:00
|
|
|
local metric=$1
|
|
|
|
local value=$2
|
|
|
|
local points
|
2015-03-14 13:31:35 -04:00
|
|
|
if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then
|
2015-03-15 09:55:36 -04:00
|
|
|
points="[$value,\"$__influxdb_hostname\"]"
|
2015-03-14 13:31:35 -04:00
|
|
|
else
|
2015-03-14 16:44:06 -04:00
|
|
|
points="[$value]"
|
2015-03-14 13:31:35 -04:00
|
|
|
fi
|
2015-03-22 13:01:27 -04:00
|
|
|
local data="[{\"name\":\"$metric\",\"columns\":$__influxdb_columns,\"points\":[$points]}]"
|
|
|
|
curl -s -X POST $INFLUXDB_API_ENDPOINT -d $data
|
2015-03-14 08:32:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
docs () {
|
|
|
|
echo "Send data to InfluxDB."
|
2015-03-21 16:19:08 -04:00
|
|
|
echo "INFLUXDB_API_ENDPOINT=$INFLUXDB_API_ENDPOINT"
|
|
|
|
echo "INFLUXDB_SEND_HOSTNAME=$INFLUXDB_SEND_HOSTNAME"
|
2015-03-14 08:32:26 -04:00
|
|
|
}
|