ntop ntopngユーザースクリプト インターフェイススループット

現在まで、ntop社のntopngユーザースクリプトを2個紹介してきました。

基本やり方は一緒ですので、説明とデバック方法は省いて、今回のユーザースクリプトの紹介をします。

インターフェイスのスループットアラートです。

図1 スループットアラート

設定では、一分ごとにインターフェースのスループットをチェックして、100Mbpsを超えている場合アラートを発報します。

/usr/share/ntopng/scripts/plugins/threshold_cross/user_scripts/interface/throughput.luaが、スクリプト本体です。

Mbpsの計算にバグがあったので、修正しております。

修正したluaスクリプトは、以下のとおりです。

--
-- (C) 2019-20 - ntop.org
--

local alerts_api = require("alerts_api")
local alert_consts = require("alert_consts")
local user_scripts = require("user_scripts")

local script = {
  -- Script category
  category = user_scripts.script_categories.network,

  default_enabled = false,

  -- This script is only for alerts generation
  is_alert = true,

  -- See below
  hooks = {},

  gui = {
    i18n_title = "alerts_thresholds_config.throughput",
    i18n_description = "alerts_thresholds_config.alert_throughput_description",
    i18n_field_unit = user_scripts.field_units.mbits,
    input_builder = "threshold_cross",
  }
}

-- #################################################################

function script.hooks.all(params)
  local value = alerts_api.interface_delta_val(script.key, params.granularity, params.entity_info["stats"]["bytes"]) * 8 / 1024 / 1024 / alert_consts.granularity2sec(params.granularity)

  -- Check if the configured threshold is crossed by the value and possibly trigger an alert
  alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
end

-- #################################################################

return script

追加したのは、/ 1024 / 1024  の部分です。こちらで、Mbpsにしております。

今回は、ntopngでiperf3サーバーを起動し、Windows側でクライアントを実行し、200Mbps帯域を占有するように実行しました。

図2 apu4サーバー側iperf3

図3 iperf3クライアント実行

iperf3クライアント実行後、1分間隔のチェックにあたれば図4のアラートが表示されます。

図4 インターフェイススループットアラート発生

200Mbpsになっていますね。修正したluaはここでデバックできます。

このインターフェイススループットアラートは、監視対象ポートのミラーポートをntopngに接続している場合、トラフィック過負荷を監視し、異常時に素早いアクションを起こすことに使えるユーザースクリプトですね。

(Visited 384 times, 1 visits today)
The following two tabs change content below.
【好きなもの】 インフラ技術が好き。古いものが好き。 【生きてきたフィールド】 システム運用、ソフトウェア開発、ミドルウェア検証、OSSサポート、プリセールスエンジニア、プロジェクトマネジメント 【このサイトでの役割】 サイト管理者。