LoginSignup
40
54

More than 5 years have passed since last update.

サーバー監視ツール Munin

Last updated at Posted at 2016-08-25

Munin

Munin は Perl で書かれたリソース監視ツール。RRDtool でグラフを作成している。

バージョン情報

安定版は 2017-10-21 リリースの 2.0.34 で、EPEL リポジトリーで提供されている。
最新評価版は 2017-01-21 リリースの 2.99.3 になる。
CentOS では EPEL リポジトリで 2.0.33 がインストール可能。

由来

munin.png

Munin はムニンと発音し、北欧神話の神オーディンに付き添う一対のワタリガラスの「記憶」を意味する片方。二羽は夜明けに外に出され、情報を集めてから夜に帰ってきてオーディンの耳にニュースをささやくという。1 リソース監視ツールとしてはなかなかセンスの良いネーミング。
というわけで、ロゴのイメージはカラスだったのである。

Munin node (client)

インストール

yum install epel-release
yum install munin-node

EPEL リポジトリーで提供されるパッケージは最新安定版の 2.0.25 になる。

プラグイン

確認

munin-node-configure --suggest
出力例
Plugin                     | Used | Suggestions
------                     | ---- | -----------
acpi                       | no   | no [cannot read []
amavis                     | no   | no
apache_accesses            | no   | no [apache server-status not found. check if mod_status is enabled]
apache_processes           | no   | no [apache server-status not found. check if mod_status is enabled]
apache_volume              | no   | no [apache server-status not found. check if mod_status is enabled]
apc_envunit_               | no   | no [no units to monitor]
bonding_err_               | no   | no [No /proc/net/bonding]
courier_mta_mailqueue      | no   | no [spooldir not found]
courier_mta_mailstats      | no   | no [could not find executable]
courier_mta_mailvolume     | no   | no [could not find executable]
cps_                       | no   | no
cpu                        | yes  | yes
cpuspeed                   | no   | no [missing /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state]
cupsys_pages               | no   | no [could not find logdir]
df                         | yes  | yes
df_inode                   | yes  | yes
diskstats                  | yes  | yes
entropy                    | yes  | yes
exim_mailqueue             | no   | no [no exiqgrep]
exim_mailstats             | no   | no ['/usr/sbin/exim -bP log_file_path' returned an error]
fail2ban                   | no   | no [/usr/bin/fail2ban-client not found]
forks                      | yes  | yes
fw_conntrack               | no   | no
fw_forwarded_local         | no   | no
fw_packets                 | yes  | yes
hddtemp_smartctl           | no   | no
http_loadtime              | no   | no
if_                        | yes  | yes (enp0s3 enp0s8)
if_err_                    | yes  | yes (enp0s3 enp0s8)
interrupts                 | yes  | yes
ip_                        | no   | no [could not run iptables as user nobody]
ipmi_                      | no   | no [missing ipmitool command]
irqstats                   | yes  | yes
load                       | yes  | yes
lpstat                     | no   | no [lpstat not found]
memory                     | yes  | yes
munin_stats                | no   | yes
mysql_                     | no   | no
netstat                    | no   | no [netstat program not found]
nfs4_client                | no   | no [no /proc/net/rpc/nfs]
nfs_client                 | no   | no
nfsd                       | no   | no [no /proc/net/rpc/nfsd]
nfsd4                      | no   | no [no /proc/net/rpc/nfsd]
nginx_request              | no   | no [no nginx status on http://localhost/nginx_status]
nginx_status               | no   | no [no nginx status on http://localhost/nginx_status]
ntp_kernel_err             | no   | no
ntp_kernel_pll_freq        | no   | no
ntp_kernel_pll_off         | no   | no
ntp_offset                 | no   | no [no ntpq program]
ntp_states                 | no   | no [ntpq not found]
nvidia_                    | no   | no [no nvclock executable at /usr/bin/nvclock, please configure]
open_files                 | yes  | yes
open_inodes                | yes  | yes
pgbouncer_connections      | no   | no
pgbouncer_requests         | no   | no
postfix_mailqueue          | yes  | yes
postfix_mailvolume         | yes  | yes
postgres_autovacuum        | no   | no
postgres_bgwriter          | no   | no
postgres_cache_            | no   | no
postgres_checkpoints       | no   | no
postgres_connections_      | no   | no
postgres_connections_db    | no   | no
postgres_locks_            | no   | no
postgres_oldest_prepared_xact_ | no   | no
postgres_prepared_xacts_   | no   | no
postgres_querylength_      | no   | no
postgres_scans_            | no   | no
postgres_size_             | no   | no
postgres_transactions_     | no   | no
postgres_tuples_           | no   | no
postgres_users             | no   | no
postgres_xlog              | no   | no
proc                       | no   | no
proc_pri                   | yes  | yes
processes                  | yes  | yes
ps_                        | no   | no
qmailqstat                 | no   | no
selinux_avcstat            | no   | no [missing /selinux/avc/cache_stats file]
sendmail_mailqueue         | no   | no
sendmail_mailstats         | no   | no [no mailstats command]
sendmail_mailtraffic       | no   | no [no mailstats command]
slapd_                     | no   | no [Net::LDAP not found]
slapd_bdb_cache_           | no   | no [Can't execute db_stat file '/usr/bin/db4.6_stat']
slony_lag_                 | no   | no
smart_                     | no   | no [smartmontools not found]
snort_alerts               | no   | no [/var/snort/snort.stats not readable]
snort_bytes_pkt            | no   | no [/var/snort/snort.stats not readable]
snort_drop_rate            | no   | no [/var/snort/snort.stats not readable]
snort_pattern_match        | no   | no [/var/snort/snort.stats not readable]
snort_pkts                 | no   | no [/var/snort/snort.stats not readable]
snort_traffic              | no   | no [/var/snort/snort.stats not readable]
squeezebox_                | no   | no [no connection on localhost port 9090]
squid_cache                | no   | no [could not connect: Connection refused]
squid_objectsize           | no   | no [could not connect: Connection refused]
squid_requests             | no   | no [could not connect: Connection refused]
squid_traffic              | no   | no [could not connect: Connection refused]
swap                       | yes  | yes
threads                    | yes  | yes
uptime                     | yes  | yes
users                      | yes  | yes
varnish_                   | no   | no [varnishstat could not be found]
vmstat                     | yes  | yes
vserver_cpu_               | no   | no [/proc/virtual/info not found]
vserver_loadavg            | no   | no [/proc/virtual/info not found]
vserver_resources          | no   | no [/proc/virtual/info not found]
yum                        | no   | no [Could not find statefile.  Please read 'munindoc yum']

Apache の Status を有効化

cat << _EOF_ > /etc/httpd/conf.d/server-status.conf
<Location "/server-status">
    SetHandler server-status
    Require host localhost
</Location>
_EOF_
systemctl restart httpd

Apache の監視には server-status の有効化が必要。
ExtendedStatus は Apache 2.3.6 以降 mod_status モジュールがロードされた時点でデフォルトで On に切り替わる。

追加

munin-node-configure -shell | sh

自動起動設定と起動

systemctl enable munin-node
systemctl start munin-node

Munin master (server)

インストール

yum install httpd munin

設定調整

chown apache:munin /var/log/munin

後から Apache をインストールした場合に拡大グラフが参照できなくなるので、ログディレクトリの所有者を変更する。

パフォーマンス改善

cron の処理分割

sed -i '/munin-cron/s/^/#/' /etc/cron.d/munin
cat << _EOF_ >> /etc/cron.d/munin
*/5 * * * *     munin test -x /usr/bin/munin-cron && /usr/share/munin/munin-update
5 */1 * * *     munin test -x /usr/bin/munin-cron && /usr/share/munin/munin-graph --cron
10 07 * * *     munin test -x /usr/bin/munin-cron && /usr/share/munin/munin-html
_EOF_

グラフの再生成を5分おきから1時間おきに、HTML の再生成を5分おきから1日おきに変更することでパフォーマンスを改善させる。
最新グラフが見たい場合はグラフをクリックして拡大グラフを確認すればよい。

不要なプラグインの除去

unlink /etc/munin/plugins/entropy
unlink /etc/munin/plugins/interrupts
unlink /etc/munin/plugins/irqstats

あまり見ないグラフは除外した方が負荷が軽くなる。

自動起動設定と起動

systemctl enable httpd
systemctl start httpd

BASIC 認証

htpasswd /etc/munin/munin-htpasswd <username>

デフォルト画面例

munin_screen.png

テンプレート

Munstrap

curl -L https://github.com/jonnymccullagh/munstrap/archive/master.tar.gz -o munstrap.tar.gz
mkdir /etc/munin/munstrap
tar vzxf munstrap.tar.gz --strip=1 -C /etc/munin/munstrap
sed -i /etc/munin/munin.conf -e '/^tmpldir/s/^/#/' -e '/^staticdir/s/^/#/'
sed -i '/#tmpldir/a tmpldir /etc/munin/munstrap/templates' /etc/munin/munin.conf
sed -i '/#staticdir/a staticdir /etc/munin/munstrap/static' /etc/munin/munin.conf

munin_screen_munstrap.png

カテゴリーがタブ化されたりして若干だがすっきりする。

munin_dynamic_template

curl -L https://github.com/DaveMDS/munin_dynamic_template/archive/master.tar.gz -o munin_dynamic_template.tar.gz
mkdir /etc/munin/munin_dynamic_template
tar vzxf munin_dynamic_template.tar.gz --strip=1 --exclude="munin1" -C /etc/munin/munin_dynamic_template
sed -i /etc/munin/munin.conf -e '/^tmpldir/s/^/#/' -e '/^staticdir/s/^/#/'
sed -i '/#tmpldir/a tmpldir /etc/munin/munin_dynamic_template/munin2' /etc/munin/munin.conf
sed -i '/#staticdir/a staticdir /etc/munin/munin_dynamic_template/munin2/static' /etc/munin/munin.conf

munin_screen_dynamic_1.png

munin_screen_dynamic_2.png

modern-munin

curl -L https://github.com/sjoudry/modern-munin/archive/master.tar.gz -o modern-munin.tar.gz
mkdir /etc/munin/modern-munin
tar vzxf modern-munin.tar.gz --strip=1 -C /etc/munin/modern-munin
sed -i /etc/munin/munin.conf -e '/^tmpldir/s/^/#/' -e '/^staticdir/s/^/#/'
sed -i '/#tmpldir/a tmpldir /etc/munin/modern-munin' /etc/munin/munin.conf
sed -i '/#staticdir/a staticdir /etc/munin/modern-munin/static' /etc/munin/munin.conf

munin-b3

curl -L https://code.not-your-server.de/munin-b3.git/tags/0.3.2.tar.gz -o munin-b3.tar.gz
mkdir /etc/munin/munin-b3
tar vzxf munin-b3.tar.gz --strip=1 -C /etc/munin/munin-b3
sed -i /etc/munin/munin.conf -e '/^tmpldir/s/^/#/' -e '/^staticdir/s/^/#/'
sed -i '/#tmpldir/a tmpldir /etc/munin/munin-b3/templates' /etc/munin/munin.conf
sed -i '/#staticdir/a staticdir /etc/munin/munin-b3/static' /etc/munin/munin.conf

munin_screen_b3_1.png

munin_screen_b3_2.png

Munin JQuery Template

curl -L https://github.com/mallocator/Munin-JQuery-Template/archive/master.tar.gz -o munin-jquery-template.tar.gz
mkdir /etc/munin/munin-jquery-template
tar vzxf munin-jquery-template.tar.gz --strip=1 -C /etc/munin/munin-jquery-template
sed -i /etc/munin/munin.conf -e '/^tmpldir/s/^/#/' -e '/^staticdir/s/^/#/'
sed -i '/#tmpldir/a tmpldir /etc/munin/munin-jquery-template/templates' /etc/munin/munin.conf
ln -s /etc/munin/munin-jquery-template/templates/assets /var/www/html/munin/
ln -s /etc/munin/munin-jquery-template/templates/style.css /var/www/html/munin/

munin_screen_jquery_1.png
ドラッグ&ドロップができたり試みとしては面白いが、設定と使い勝手がやや残念。
拡大グラフはリンクされていない模様。

モニタリング関連記事

40
54
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
40
54