mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-02-28 13:59:12 -05:00
40 lines
926 B
Bash
40 lines
926 B
Bash
#!/bin/sh
|
|
|
|
defaults () {
|
|
if [ -z $INFLUXDB_SEND_HOSTNAME ]; then
|
|
INFLUXDB_SEND_HOSTNAME=true
|
|
fi
|
|
}
|
|
|
|
start () {
|
|
if [ -z $INFLUXDB_API_ENDPOINT ]; then
|
|
echo "Error: influxdb requires \$INFLUXDB_API_ENDPOINT to be specified"
|
|
return 1
|
|
fi
|
|
|
|
if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then
|
|
__influxdb_columns="[\"value\",\"host\"]"
|
|
__influxdb_hostname=$(hostname)
|
|
else
|
|
__influxdb_columns="[\"value\"]"
|
|
fi
|
|
}
|
|
|
|
report () {
|
|
local metric=$1
|
|
local value=$2
|
|
local points
|
|
if [ "$INFLUXDB_SEND_HOSTNAME" = true ]; then
|
|
points="[$value,\"$__influxdb_hostname\"]"
|
|
else
|
|
points="[$value]"
|
|
fi
|
|
local data="[{\"name\":\"$metric\",\"columns\":$__influxdb_columns,\"points\":[$points]}]"
|
|
curl -s -X POST $INFLUXDB_API_ENDPOINT -d $data
|
|
}
|
|
|
|
docs () {
|
|
echo "Send data to InfluxDB."
|
|
echo "INFLUXDB_API_ENDPOINT=$INFLUXDB_API_ENDPOINT"
|
|
echo "INFLUXDB_SEND_HOSTNAME=$INFLUXDB_SEND_HOSTNAME"
|
|
} |