rrdcached と munin 続き

デフォルトのmunin.confだとパフォーマンスがかなり悪いのでいくつか設定を追加してみた。
結果から言うとfastcgi+graph/htmlの動的生成とrrdcachedの導入で相当の数のrrdオブジェクトを扱う事が可能になると思う。
デメリットとしてはgraph/html生成時に少し待ち時間が増える事と、rrdcachedがメモリを結構使うのでswapしないように注意。
早く2.0.xのrpm配布されないかな。

  • htmlファイルもgraph同様にcgiで動的に生成

/etc/opt/munin/munin.conf

html_strategy cgi

/etc/httpd/conf.d/munin.conf

<VirtualHost *:80>
    ServerName munin.example.org
    DocumentRoot /opt/munin/www/docs
    Alias /static /opt/munin/www/docs/static
    ScriptAlias /cgi-bin/ /opt/munin/www/cgi/

    # Rewrites
    RewriteEngine On

    # HTML
    RewriteCond %{REQUEST_URI} !^/static
    RewriteCond %{REQUEST_URI} .html$ [or]
    RewriteCond %{REQUEST_URI} =/
    RewriteRule ^/(.*)          /opt/munin/www/cgi/munin-cgi-html/$1 [L]

    # Ensure we can run (fast)cgi scripts
    <Directory "/opt/munin/www/cgi/">
    Options +ExecCGI
    <IfModule mod_fcgid.c>
        SetHandler fcgid-script
    </IfModule>
    <IfModule !mod_fcgid.c>
        SetHandler cgi-script
    </IfModule>
    </Directory>

</VirtualHost>

apache graceful restart

$ sudo service httpd graceful
  • rrdcachedの導入(epelのrrdtool-1.4.7に既に含まれてるのインストール作業はなし。)

/etc/opt/munin.conf

rrdcached_socket /var/rrdtool/rrdcached/rrdcached.sock

/etc/sysconfig/rrdcached (障害対策でデータを守りたい場合は -j オプションあったほうがいい)
オプションの順番に注意。-s と -m は一番最初にしないとオプション通りに起動しない罠。

OPTIONS="-s rrdcached -m 664 -l unix:/var/rrdtool/rrdcached/rrdcached.sock -l 127.0.0.1 -b /var/opt/munin -w 3600 -z 3600 -f 86400"

munin/apacheアカウントをrrdcached グループに入れる

$ sudo usermod -G rrdcached munin
$ sudo usermod -G rrdcached apache

rrdファイルがmuninアカウントで作成されるためpermissionとownerを変更する
環境によってはrrdファイルの存在するディレクトリのパーミッションも直さないいけないかも(追記修正)

#!/bin/sh

FILE_NUM=`find /var/opt/munin -name "*.rrd" -type f -user munin -group munin -perm 644|wc -l`
if [ $FILE_NUM -eq 0 ];then
  exit 1
fi

for i in `find /var/opt/munin -name "*.rrd" -type f -user munin -group munin -perm 644`; do
  sudo chmod 664 $i
  sudo chown :rrdcached $i
done
exit 0

rrdcached 起動

$ sudo chkconfig rrdcached on
$ sudo service rrdcached start

rrdcached のstatsが確認できる

$ telnet 127.0.0.1 42217
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
STATS
9 Statistics follow
QueueLength: 0
UpdatesReceived: 3024
FlushesReceived: 108
UpdatesWritten: 54
DataSetsWritten: 756
TreeNodesNumber: 216
TreeDepth: 9
JournalBytes: 0
JournalRotate: 0
quit
Connection closed by foreign host.

手動でrrdcached のcacheをフラッシュする

$ telnet 127.0.0.1 42217
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
FLUSHALL
0 Started flush.

参考