diff --git a/scripts/lua/modules/timeseries/custom/ts_5min_custom.lua.sample b/scripts/lua/modules/timeseries/custom/ts_5min_custom.lua.sample new file mode 100644 index 0000000000..630903e304 --- /dev/null +++ b/scripts/lua/modules/timeseries/custom/ts_5min_custom.lua.sample @@ -0,0 +1,33 @@ +-- +-- (C) 2019 - ntop.org +-- + +local ts_utils = require "ts_utils_core" + +local ts_custom = {} + +local function setup() + -- SCHEMAS MUST BE ADDED IN THIS FUNCTION + -- + -- This is an example of a 5 minute (300 sec) counter + -- + local schema + + schema = ts_utils.newSchema("host:traffic_total", {step = 300}) + schema:addTag("ifid") + schema:addTag("host") + schema:addMetric("bytes") +end + +function ts_custom.host_update_stats(when, hostname, host, ifstats, verbose) + -- THIS IS THE FUNCTION THAT IS CALLED EVERY 5 MINUTES BY NTOPNG + -- USE THIS TO append() TO THE TIMESERIES + + ts_utils.append("host:traffic_total", + {ifid = ifstats.id, host = hostname, + bytes = host["bytes.sent"] + host["bytes.rcvd"]}, + when, verbose) +end + +setup() +return ts_custom diff --git a/scripts/lua/modules/timeseries/custom/ts_minute_custom.lua.sample b/scripts/lua/modules/timeseries/custom/ts_minute_custom.lua.sample new file mode 100644 index 0000000000..cce62d88a4 --- /dev/null +++ b/scripts/lua/modules/timeseries/custom/ts_minute_custom.lua.sample @@ -0,0 +1,34 @@ +-- +-- (C) 2019 - ntop.org +-- + +local ts_utils = require "ts_utils_core" + +local ts_custom = {} + +local function setup() + -- SCHEMAS MUST BE ADDED IN THIS FUNCTION + -- + -- This is an example of a minute (60 sec) counter + -- + local schema + + schema = ts_utils.newSchema("iface:tcp_seq_errors", {step = 60}) + schema:addTag("ifid") + schema:addMetric("packets") +end + +function ts_custom.iface_update_stats(when, _ifname, ifstats, verbose) + -- THIS IS THE FUNCTION THAT IS CALLED EVERY MINUTE BY NTOPNG + -- USE THIS TO append() TO THE TIMESERIES + + ts_utils.append("iface:tcp_seq_errors", + {ifid = ifstats.id, + packets = ifstats.tcpPacketStats.retransmissions + + ifstats.tcpPacketStats.out_of_order + + ifstats.tcpPacketStats.lost}, + when, verbose) +end + +setup() +return ts_custom diff --git a/scripts/lua/modules/ts_5min_dump_utils.lua b/scripts/lua/modules/ts_5min_dump_utils.lua index 14407ecbd9..2fb623545c 100644 --- a/scripts/lua/modules/ts_5min_dump_utils.lua +++ b/scripts/lua/modules/ts_5min_dump_utils.lua @@ -10,6 +10,12 @@ require "ntop_utils" require "check_redis_prefs" local ts_utils = require "ts_utils_core" +local ts_custom +if ntop.exists(dirs.installdir .. "/scripts/lua/modules/timeseries/custom/ts_5min_custom.lua") then + package.path = dirs.installdir .. "/scripts/lua/modules/timeseries/custom/?.lua;" .. package.path + ts_custom = require "ts_5min_custom" +end + -- Set to true to debug host timeseries points timestamps local enable_debug = false @@ -555,6 +561,11 @@ function ts_dump.host_update_stats_rrds(when, hostname, host, ifstats, verbose) bytes_sent_unicast = host["udpBytesSent.unicast"], bytes_sent_non_uni = host["udpBytesSent.non_unicast"] }, when) + + -- create custom rrds + if ts_custom and ts_custom.host_update_stats then + ts_custom.host_update_stats(when, hostname, host, ifstats, verbose) + end end function ts_dump.host_update_ndpi_rrds(when, hostname, host, ifstats, verbose, config) diff --git a/scripts/lua/modules/ts_min_dump_utils.lua b/scripts/lua/modules/ts_min_dump_utils.lua index fe8f841bba..c61eaceb2d 100644 --- a/scripts/lua/modules/ts_min_dump_utils.lua +++ b/scripts/lua/modules/ts_min_dump_utils.lua @@ -12,6 +12,13 @@ require "ntop_utils" require "ts_minute" require "check_redis_prefs" local ts_utils = require("ts_utils_core") + +local ts_custom +if ntop.exists(dirs.installdir .. "/scripts/lua/modules/timeseries/custom/ts_5min_custom.lua") then + package.path = dirs.installdir .. "/scripts/lua/modules/timeseries/custom/?.lua;" .. package.path + ts_custom = require "ts_5min_custom" +end + local ts_dump = {} -- ######################################################## @@ -586,6 +593,11 @@ function ts_dump.run_min_dump(_ifname, ifstats, when, verbose) ts_dump.iface_update_ndpi_rrds(when, _ifname, ifstats, verbose, config) end + -- create custom rrds + if ts_custom and ts_custom.iface_update_stats then + ts_custom.iface_update_stats(when, _ifname, ifstats, verbose) + end + if config.interface_ndpi_timeseries_creation == "per_category" or config.interface_ndpi_timeseries_creation == "both" then ts_dump.iface_update_categories_rrds(when, _ifname, ifstats, verbose)