diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2024-11-09 14:13:57 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2024-11-14 14:33:27 +0100 |
commit | bd269c9ead187c026094cf7eee9d9c292416e309 (patch) | |
tree | 56eaca39195678e9e0e2ba4873dfa109fedeb463 /examples | |
parent | 7e4c69635ae2ed6f073e4b4b3b67f3c31c554813 (diff) |
Added global stats diff test
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/c-analysed/c-analysed.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/examples/c-analysed/c-analysed.c b/examples/c-analysed/c-analysed.c index f1a0cf982..6df460910 100644 --- a/examples/c-analysed/c-analysed.c +++ b/examples/c-analysed/c-analysed.c @@ -207,7 +207,7 @@ static struct nDPIsrvd_ull flow_risk_count[NDPI_MAX_RISK - 1 /* NDPI_NO_RISK */]; nDPIsrvd_ull flow_risk_unknown_count; - } gauges[2]; /* values after InfluxDB push: gauges[0] -= gauges[1], gauges[1] is zero'd afterwards */ + } gauges[2]; /* values after CSV write: gauges[0] -= gauges[1], gauges[1] is zero'd afterwards */ } analysed_statistics = {}; struct global_map @@ -1553,9 +1553,13 @@ static int parse_options(int argc, char ** argv) if (str_value_to_ull(analysed_interval, &analysed_interval_ull) != CONVERSION_OK) { - logger_early(1, "InfluxDB push interval `%s' is not a valid number", analysed_interval); + logger_early(1, "Global Stats CSV write interval `%s' is not a valid number", analysed_interval); return 1; } + if (analysed_interval_ull == 0) + { + logger_early(0, "%s", "Global Stats CSV write interval is zero, summarizing stats during termination"); + } } if (optind < argc) @@ -1570,6 +1574,11 @@ static int parse_options(int argc, char ** argv) static int set_analysed_timer(void) { + if (analysed_interval_ull == 0) + { + return 0; + } + const time_t interval = analysed_interval_ull * 1000; struct itimerspec its; its.it_value.tv_sec = interval / 1000; @@ -1814,7 +1823,7 @@ static int write_global_flow_stats(void) buf[-1] = '\n'; struct timeval tval; - if (gettimeofday(&tval, NULL) == 0) + if (analysed_interval_ull != 0 && gettimeofday(&tval, NULL) == 0) { unsigned long long int sec = tval.tv_sec; unsigned long long int usec = tval.tv_usec; @@ -2112,6 +2121,13 @@ int main(int argc, char ** argv) logger(0, "%s", "Initialization succeeded."); retval = mainloop(epollfd, distributor); + if (analysed_interval_ull == 0) + { + if (write_global_flow_stats() != 0) + { + logger(1, "%s", "Could not write global/flow stats on termination."); + } + } failure: nDPIsrvd_socket_free(&distributor); daemonize_shutdown(pidfile); |