RT57iのトラフィック監視

概要

  • RT57iはSNMPを喋れないので、なんとかしようとして動かしていた頃の記録を残しておく。
  • 同様のことを考えていた人がRTA50i用のスクリプトを公開してくれていたので、ちょっとだけ変更した記憶があるけど、もはや分からないです。

MRTGの設定

######################################################################
# YAMAHA RT57i Router 2017/02/11 obsolated
######################################################################

Target[rt57i]: `/home/cutxout/bin/getstat-rta50i.pl`
SetEnv[rt57i]: MRTG_INT_IP="192.168.100.1" MRTG_INT_DESCR="PP1"
MaxBytes[rt57i]: 125000000
Options[rt57i]: avgpeak, growright, bits, dorelpercent, unknaszero
XSize[rt57i]: 600
YSize[rt57i]: 200
Title[rt57i]: miyabi.dyndns.org: Traffic Analysis [RT57i]
PageTop[rt57i]: <H1>miyabi.dyndns.org: Traffic Analysis [RT57i]</H1>
 <TABLE>
   <TR><TD>Max Speed:</TD>    <TD>12.5 MBytes/s  </TD></TR>
   <TR><TD>Ip Address:</TD>   <TD>192.168.100.1 [gateway]</TD></TR>
   <TR><TD>YAMAHA</TD>       <TD>RT57i</TD></TR>
 </TABLE>

getstat-rta50i.pl

#!/usr/bin/perl

# getstat-rta50i  -- Get statistic information for 'mrtg' from RTA50i.

#	Copyright (C) 1999 by Yoshiyuki Kondo <cond@context.co.jp>

#	You may redistribute and/or modify this file under the terms of
#	the GNU General Public Licence as published by the Free Software 
#	Foundation.

#	NO WARRANTY

#	2000/3/21
#	  RTA50iが返す送受信バイト数の単位が、(octetsではなく)octet
#	  になっていることがあるので、それに対応した。

# ルーターの名前
$routername = '192.168.100.1';

# ルーターのパスワード
$passwd = '#####';

# ----------------------------------------------------------------------
# これ以降の部分はいじらないこと。

$prompt = '/>\s+/';

use Net::Telnet ();
$t = new Net::Telnet;

# RTA50iにログインする
#	いきなりPassword:プロンプトが出るので、標準のlogin()メソッドが使えない
$t->open($routername);
$t->waitfor('/assword: $/');
$t->print($passwd);
$t->waitfor($prompt);

# プロンプトをセットする
$t->prompt($prompt);

# 表示を英語モードに設定
$t->cmd("console character ascii");

# 転送バイト数を取得する
@lines = $t->cmd("show status pp 1");
foreach (@lines) {
    if (/^Received: /) {	# 受信バイト数
	/\[(\d+) octets?]/;		# [2000/3/21] 変更
	$recv = $1;
    }
    if (/^Transmitted:/) {	# 送信バイト数
	/\[(\d+) octets?]/;		# [2000/3/21] 変更
	$trans = $1;
    }
}

# uptimeを取得する
@lines = $t->cmd("show environment");
foreach (@lines) {
    if (/Elapsed time from boot: (.+)/) {
	$uptime = $1;
	last;
    }
}

# 結果を出力する
print $recv, "\n";
print $trans, "\n";
print $uptime, "\n";
print $routername, "\n";