リソース監視ツール Munin を使う
Munin とは?
Munin はperlで書かれたサーバリソース等を監視するためのシステムです。
データ取得にはmuninマスターが全てのmuninノードに一定の間隔で接続し、それらのデータを要求する、マスター ・ ノード アーキテクチャを用いており監視対象のホストを追加するのも容易に行なえます。
監視項目はplugin形式で簡単に追加することができ数十の基本的なpluginが付属しており自作のpluginも簡単に作ることが出来ます。
監視対象のサーバリソースを描画されたグラフはWEBインターフェースで一覧表示させることが出来ます。
インストール
# portinstall sysutils/munin-master # portinstall sysutils/munin-node
munin-master設定
/usr/local/etc/munin/munin.conf
取得データの保存場所を指定する事が出来ます。
dbdir /path/to/munin/db htmldir /path/to/munin/www logdir /var/log/munin-master rundir /var/run/munin
muninで利用するディレクトリの作成
$ mkdir /path/to/munin $ mkdir /path/to/munin/db $ mkdir /path/to/munin/www $ sudo chown -R munin:munin /path/to/munin
自動起動設定
/etc/rc.conf
munin_node_enable="YES"
muninを起動・停止
/usr/local/etc/rc.d/munin-node.sh start /usr/local/etc/rc.d/munin-node.sh stop
WEBからグラフを見る
apacheの設定
http://host.example.com/munin/ で取得データ一覧表示する設定
httpd.conf
Alias /munin "/path/to/munin/www"
<Directory "/path/to/munin/www">
DirectoryIndex index.htm index.html
AllowOverride None
Order allow,deny
Allow from all
</Directory>
/usr/local/etc/munin/munin.conf
# Example configuration file for Munin, generated by 'make build'
# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files. They all
# must be writable by the user running munin-cron. They are all
# defaulted to the values you see here.
#
dbdir /path/to/munin/db
htmldir /path/to/munin/www
logdir /path/to/munin/log
# rundir /var/run/munin
#
# Where to look for the HTML templates
tmpldir /usr/local/etc/munin/templates
# (Exactly one) directory to include all files from.
#
includedir /usr/local/etc/munin/munin-conf.d
# Make graphs show values per minute instead of per second
#graph_period minute
# Graphics files are normaly generated by munin-graph, no matter if
# the graphs are used or not. You can change this to
# on-demand-graphing by following the instructions in
# http://munin.projects.linpro.no/wiki/CgiHowto
#
#graph_strategy cgi
# munin-cgi-graph is invoked by the web server up to very many times at the
# same time. This is not optimal since it results in high CPU and memory
# consumption to the degree that the system can thrash. Again the default is
# 6. Most likely the optimal number for max_cgi_graph_jobs is the same as
# max_graph_jobs.
#
#munin_cgi_graph_jobs 6
# If the automatic CGI url is wrong for your system override it here:
#
#cgiurl_graph /cgi-bin/munin-cgi-graph
# munin-graph runs in parallel, the number of concurrent processes is
# 6. If you want munin-graph to not be parallel set to 0. If set too
# high it will slow down munin-graph. Some experiments are needed to
# determine how many are optimal on your system. On a multi-core
# system with good SCSI disks the number can probably be quite high.
#
#max_graph_jobs 6
# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime
# something changes (OK -> WARNING, CRITICAL -> OK, etc)
#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm
#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm
#
# For those with Nagios, the following might come in handy. In addition,
# the services must be defined in the Nagios server as well.
#contact.nagios.command /usr/bin/send_nsca nagios.host.comm -c /etc/nsca.conf
# a simple host tree
[yourhost.example.com]
address 127.0.0.1
use_node_name yes
/usr/local/etc/munin/munin-node.conf
注)追加しないと動かなかった
setsid yes
# # Example config-file for munin-node # log_level 4 log_file /path/to/munin/log/munin-node.log pid_file /var/run/munin/munin-node.pid background 1 setsid 1 user root group wheel setsid yes # Regexps for files to ignore ignore_file ~$ #ignore_file [#~]$ # FIX doesn't work. '#' starts a comment ignore_file DEADJOE$ ignore_file \.bak$ ignore_file %$ ignore_file \.dpkg-(tmp|new|old|dist)$ ignore_file \.rpm(save|new)$ ignore_file \.pod$ ignore_file \.sample$ # Set this if the client doesn't report the correct hostname when # telnetting to localhost, port 4949 # host_name yourhost.example.com # A list of addresses that are allowed to connect. This must be a # regular expression, since Net::Server does not understand CIDR-style # network notation unless the perl module Net::CIDR is installed. You # may repeat the allow line as many times as you'd like allow ^127\.0\.0\.1$ # If you have installed the Net::CIDR perl module, you can use # multiple cidr_allow and cidr_deny address/mask patterns. A # connecting client must match any cidr_allow, and not match any # cidr_deny. Example: # cidr_allow 127.0.0.1/32 # cidr_allow 192.0.2.0/24 # cidr_deny 192.0.2.42/32 # Which address to bind to; host * # host 127.0.0.1 # And which port port 4949
plugin設定
初期設定は何も設定されておりません。監視したい項目のpluginを設定すること。
設定はpluginの実体ファイルが /usr/local/share/munin/plugins/* にあるのでこれらのファイルを /usr/local/etc/munin/plugins/* へシンボリックリンクを貼り付けるだけです。
例)メモリーの利用状況を監視するプラグインmemoryを設定する
# ln -s /usr/local/share/munin/plugins/memory /usr/local/etc/munin/plugins/memory
pluginを設定したらmunin-nodeを再起動して下さい。
5分後に以下のようなグラフが描画されます。

created: