インターフェイスでの帯域幅の使用率の監視

メモ この例は説明のために示されているに過ぎず、実際にはサポートされていません。Ipswitch は、Context オブジェクト、SNMP API、およびスクリプティング環境については、テクニカルサポートを提供しますが、JScript、VBScript、およびアクティブスクリプトのモニタとアクションの開発とデバッグについては、サポートを提供しません。この例および自社独自のスクリプトを作成することに関する援助については、WhatsUp Gold ユーザーコミュニティにアクセスしてください。

このアクティブモニタは、インターフェイス MIB の値をポーリングして、個々のインターフェイスの総帯域幅使用率 (出入力オクテット数) を監視するために使用されます。

// このモニタの設定
// インターフェイスインデックス ifIndex:
var nInterfaceIndex = 65540;

// このモニタはインターフェイス使用率が次の比率を超えると失敗します。
// 現在の帯域幅 / 最大帯域幅 > nMaxInterfaceUtilizationRatio
var nMaxInterfaceUtilizationRatio = 0.7; // 70% に設定

// デバイスをポーリングする SNMP オブジェクトを作成。
var oSnmpRqst = new ActiveXObject("CoreAsp.SnmpRqst");

// デバイス ID を取得
var nDeviceID = Context.GetProperty("DeviceID");

// この関数はデバイスをポーリングし、インデックス nIfIndex ごとにインターフェイスの ifSpeed を返します。
// ifSpeed の単位はビット/秒です。
function getIfSpeed(nIfIndex) {
var oResult = oSnmpRqst.Initialize(nDeviceID);
if (oResult.Failed) {
return null;
}
return parseInt(SnmpGet("1.3.6.1.2.1.2.2.1.5."+ nIfIndex)); // ifSpeed
}
// 関数はそのインターフェイスインデックスの SNMP ifInOctets を nIfIndex (バイト単位) を使って取得。
// 成功したらその値を返し、失敗したら NULL を返します。
function getInOctets(nIfIndex) {
var oResult = oSnmpRqst.Initialize(nDeviceID);
if (oResult.Failed) {
return null;
}
return parseInt(SnmpGet("1.3.6.1.2.1.2.2.1.10."+ nIfIndex)); // inOctets
}

// そのインターフェイスインデックスの SNMP ifOutOctets を nIfIndex (バイト単位) を使って取得するための関数。
// 成功したらポーリングした値を返し、失敗したら NULL を返します。
function getOutOctets(nIfIndex) {
var oResult = oSnmpRqst.Initialize(nDeviceID);
if (oResult.Failed) {
return null;
}
return parseInt(SnmpGet("1.3.6.1.2.1.2.2.1.16."+ nIfIndex)); // outOctets
}

// SNMP オブジェクト (sOid に入れた OID) を取得するためのヘルパー関数。
// 成功したらポーリングした値を返し、失敗したら NULL を返します。
function SnmpGet(sOid) {
var oResult = oSnmpRqst.Get(sOid);
if (oResult.Failed) {
return null;
}
else {
return oResult.GetPayload;
}
}

// 現在の日付を取得。SNMP ポーリングの参照日付として使用されます。
var oDate = new Date();
var nPollDate = parseInt(oDate.getTime()); // ミリ秒単位の整数として日付を取得。
// 実際のポーリングを実行。
var nInOctets = getInOctets(nInterfaceIndex);
var nOutOctets = getOutOctets(nInterfaceIndex);
var nIfSpeed = getIfSpeed(nInterfaceIndex);
if (nInOctets == null || nOutOctets == null || nIfSpeed == null) {
Context.SetResult(1, "Failure to poll this device.");
}
else {
var nTotalOctets = nInOctets + nOutOctets;
// コンテキスト変数に保存されている最新のポーリングのオクテック値と日付を取得。
var nInOutOctetsMonitorPreviousPolledValue = Context.GetProperty("nInOutOctetsMonitorPreviousPolledValue");
var nInOutOctetsMonitorPreviousPollDate = Context.GetProperty("nInOutOctetsMonitorPreviousPollDate");
if (nInOutOctetsMonitorPreviousPolledValue == null || nInOutOctetsMonitorPreviousPollDate == null) {
// これは初めてのポーリングなので、コンテキスト変数はまだ設定されていません。
Context.LogMessage("This monitor requires two polls.");
Context.SetResult(0, "success");
}
else {
// 前回のポーリングから今回のポーリングまでの間に使用された帯域幅を計算。
var nIntervalSec = (nPollDate - nInOutOctetsMonitorPreviousPollDate) / 1000; // 前回のポーリングからの秒単位の経過時間
var nCurrentBps = (nTotalOctets - nInOutOctetsMonitorPreviousPolledValue) * 8 / nIntervalSec;
Context.LogMessage("total octets for interface " + nInterfaceIndex + " = " + nTotalOctets);
Context.LogMessage("previous value = " + nInOutOctetsMonitorPreviousPolledValue);
Context.LogMessage("difference:" + (nTotalOctets - nInOutOctetsMonitorPreviousPolledValue) + " bytes");
Context.LogMessage("Interface Speed:" + nIfSpeed + "bps");
Context.LogMessage("time elapsed since last poll:" + nIntervalSec + "s");
Context.LogMessage("Current Bandwidth utilization:" + nCurrentBps + "bps");
if (nCurrentBps / nIfSpeed > nMaxInterfaceUtilizationRatio) {
Context.SetResult(1, "Failure:bandwidth used on this interface " + nCurrentBps + "bps / total available:" + nIfSpeed + "bps is above the specified ratio:" + nMaxInterfaceUtilizationRatio);
}
else {
Context.SetResult(0, "Success");
}
}
// このポーリング情報をコンテキスト変数に保存。
Context.PutProperty("nInOutOctetsMonitorPreviousPolledValue", nTotalOctets);
Context.PutProperty("nInOutOctetsMonitorPreviousPollDate", nPollDate);
}

参照

アクティブスクリプトのアクティブモニタの例

プリンタのインクレベルと使用率の監視

温度が範囲外になったときにアラート発信

無効ユーザーアカウントアクティビティの確認

非標準ポートで実行中の SNMP エージェントの監視

不明な MAC アドレスの監視