Last active
October 12, 2018 15:53
-
-
Save kmiyabbm/06988a32ed2c4ee39c7ad0825a80aebf to your computer and use it in GitHub Desktop.
Mackerel のサービスメトリックの1分粒度メトリックデータをダウンロードし、CSV形式でバックアップするシェルスクリプト
This file contains 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 | |
API_KEY="<Your API KEY>" | |
SERVICE_NAME="<Your service name>" | |
METRIC="<Your metric name>" | |
FROM="2018-10-01 00:00" | |
TO="2018-10-05 00:00" | |
FROM_EPOCH=`date +%s --date "${FROM}"` | |
TO_EPOCH=`date +%s --date "${TO}"` | |
SPAN=72239 | |
from=${FROM_EPOCH} | |
while [ ${from} -lt ${TO_EPOCH} ] | |
do | |
to=`expr ${from} + ${SPAN}` | |
curl -s -H "X-Api-Key:${API_KEY}" "https://api.mackerelio.com/api/v0/services/${SERVICE_NAME}/metrics?name=${METRIC}&from=${from}&to=${to}" |jq -r '.metrics[]| [.time, .value] | @csv' | |
from=${to} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment