LoginSignup
3
4

More than 5 years have passed since last update.

Mackerelの監視モニタリングをコード管理しよう

Last updated at Posted at 2017-01-27

概要

今回は下記グラフの監視設定を追加してみます

  • メトリック名:custom.rds.Deadlocks
  • label名:Deadlocks
  • 閾値: 5 warning, 10 critical, 3回計測
  • hoge.com:db, fuga.com:dbが対象 スクリーンショット 2017-01-27 17.55.09.png

内容

①mkrでwrite可能なMackerel API_Keyを読み込んでおく

$ vim ~/.bashrc
export MACKEREL_APIKEY="xxxxxx"

### 読み込む
$ source ~/.bashrc

②mkrインストール

### 参照:https://mackerel.io/ja/docs/entry/advanced/cli
$ brew install mkr

③今回はdeadlockというのを監視してみます

### ディレクトリ作成
$ mkdir /path/to/mackerel

### ディレクトリ移動
$ cd /path/to/mackerel

### 最新のデータを持ってくる
$ mkr monitors pull
# monitors.jsonが出来る

### 編集してdiff
$ vim monitors.json
# diffで出力されるのであえて書かない

$ mkr monitors diff
+ {
+   "name": "custom.rds.Deadlocks",
+   "type": "host",
+   "metric": "custom.rds.Deadlocks.Deadlocks",
+   "operator": ">",
+   "warning": 5,
+   "critical": 10,
+   "duration": 3,
+   "scopes": [
+     "hoge.com: db",
+     "fuga.com: db"
+   ]
+ },

### 反映
$ mkr monitors push --dry-run
$ mkr monitors push
# 403 Forbiddenが出る人はAPI_KEYがReadOnlyかもしれないです

### 反映後、idが付与されるので、pullしてください。
$ mkr monitors pull

④確認

  • Monitorsに追加されてる
    スクリーンショット 2017-01-27 17.59.41.png

  • 対象のホストの右側にも追加されてる(時間差で反映されます)
    スクリーンショット 2017-01-27 18.00.41.png

最後に

  • mkrでの監視モニタリングのコード管理すごい便利!
  • コード化出来たので、そのままGit管理していきましょう
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4