Skip to content

Instantly share code, notes, and snippets.

@itchyny
Last active December 12, 2015 14:39
Show Gist options
  • Save itchyny/d8e710aa26a5566e2936 to your computer and use it in GitHub Desktop.
Save itchyny/d8e710aa26a5566e2936 to your computer and use it in GitHub Desktop.
Weather metric for Mackerel
#!/bin/bash
pos=Kyoto,jp
units=metric
appid=
url="http://api.openweathermap.org/data/2.5/weather?q=$pos&units=$units&APPID=$appid"
res=$(/usr/bin/curl -m 5 -s "$url")
time=$(date +%s)
curl https://mackerel.io/api/v0/services/SERVICE/tsdb \
-H 'X-Api-Key: APIKEY' \
-H 'Content-Type: application/json' \
-X POST \
-d '[{"name": "weather.temperature", "time": '$time', "value": '$(echo $res | /usr/local/bin/jq ".main.temp")'},
{"name": "weather.rain", "time": '$time', "value": '$(echo $res | /usr/local/bin/jq '.rain["1h"] // 0')'},
{"name": "weather.wind", "time": '$time', "value": '$(echo $res | /usr/local/bin/jq '.wind.speed')'},
{"name": "weather.pressure", "time": '$time', "value": '$(echo $res | /usr/local/bin/jq ".main.pressure" | awk '{ print ($1/100) }')'}
]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment