LoginSignup
3
5

More than 5 years have passed since last update.

CoreOS で Mackerel のプラグインを docker からビルドして使う

Last updated at Posted at 2017-01-11

Mackerel で Linux の基本的なメトリクスの監視やプロセスの監視が行える、便利な公式プラグインは rpm/deb しか提供されていないので、CoreOS からはすぐに利用できない。

そこで、CoreOS の強みを生かして、docker でソースからビルドしたものを使ってみることにした。(もっと楽なやり方があれば是非教えてください。)

やり方

以下はコンテナの中で check-procsmackerel-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 を再起動すればよい。

参考資料

3
5
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
5