Get mackerel graph annotation list with mkr

Get mackerel graph annotation list with mkr

mackerelにはグラフに注釈(アノテーション)を付ける機能があります。

このアノテーションを一覧して見たかったのでやってみました。Web画面からは一覧を表示できなくて、APIかmkrコマンドから取得する必要があります。そのやりかたをメモ。

以下のコマンドで取得できます。

  • --from ~ --toで期間を指定しなければならない
    • 2016/01/01 00:00:00から今現在までの期間を指定している
  • エポックタイムで指定しなければならない(dateコマンドでエポックタイムに変換している)
mkr annotations list \
--service <サービス名> \
--from $(date -jf '%Y/%m/%d %H:%M:%S' '2016/01/01 00:00:00' +%s) \
--to $(date +%s)

ちょっと面倒!

こんな感じで一覧を取得できます。

$ mkr annotations list \
--service VPS \
--from $(date -jf '%Y/%m/%d %H:%M:%S' '2016/01/01 00:00:00' +%s) \
--to $(date +%s)

[
    {
        "id": "xxxxxxxx",
        "title": "test",
        "description": "test",
        "from": 1485672698,
        "to": 1485672698,
        "service": "VPS",
        "roles": [
            "ponpokopon"
        ]
    },

...

あとはjqと組み合わせるなりなんなり。以下ではアノテーションのタイトルだけ表示してみています。

$ mkr annotations list \
--service VPS \
--from $(date -jf '%Y/%m/%d %H:%M:%S' '2016/01/01 00:00:00' +%s) \
--to $(date +%s) | jq '.[].title'
"test"
"test"
"test"
"test"
"test"
"test"
"test"
"terraform"
"terraform"
"test"
"terraform"
"terraform"
"terraform"
"terraform"
"terraform"
"terraform"

感想

期間の指定でエポックタイム以外も使えるとより便利そう。