mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-05 10:41:34 +00:00
Added granularity to AlertableEntity
This commit is contained in:
parent
8ad9e6b336
commit
3e223849ba
9 changed files with 164 additions and 92 deletions
|
|
@ -6,21 +6,20 @@ local check = {}
|
|||
|
||||
-- #################################################################
|
||||
|
||||
local function cached_val_key(metric_name, granularity)
|
||||
return string.format("%s:%s", metric_name, granularity)
|
||||
local function cached_val_key(metric_name, granularity_num)
|
||||
return string.format("%s:%s", metric_name, granularity_num)
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
local function delta_val(metric_name, granularity, curr_val)
|
||||
local key = cached_val_key(metric_name, granularity)
|
||||
local function delta_val(metric_name, granularity_num, curr_val)
|
||||
local key = cached_val_key(metric_name, granularity_num)
|
||||
|
||||
-- Read cached value and purify it
|
||||
local prev_val = host.getCachedAlertValue(key)
|
||||
local prev_val = host.getCachedAlertValue(key, granularity_num)
|
||||
prev_val = tonumber(prev_val) or 0
|
||||
|
||||
-- Save the value for the next round
|
||||
host.setCachedAlertValue(key, tostring(curr_val))
|
||||
host.setCachedAlertValue(key, tostring(curr_val), granularity_num)
|
||||
|
||||
-- Compute the delta
|
||||
return curr_val - prev_val
|
||||
|
|
@ -40,54 +39,54 @@ end
|
|||
|
||||
-- #################################################################
|
||||
|
||||
function check.active(metric_name, info, granularity)
|
||||
return delta_val(metric_name, granularity, info["total_activity_time"])
|
||||
function check.active(metric_name, info, granularity, granularity_num)
|
||||
return delta_val(metric_name, granularity_num, info["total_activity_time"])
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.bytes(metric_name, info, granularity)
|
||||
return delta_val(metric_name, granularity, info["bytes.sent"] + info["bytes.rcvd"])
|
||||
function check.bytes(metric_name, info, granularity, granularity_num)
|
||||
return delta_val(metric_name, granularity_num, info["bytes.sent"] + info["bytes.rcvd"])
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.packets(metric_name, info, granularity)
|
||||
return delta_val(metric_name, granularity, info["packets.sent"] + info["packets.rcvd"])
|
||||
function check.packets(metric_name, info, granularity, granularity_num)
|
||||
return delta_val(metric_name, granularity_num, info["packets.sent"] + info["packets.rcvd"])
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.flows(metric_name, info, granularity)
|
||||
return delta_val(metric_name, granularity, info["total_flows.as_client"] + info["total_flows.as_server"])
|
||||
function check.flows(metric_name, info, granularity, granularity_num)
|
||||
return delta_val(metric_name, granularity_num, info["total_flows.as_client"] + info["total_flows.as_server"])
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.idle(metric_name, info, granularity)
|
||||
return delta_val(metric_name, granularity, os.time() - info["seen.last"])
|
||||
function check.idle(metric_name, info, granularity, granularity_num)
|
||||
return delta_val(metric_name, granularity_num, os.time() - info["seen.last"])
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.dns(metric_name, info, granularity)
|
||||
return delta_val(metric_name, granularity, application_bytes(info, "DNS"))
|
||||
function check.dns(metric_name, info, granularity, granularity_num)
|
||||
return delta_val(metric_name, granularity_num, application_bytes(info, "DNS"))
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.p2p(metric_name, info, granularity)
|
||||
function check.p2p(metric_name, info, granularity, granularity_num)
|
||||
local tot_p2p = application_bytes(info, "eDonkey") + application_bytes(info, "BitTorrent") + application_bytes(info, "Skype")
|
||||
|
||||
return delta_val(metric_name, granularity, tot_p2p)
|
||||
return delta_val(metric_name, granularity_num, tot_p2p)
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function check.throughput(metric_name, info, granularity)
|
||||
local duration = granularity2sec(granularity)
|
||||
function check.throughput(metric_name, info, granularity, granularity_num)
|
||||
local duration = granularity_num2sec(granularity_num)
|
||||
|
||||
return delta_val(metric_name, granularity, info["bytes.sent"] + info["bytes.rcvd"]) * 8 / duration
|
||||
return delta_val(metric_name, granularity_num, info["bytes.sent"] + info["bytes.rcvd"]) * 8 / duration
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue