mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Add interfaces stats api and refactor the others health api. (#7141)
This commit is contained in:
parent
193927107e
commit
ba9bfd3d1a
9 changed files with 205 additions and 49 deletions
25
scripts/lua/rest/v2/get/system/health/influxdb.lua
Normal file
25
scripts/lua/rest/v2/get/system/health/influxdb.lua
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
--
|
||||
-- (C) 2021 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local ts_utils = require("ts_utils")
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
local influxdb = ts_utils.getQueryDriver()
|
||||
local info = {}
|
||||
|
||||
if influxdb.getInfluxdbVersion then
|
||||
info.version = influxdb:getInfluxdbVersion()
|
||||
info.db_bytes = influxdb:getDiskUsage()
|
||||
info.memory = influxdb:getMemoryUsage()
|
||||
info.num_series = influxdb:getSeriesCardinality()
|
||||
info.points_exported = influxdb:get_exported_points()
|
||||
info.exports = influxdb:get_exports()
|
||||
info.health = influxdb:get_health()
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, info)
|
||||
77
scripts/lua/rest/v2/get/system/health/interfaces.lua
Normal file
77
scripts/lua/rest/v2/get/system/health/interfaces.lua
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
--
|
||||
-- (C) 2013-23 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
-- ##############################################
|
||||
-- # Requirements #
|
||||
-- ##############################################
|
||||
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
-- ##############################################
|
||||
|
||||
--
|
||||
-- Return interfaces informations
|
||||
-- Example: curl -u admin:admin http://localhost:3000/lua/rest/v2/get/system/health/interfaces_stats.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
-- # Functions #
|
||||
-- ##############################################
|
||||
|
||||
-- Gets the interfaces informations
|
||||
|
||||
local function get_interfaces_info()
|
||||
local interfaces_info = {}
|
||||
|
||||
for _,iface in pairs(interface.getIfNames()) do
|
||||
interface.select(iface)
|
||||
local ifstats = interface.getStats()
|
||||
|
||||
if ifstats then
|
||||
|
||||
local since_reset_drops = ifstats.stats_since_reset.drops
|
||||
local since_reset_packets = ifstats.stats_since_reset.packets
|
||||
local drops_pct = 0
|
||||
|
||||
if (since_reset_drops > 0 or since_reset_packets > 0) then
|
||||
drops_pct = round(since_reset_drops / (since_reset_drops + since_reset_packets) * 100, 2)
|
||||
end
|
||||
|
||||
local item = {
|
||||
engaged_alerts = ifstats.num_alerts_engaged,
|
||||
alerted_flows = ifstats.num_alerted_flows,
|
||||
local_hosts = ifstats.stats.local_host,
|
||||
remote_hosts = ifstats.stats.hosts - ifstats.stats.local_hosts,
|
||||
devices = ifstats.stats.devices,
|
||||
flows = ifstats.stats.flows,
|
||||
total_traffic = ifstats.stats_since_reset.bytes,
|
||||
total_packets = since_reset_packets,
|
||||
dropped_packets = drops_pct
|
||||
}
|
||||
interfaces_info[iface] = item
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return interfaces_info
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- Retrieves the REST API response
|
||||
|
||||
local function build_response()
|
||||
local interfaces_info = get_interfaces_info()
|
||||
rest_utils.answer(rest_utils.consts.success.ok,{interfaces_stats = interfaces_info})
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
build_response()
|
||||
|
||||
13
scripts/lua/rest/v2/get/system/health/redis.lua
Normal file
13
scripts/lua/rest/v2/get/system/health/redis.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
--
|
||||
-- (C) 2019-22 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
local redis_api = require "redis_api"
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
local stats = redis_api.getStats()
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, stats)
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
-- (C) 2013-23 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
|
@ -28,4 +28,9 @@ local res = cpu_utils.systemHostStats()
|
|||
res.epoch = os.time()
|
||||
res.storage = storage_utils.storageInfo()
|
||||
|
||||
local info = ntop.getInfo()
|
||||
if(info.pid ~= nil) then
|
||||
res.pid = info.pid
|
||||
end
|
||||
|
||||
rest_utils.answer(rc, res)
|
||||
Loading…
Add table
Add a link
Reference in a new issue