snmpを使ってグラフが描けます。
グラフを作る基本はsnmpを立ち上げた機器に対して問い合わせ。
# cfgmaker community@192.168.0.1 -output out.cfg
@の前がsnmp community。defaultだとpublicとかの値ですね。ここでは”chi”に設定してあります。後ろがホストのIP。outputが出力ファイル。指定しなければ標準出力に。configを作ったらhtmlを作成します。communityをオプションで書くこともできますし、複数のホストをつらつらと書くこともできます。
# indexmaker out.cfg -output=index.html
CentOSで、パッケージインストールしてあれば /etc/httpd/conf.d/ 配下にmrtgの設定があるので/var/www/mrtgも見れるようになります。初期状態でlocalhostだけのallowなので必要に応じて許可する範囲を指定しましょう。
# cat /etc/httpd/conf.d/mrtg.conf
#
# This configuration file maps the mrtg output (generated daily)
# into the URL space. By default these results are only accessible
# from the local host.
#
Alias /mrtg /var/www/mrtg
<Location /mrtg>
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.0.0/16
Allow from ::1
# Allow from .example.com
</Location>
あとは、こっちもパッケージだと勝手に設定されるかもしれませんが、5分毎にmrtgを起動してデータを取りに行きます。
# crontab -l
*/5 * * * * LANG=C /usr/bin/mrtg /var/www/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok >/dev/null 2>/dev/null
——–
以下、自分用メモ。オプションをうまくやればいけそうだけどできなかったのでdescrをベースにオプションを書き換え。出力したものを全部手で直すより、元のscriptを改造したほうが楽ぢゃん。といふことで。
# yum list installed | grep mrtg
mrtg.i686 2.16.2-9.el6 @base
mrtg-libs.i686 2.16.2-9.el6 @base
# pwd
/usr/bin
# diff indexmaker indexmaker.org
354d353
< my $chi = "";
400,410d398
< /^chi$/ &&
< do{
< $section = "$item";
< $$rcfg{setenv}{$item} =~ /MRTG_INT_DESCR="(.+?)"/
< and $section = $1;
< $$rcfg{pagetop}{$item} =~
< m,<td>Description:</td>\s*<td>\Q$section\E\s*([^< ][^<]+?)</td>,i
< and $chi = $1;
< $section = $section . " " . $chi;
< last;
< };
★configとhtml作成用script
#!/bin/bash
for i in \
chi-labo-SW1:192.168.0.225 \
chi-labo-RT0:192.168.0.236 \
chi-labo-RT1:192.168.0.237 \
do
echo $i
read -a node <<<${i//:/ } ★forでまわして":"でnode{0},node{1}の2つの変数に分離
/usr/bin/cfgmaker \
--noreversedns --show-op-down --subdirs=HOSTNAME \
--ifref=descr \
--global "WorkDir: /var/www/mrtg/" \
--global "Options[_]: growright,bits,unknaszero" \
--global "ImageDir: images/" \
chi@${node[1]}:::::2 >${node[0]}.cfg
/usr/bin/indexmaker ${node[0]}.cfg \
--column 3 --width=365 \
--section=chi --title ${node[0]} --output=${node[0]}.html
done
cat chi*cfg >mrtg.cfg
あとは、各node毎にhtmlファイルを作ったので、それをまとめるindex.htmlを書いておけば見やすくなります。