Skip to content

Instantly share code, notes, and snippets.

@kmiyabbm
Last active October 12, 2018 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmiyabbm/06988a32ed2c4ee39c7ad0825a80aebf to your computer and use it in GitHub Desktop.
Save kmiyabbm/06988a32ed2c4ee39c7ad0825a80aebf to your computer and use it in GitHub Desktop.
Mackerel のサービスメトリックの1分粒度メトリックデータをダウンロードし、CSV形式でバックアップするシェルスクリプト
#!/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