mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Simplifies widgets backend
This commit is contained in:
parent
debf0c412b
commit
3659188002
5 changed files with 133 additions and 67 deletions
|
|
@ -5,46 +5,33 @@
|
|||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/datamodel/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/rest/v1/get/datasource/?.lua;" .. package.path
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Import the base class
|
||||
local datasource = require "datasource"
|
||||
-- Import the datasource keys
|
||||
local datasource_keys = require "datasource_keys"
|
||||
-- This is the datamodel used to represent data associated with this datasource
|
||||
local datamodel = require "slices"
|
||||
local slices = require "slices"
|
||||
-- Rest utilities
|
||||
local rest_utils = require "rest_utils"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local packet_distro = classes.class(datasource)
|
||||
local packet_distro = classes.class(slices)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
packet_distro.meta = {
|
||||
datasource_key = datasource_keys.interface_packet_distro, -- Uniquely identifies this datasource
|
||||
i18n_title = "Interface Packet Distribution",
|
||||
icon = "fas fa-exclamation",
|
||||
datamodel = datamodel,
|
||||
params = {
|
||||
"ifid" -- validated according to http_lint.lua
|
||||
-- NOTE: Specify all the parameter keys that must be passed in the request
|
||||
"ifid" -- validated according to http_lint.lua
|
||||
},
|
||||
-- A URL possibly formatted with parsed_params sent via REST
|
||||
url = "/lua/if_stats.lua?ifid={{ params.ifid }}&page=packets",
|
||||
-- Possibly add placeholders to replace keys and values, e.g.,
|
||||
-- k is the `k` in the response data, v is the `v` in the response data
|
||||
-- url = "/lua/if_stats.lua?ifid={{ params.ifid }}&page=packets&key=__k__&value=__v__",
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- Human-friendly labels for the distribution
|
||||
packet_distro.slices = {
|
||||
local available_bins = {
|
||||
{ key = 'upTo64', label = '<= 64' },
|
||||
{ key = 'upTo128', label = '64 <= 128' },
|
||||
{ key = 'upTo256', label = '128 <= 256' },
|
||||
|
|
@ -61,10 +48,9 @@ packet_distro.slices = {
|
|||
|
||||
-- @brief Datasource constructor
|
||||
function packet_distro:init()
|
||||
-- Call the parent constructor
|
||||
self.super:init()
|
||||
|
||||
self.datasource_key_str = datasource_keys[datasource.ds_type]
|
||||
-- Initializes parent class slices
|
||||
self.super:init(10 --[[ Maximum number of slices ]],
|
||||
3 --[[ Percentage under which the slice is ignored and added to other --]])
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
|
@ -77,13 +63,9 @@ function packet_distro:fetch()
|
|||
local ifstats = interface.getStats()
|
||||
local size_bins = ifstats["pktSizeDistribution"]["size"]
|
||||
|
||||
self.datamodel_instance = self.meta.datamodel.new(
|
||||
getHumanReadableInterfaceName(getInterfaceName(ifstats.id)),
|
||||
10 --[[ Maximum number of slices ]],
|
||||
3 --[[ Percentage under which the slice is ignored and added to other --]])
|
||||
|
||||
for _, slice in ipairs(packet_distro.slices) do
|
||||
self.datamodel_instance:append(slice.label, size_bins[slice.key] or 0)
|
||||
self:set_label(getHumanReadableInterfaceName(getInterfaceName(ifstats.id)))
|
||||
for _, bin in ipairs(available_bins) do
|
||||
self:append(bin.label, size_bins[bin.key] or 0)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue