Mackerel で Linux の基本的なメトリクスの監視やプロセスの監視が行える、便利な公式プラグインは rpm/deb しか提供されていないので、CoreOS からはすぐに利用できない。
そこで、CoreOS の強みを生かして、docker でソースからビルドしたものを使ってみることにした。(もっと楽なやり方があれば是非教えてください。)
やり方
以下はコンテナの中で check-procs と mackerel-agent-plugins をビルドして、ホストの /etc/mackerel-agent/plugins
に配置する例です。
こんな感じの Dockerfile を作成する。いちいち ADD するファイルをリポジトリにコミットしたくなかったので、Dockerfile だけで完結するようにヒアドキュメント風に記述してみた。
$ cat Dockerfile.mackerel_plugins
FROM golang
RUN echo '#!/bin/bash \n\
mkdir -p src/github.com/mackerelio/ \n\
git clone https://github.com/mackerelio/go-check-plugins.git /go/src/github.com/mackerelio/go-check-plugins \n\
git clone https://github.com/mackerelio/mackerel-agent-plugins.git /go/src/github.com/mackerelio/mackerel-agent-plugins \n\
cd /go/src/github.com/mackerelio/go-check-plugins/check-procs && go get \n\
cd /go/src/github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-linux && go get \n\
go install github.com/mackerelio/go-check-plugins/check-procs \n\
go install github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-linux \n'\
>> build.sh && chmod +x build.sh
CMD ./build.sh
イメージビルド。
$ docker build -f Dockerfile.mackerel_plugins -t mackerel_plugins .
(略)
Successfully built dae8d86210ed
コンテナ実行。
$ docker run -v /etc/mackerel-agent/plugins/:/go/bin/ mackerel_plugins
Cloning into '/go/src/github.com/mackerelio/go-check-plugins'...
Cloning into '/go/src/github.com/mackerelio/mackerel-agent-plugins'...
ホスト側にバイナリができてる。
$ ls /etc/mackerel-agent/plugins/
check-procs mackerel-plugin-linux
普通に実行もできた。
$ /etc/mackerel-agent/plugins/check-procs
Procs OK: Found 87 matching processes
$ /etc/mackerel-agent/plugins/mackerel-plugin-linux
linux.ss.ESTAB 44.000000 1484115977
linux.ss.TIME-WAIT 1.000000 1484115977
linux.ss.UNCONN 83.000000 1484115977
linux.ss.LISTEN 19.000000 1484115977
linux.disk.elapsed.iotime_sda 176.842105 1484115977
linux.disk.elapsed.iotime_weighted_sda 1676.842105 1484115977
linux.disk.rwtime.tsreading_sda 1676.842105 1484115977
linux.disk.rwtime.tswriting_sda 0.000000 1484115977
linux.interrupts.interrupts 5687.368421 1484115977
linux.context_switches.context_switches 6543.157895 1484115977
linux.forks.forks 82.105263 1484115977
linux.users.users 1.000000 1484115977
linux.swap.pswpin 0.000000 1484115977
linux.swap.pswpout 0.000000 1484115977
あとは公式のドキュメントを参考に、mackerel-agent.conf を書き換えて mackerel-agent を再起動すればよい。
参考資料
- チェック監視に公式チェックプラグイン集を使う - Mackerel ヘルプ
- ミドルウェアのメトリック可視化に公式プラグイン集を使う - Mackerel ヘルプ
- Multiline Dockerfile syntax · Issue #1799 · docker/docker
- mackerelio/mackerel-agent-plugins: Plugins for mackerel-agent
- mackerelio/go-check-plugins: Check Plugins for monitoring written in golang
- [CoreOS][Mackerel]バイナリファイルでmackerel-agentインストールしてみた – ADACHIN SERVER Lab