diff --git a/include/ntop_defines.h b/include/ntop_defines.h index 41c812025b..1a6e672961 100644 --- a/include/ntop_defines.h +++ b/include/ntop_defines.h @@ -852,6 +852,7 @@ #define SECOND_SCRIPT_PATH "second.lua" #define MINUTE_SCRIPT_PATH "minute.lua" #define HT_STATE_UPDATE_SCRIPT_PATH "ht_state_update.lua" +#define STATS_UPDATE_SCRIPT_PATH "stats_update.lua" #define THIRTY_SECONDS_SCRIPT_PATH "30sec.lua" #define FIVE_MINUTES_SCRIPT_PATH "5min.lua" #define HOURLY_SCRIPT_PATH "hourly.lua" diff --git a/scripts/callbacks/interface/ht_state_update.lua b/scripts/callbacks/interface/ht_state_update.lua index c0977feec3..c5dd65cc54 100644 --- a/scripts/callbacks/interface/ht_state_update.lua +++ b/scripts/callbacks/interface/ht_state_update.lua @@ -5,7 +5,6 @@ local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path -require "lua_utils" -- Keep it in sync with HT_STATE_UPDATE_SCRIPT_PATH periodicity in PeriodicActivities.cpp -- that is, with the frequency of execution of this script. local HT_STATE_UPDATE_FREQ = 5 diff --git a/scripts/callbacks/interface/stats_update.lua b/scripts/callbacks/interface/stats_update.lua new file mode 100644 index 0000000000..fb789c6821 --- /dev/null +++ b/scripts/callbacks/interface/stats_update.lua @@ -0,0 +1,13 @@ +-- +-- (C) 2013 - ntop.org +-- + +local dirs = ntop.getDirs() +package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path + +-- ######################################################## + +interface.periodicStatsUpdate() + +-- ######################################################## + diff --git a/src/LuaEngine.cpp b/src/LuaEngine.cpp index e8a4aca09c..38492bbdcd 100644 --- a/src/LuaEngine.cpp +++ b/src/LuaEngine.cpp @@ -5866,6 +5866,20 @@ static int ntop_periodic_ht_state_update(lua_State* vm) { /* ****************************************** */ +static int ntop_periodic_stats_update(lua_State* vm) { + NetworkInterface *ntop_interface = getCurrentInterface(vm); + + if(!ntop_interface) + return(CONST_LUA_ERROR); + + ntop_interface->periodicStatsUpdate(); + lua_pushnil(vm); + + return(CONST_LUA_OK); +} + +/* ****************************************** */ + static int ntop_get_interface_stats(lua_State* vm) { NetworkInterface *ntop_interface = getCurrentInterface(vm); bool get_direction_stats = false; @@ -10350,6 +10364,9 @@ static const luaL_Reg ntop_interface_reg[] = { { "getHashTablesStats", ntop_get_interface_hash_tables_stats }, { "periodicHTStateUpdate", ntop_periodic_ht_state_update }, + /* Function for the periodic update of hash tables stats (e.g., throughputs) */ + { "periodicStatsUpdate", ntop_periodic_stats_update }, + #ifndef HAVE_NEDGE { "processFlow", ntop_process_flow }, #endif diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 3ae96fdc9e..2e8049c808 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -2729,6 +2729,9 @@ u_int32_t NetworkInterface::getFlowMaxIdle() { /* **************************************************** */ void NetworkInterface::periodicStatsUpdate() { +#if 0 + ntop->getTrace()->traceEvent(TRACE_NORMAL, "[%s][%s]", __FUNCTION__, get_name()); +#endif u_int32_t begin_slot = 0; periodic_stats_update_user_data_t periodic_stats_update_user_data; struct timeval tv; @@ -5430,16 +5433,6 @@ void NetworkInterface::lua_hash_tables_stats(lua_State *vm) { /* **************************************************** */ void NetworkInterface::runHousekeepingTasks() { - /* NOTE NOTE NOTE - - This task runs asynchronously with respect to ntopng - so if you need to allocate memory you must LOCK - - Example HTTPStats::updateHTTPHostRequest() is called - by both this function and the main thread - */ - - periodicStatsUpdate(); } /* **************************************************** */ diff --git a/src/PeriodicActivities.cpp b/src/PeriodicActivities.cpp index 14ac4405a4..77a99a88c1 100644 --- a/src/PeriodicActivities.cpp +++ b/src/PeriodicActivities.cpp @@ -99,6 +99,7 @@ void PeriodicActivities::startPeriodicActivitiesLoop() { static activity_descr ad[] = { { SECOND_SCRIPT_PATH, 1, false, 1 }, { HT_STATE_UPDATE_SCRIPT_PATH, 5, false, num_threads }, + { STATS_UPDATE_SCRIPT_PATH, 5, false, num_threads }, { MINUTE_SCRIPT_PATH, 60, false, num_threads }, { FIVE_MINUTES_SCRIPT_PATH, 300, false, num_threads }, { HOURLY_SCRIPT_PATH, 3600, false, num_threads },