Mackerelを入れてpostgres監視するまでのメモ

環境

  • Ubuntu 18.04LTS
  • Mackerel

手順

Mackerel エージェントを入れる

https://mackerel.io/ja/docs/entry/howto/install-agent

Ubuntu16 以降なので以下のコマンド。と言っても、Mackerel の Web にログイン状態で、Hosts→ 右上のエージェントをインストール を選択すると OS の選択肢が表示されて、そこから選ぶとコマンドが完璧な形で表示されるのでそこをコピペすることをおすすめします。

1
wget -q -O - https://mackerel.io/file/script/setup-all-apt-v2.sh | MACKEREL_APIKEY='<YOUR_API_KEY>' sh

Mackerel Agent Plugin を入れる

全部のプラグインがセットになっています。

1
apt-get install mackerel-agent-plugins

Postgres Plugin 設定

Mackerel のプラグインは CLI からテストできる。楽。

1
2
mackerel-plugin-postgres -user=postgres -password=postgres_pwd [-database=<databasename>]
# -database 以降省略可能

出力例

なお、最初は同じコマンドを二度実行しないと警告が表示されます。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
postgres.tempfile.temp_bytes    0.000000        1534094514
postgres.connections.active 1.000000 1534094514
postgres.connections.active_waiting 0.000000 1534094514
postgres.connections.idle 0.000000 1534094514
postgres.connections.idle_in_transaction 0.000000 1534094514
postgres.commits.xact_commit 77.899761 1534094514
postgres.commits.xact_rollback 0.000000 1534094514
postgres.blocks.blks_read 2.291169 1534094514
postgres.blocks.blks_hit 1660.954654 1534094514
postgres.size.total_size 984558979.000000 1534094514
postgres.iotime.blk_read_time 0.000000 1534094514
postgres.iotime.blk_write_time 0.000000 1534094514
postgres.rows.tup_returned 7974.272076 1534094514
postgres.rows.tup_fetched 739.761337 1534094514
postgres.rows.tup_inserted 1.861575 1534094514
postgres.rows.tup_updated 2.004773 1534094514
postgres.rows.tup_deleted 0.000000 1534094514
postgres.deadlocks.deadlocks 0.000000 1534094514
postgres.xlog_location.xlog_location_bytes 37238.377088 1534094514

Mackerel Agent に plugin 実行を指示する

設定ファイルに実行する内容を記述する必要があります。

/etc/mackerel-agent/mackerel-agent.conf を編集します。

すでに plugin の設定サンプルが書かれているので、コメントアウトするだけ…

ではありません 設定例は以下のような形になります。

1
2
[plugin.metrics.postgres]
command = "mackerel-plugin-postgres -user=postgres -password=postgres_pwd"

蛇足

ようするに command = "先程テストしたコマンドラインそのまま"

です。これに気づかず、少しハマりました。

他のプラグインでパラメタがないものについては、設定ファイルのコメントアウトを外すだけで有効になります。

各プラグインの説明は・・・ https://github.com/mackerelio/mackerel-agent-plugins

これなんですかねぇ… 割と淡白な説明ですがなんとかなると思います。