Skip to content

Instantly share code, notes, and snippets.

@dansimau
Created May 16, 2022 09:14
Show Gist options
  • Save dansimau/fc2c4c277f510db2f76d7b48ba919fce to your computer and use it in GitHub Desktop.
Save dansimau/fc2c4c277f510db2f76d7b48ba919fce to your computer and use it in GitHub Desktop.
Push metric to a Grafana Cloud Graphite instance
#!/bin/bash
set -euo pipefail
api_key="" # API key from Grafana Cloud
metrics_user="" # Graphite username from Grafana Cloud console
metrics_endpoint="" # Graphite endpoint from Grafana Cloud console
now=$(date +%s)
metric_name=$1
metric_value=$2
metric_interval=$3
metric_body="
[{
\"name\": \"${metric_name}\",
\"value\": ${metric_value},
\"time\": $now,
\"interval\": ${metric_interval}
}]
"
curl -X POST -u "$metrics_user:$api_key" -H "Content-Type: application/json" "$metrics_endpoint" -d "$metric_body"
echo
@dansimau
Copy link
Author

Example usage:

./send-grafana-cloud-metric.sh "home.temperatures;sensor=bathroom" 25.2 300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment