こんにちは松田です。
muninのプラグインを作成する機会があったので共有します。
各バージョン
- CentOS 6.8
- munin-2.0.25
- munin-node-2.0.25
概要
プラグインはmunin-node側に作成します。
munin-master側では自動で認識して監視項目に追加されます。
プラグイン本体
プラグインの本体(実行ファイル)は値を返すだけのシェルスクリプトです。
(シェルスクリプトでなくても実行できる形式なら良い)
標準で組み込まれているapache_accessesの実行例を下に示します。項目名と値を返すだけです。
[root@srv1 ~]# /etc/munin/plugins/apache_accesses
accesses80.value 826
プラグインの作成
実行ファイルは第一引数configに対応する必要があります。
第一引数にconfigを指定された場合は、グラフ(RRDtool)の設定を返すようにします。
#!/bin/sh
if [ "$1" = "config" ]; then
echo 'graph_title test plugin'
echo 'graph_args --rigid --lower-limit 0 --upper-limit 100'
echo 'graph_scale no'
echo 'graph_vlabel vlabel'
echo 'graph_category Test'
echo 'test1.label test1(%)'
echo 'test1.draw LINE2'
echo 'test1.type GAUGE'
echo 'test2.label test2(%)'
echo 'test2.draw LINE2'
echo 'test2.type GAUGE'
exit 0
fi
echo "test1.value 55"
echo "test2.value 38"
作成したプラグインの設置
以下のパスに実行ファイルを設置します。
/usr/share/munin/plugins/testplugin
以下のシンボリックリンクを貼ります。
/etc/munin/plugins/testplugin -> /usr/share/munin/plugins/testplugin
munin-nodeデーモンを再起動することで反映されます。
services munin-node restart
動作確認
munin-runコマンドで値が正常に返ってくるか確認します。
[root@srv1 ~]# /usr/sbin/munin-run testplugin
test1.value 55
test2.value 38
しばらくするとmunin-master側に反映されるので、Webブラウザで確認します。