Last active
December 12, 2015 14:39
-
-
Save itchyny/d8e710aa26a5566e2936 to your computer and use it in GitHub Desktop.
Weather metric for Mackerel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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