2015-03-14 13:32:26 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
init () {
|
|
|
|
if [ -z $INFLUXDB_API_ENDPOINT ]; then
|
2015-03-14 21:44:06 +01:00
|
|
|
echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be specified"
|
2015-03-14 13:32:26 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
2015-03-14 18:31:35 +01:00
|
|
|
|
|
|
|
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
|
2015-03-14 13:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
report () {
|
2015-03-14 21:44:06 +01:00
|
|
|
local metric=$1
|
|
|
|
local value=$2
|
|
|
|
local points
|
2015-03-14 18:31:35 +01:00
|
|
|
if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then
|
2015-03-14 21:44:06 +01:00
|
|
|
points="[$value,\"$HOSTNAME\"]"
|
2015-03-14 18:31:35 +01:00
|
|
|
else
|
2015-03-14 21:44:06 +01:00
|
|
|
points="[$value]"
|
2015-03-14 18:31:35 +01:00
|
|
|
fi
|
2015-03-14 21:44:06 +01:00
|
|
|
|
2015-03-14 14:46:17 +01:00
|
|
|
curl -X POST $INFLUXDB_API_ENDPOINT \
|
2015-03-14 21:44:06 +01:00
|
|
|
-d "[{\"name\":\"$metric\",\"columns\":$__influxdb_columns,\"points\":[$points]}]"
|
2015-03-14 13:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
docs () {
|
|
|
|
echo "Send data to InfluxDB."
|
|
|
|
echo "\$INFLUXDB_API_ENDPOINT="
|
2015-03-15 10:01:41 +01:00
|
|
|
echo "\$INFLUXDB_SEND_HOSTNAME=true"
|
2015-03-14 13:32:26 +01:00
|
|
|
}
|