2011年4月10日日曜日

cacti コマンドライン(CLI)での操作

cactiをコマンドライン(CLI)で扱う手順を残しておく。


登録内容
① Devices(ホスト)の登録
デバイス名:new_server
IPアドレス:10.0.0.1
コミュニティ名:public

② Associated Graph Templates
・ ucd/net - CPU Usage
・ ucd/net - Load Average
・ ucd/net - Memory Usage

③ Associated Data Queries
・ SNMP - Interface Statistics
・ ucd/net - Get Monitored Partitions


前提
cactiはインストール済みとする

コマンド操作はcactiユーザで行う
$ su - cacti


下記ディレクトリに移動しておく
$ cd /var/www/cacti/cli/



登録手順
① デバイス(ホスト)の登録
ホストテンプレートの確認
$ php add_device.php --list-host-templates
Valid Host Templates: (id, name)
0 None
1 Generic SNMP-enabled Host
3 ucd/net SNMP Host
4 Karlnet Wireless Bridge
5 Cisco Router
6 Netware 4/5 Server
7 Windows 2000/XP Host
8 Local Linux Machine

今回は0番のNoneを選ぶ


デバイスの登録
$ php add_device.php --description=new_server --ip=10.0.0.1 --version=2 --avail=snmp --community=public --template=0
Adding newserver (10.0.0.1) as "None" using SNMP v2 with community "public"
Success - new device-id: (10) ← このdevice-idを覚えておく



② Associated Graph Templates への登録
グラフテンプレートIDの確認
$ php add_graph_template.php --list-graph-templates
11 ucd/net - CPU Usage
12 ucd/net - Load Average
13 ucd/net - Memory Usage


グラフテンプレートの登録
$ php add_graph_template.php --host-id=10 --graph-template-id=11

$ php add_graph_template.php --host-id=10 --graph-template-id=12

$ php add_graph_template.php --host-id=10 --graph-template-id=13



グラフの登録
"Associated Graph Templates"のステータスが"Is Being Graphed"に変わる

$ php add_graphs.php --host-id=10 --graph-template-id=11 --graph-type=cg

$ php add_graphs.php --host-id=10 --graph-template-id=12 --graph-type=cg

$ php add_graphs.php --host-id=10 --graph-template-id=13 --graph-type=cg




③ Associated Data Queries への登録
(a) データのクエリの登録
データクエリIDの確認
$ php -q add_graphs.php --list-graph-templates
21 Interface - Traffic (bits/sec)
22 ucd/net - Available Disk Space

データクエリIDの登録
$ php add_data_query.php --host-id=10 --data-query-id=21 --reindex-method=1

$ php add_data_query.php --host-id=10 --data-query-id=22 --reindex-method=1

[--reindex-method=]
the reindex method to be used for that data query
if data query already exists, the reindex method will not be changed
0 | None = no reindexing
1 | Uptime = Uptime goes Backwards (Default)
2 | Index = Index Count Changed
※とりあえず1でよい


(b) データクエリのどの項目を登録するかの決定
フィールドの確認
$ php -q add_graphs.php --host-id=10 --list-snmp-fields
ifAlias
ifDescr
ifHwAddr
ifIndex
ifIP
ifName
ifOperStatus
ifSpeed
ifType

dskDevice
dskIndex
dskPath


バリューの確認
ディスクパス
$ php -q add_graphs.php --host-id=10 --snmp-field=dskPath --list-snmp-values
/
/boot
/imail


インターフェースステータスの確認
$ php -q add_graphs.php --host-id=10 --snmp-field=ifOperStatus --list-snmp-values
Down
Up


グラフテンプレートIDの確認
$ php -q add_graphs.php --list-graph-templates
31 Interface - Errors/Discards
32 Interface - Traffic (bits/sec)
33 ucd/net - Available Disk Space


データクエリIDの確認
"Data Queries"の"Associated Graph Templates"を設定をした時の名前が、
そこに紐づくIDと共に表示される
$ php -q add_graphs.php --list-snmp-queries
41 SNMP - Interface Statistics
42 ucd/net - Get Monitored Partitions


クエリタイプの確認
$ php -q add_graphs.php --snmp-query-id=1 --list-query-types
51 In/Out Errors/Discarded Packets
52 In/Out Bits (64-bit Counters)

$ php -q add_graphs.php --snmp-query-id=2 --list-query-types
61 Available/Used Disk Space


グラフの追加
インターフェースのエラーカウンタ
$ php add_graphs.php --host-id=10 --graph-type=ds --graph-template-id=31 --snmp-query-id=41 --snmp-query-type-id=51 --snmp-field=ifOperStatus --snmp-value=Up


インターフェースのトラフィック
$ php add_graphs.php --host-id=10 --graph-type=ds --graph-template-id=32 --snmp-query-id=41 --snmp-query-type-id=52 --snmp-field=ifOperStatus --snmp-value=Up


マウントポイント
$ php add_graphs.php --host-id=10 --graph-type=ds --graph-template-id=33 --snmp-query-id=42 --snmp-query-type-id=61 --snmp-field=dskPath --snmp-value=/

$ php add_graphs.php --host-id=10 --graph-type=ds --graph-template-id=33 --snmp-query-id=42 --snmp-query-type-id=61 --snmp-field=dskPath --snmp-value=/boot

$ php add_graphs.php --host-id=10 --graph-type=ds --graph-template-id=33 --snmp-query-id=42 --snmp-query-type-id=61 --snmp-field=dskPath --snmp-value=/var




【参考】
http://www.cacti.net/downloads/docs/html/cli_add_graphs.html
http://labs.unoh.net/2010/02/cacti.html