diff --git a/include/NetworkInterface.h b/include/NetworkInterface.h index f75a21fc5c..10838cfca5 100644 --- a/include/NetworkInterface.h +++ b/include/NetworkInterface.h @@ -81,7 +81,6 @@ class NetworkInterface : public AlertableEntity { /* Flows queues waiting to be dumped */ SPSCQueue *idleFlowsToDump, *activeFlowsToDump; u_int32_t idleFlowsToDump_drops, activeFlowsToDump_drops; - u_int64_t flowsToDump_total, flowsToDump_enqueued, flowsToDump_nomem; /* Queue containing the ip@vlan strings of the hosts to restore. */ FifoStringsQueue *hosts_to_restore; @@ -676,8 +675,8 @@ class NetworkInterface : public AlertableEntity { #endif void getFlowsStatus(lua_State *vm); - inline void startDBLoop() { if(db) db->startDBLoop(); }; - inline void incDBNumDroppedFlows(u_int num) { if(db) db->incNumDroppedFlows(num); }; + inline void startDBLoop() { if(db) db->startDBLoop(); }; + inline void incDBNumDroppedFlows(u_int num = 1) { if(db) db->incNumDroppedFlows(num); }; #ifdef NTOPNG_PRO inline void getFlowDevices(lua_State *vm) { if(flow_interfaces_stats) flow_interfaces_stats->luaDeviceList(vm); else lua_newtable(vm); diff --git a/src/Flow.cpp b/src/Flow.cpp index 4d33eeed53..5711a1e278 100644 --- a/src/Flow.cpp +++ b/src/Flow.cpp @@ -1741,7 +1741,7 @@ void Flow::dumpCheck(const struct timeval *tv, bool no_time_left, bool last_dump dumped in the next iteration */ - d_if->incDBNumDroppedFlows(1); + d_if->incDBNumDroppedFlows(); } return; } else { diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index feac60421b..2f7115e8f7 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -50,8 +50,6 @@ NetworkInterface::NetworkInterface(const char *name, customIftype = custom_interface_type; influxdb_ts_exporter = rrd_ts_exporter = NULL; idleFlowsToDump_drops = activeFlowsToDump_drops = 0; - flowsToDump_total = flowsToDump_enqueued = 0; - flowsToDump_nomem = 0; #ifdef WIN32 if(name == NULL) name = "1"; /* First available interface */ @@ -643,7 +641,6 @@ int NetworkInterface::dumpFlow(time_t when, Flow *f, bool no_time_left) { idleFlowsToDump->enqueue(f, false); - flowsToDump_enqueued++; #if DEBUG_FLOW_DUMP ntop->getTrace()->traceEvent(TRACE_NORMAL, "[%s] Queueing flow to dump [IDLE]", __FUNCTION__); #endif @@ -660,7 +657,6 @@ int NetworkInterface::dumpFlow(time_t when, Flow *f, bool no_time_left) { activeFlowsToDump->enqueue(f, false); - flowsToDump_enqueued++; #if DEBUG_FLOW_DUMP ntop->getTrace()->traceEvent(TRACE_NORMAL, "[%s] Queueing flow to dump [ACTIVE]", __FUNCTION__); #endif @@ -673,7 +669,7 @@ int NetworkInterface::dumpFlow(time_t when, Flow *f, bool no_time_left) { } else { /* Sychronous dump and not via a thread */ rc = db->dumpFlow(when, f, json); /* Finally dump this flow */ - if(!rc) incDBNumDroppedFlows(1); + if(!rc) incDBNumDroppedFlows(); if(json != NULL) free(json); /* No need to delete the memory as everything @@ -2357,7 +2353,7 @@ void NetworkInterface::dumpFlowLoop() { #if DEBUG_FLOW_DUMP ntop->getTrace()->traceEvent(TRACE_NORMAL, "Dumped idle flow"); #endif - if(!rc) incDBNumDroppedFlows(1); + if(!rc) incDBNumDroppedFlows(); f->decUses(); delete f; n++; @@ -2370,7 +2366,7 @@ void NetworkInterface::dumpFlowLoop() { #if DEBUG_FLOW_DUMP ntop->getTrace()->traceEvent(TRACE_NORMAL, "Dumped active flow"); #endif - if(!rc) incDBNumDroppedFlows(1); + if(!rc) incDBNumDroppedFlows(); f->decUses(); n++; } @@ -2622,26 +2618,6 @@ void NetworkInterface::periodicStatsUpdate() { #endif struct timeval tv = periodicUpdateInitTime(); -#if 0 /* Debug */ - if (db && db->getNumExportedFlows()) { - time_t now = time(NULL); - static time_t start = 0; - - if (start == 0) - start = now; - else - ntop->getTrace()->traceEvent(TRACE_NORMAL, "FLOW DUMP STATS: %ju received %ju no-mem %ju enqueued %ju exported %u drop %u idle-q-drop %u active-q-drop [relative time: %us]", - flowsToDump_total, - flowsToDump_nomem, - flowsToDump_enqueued, - db->getNumExportedFlows(), - db->getNumDroppedFlows(), - idleFlowsToDump_drops, - activeFlowsToDump_drops, - now-start); - } -#endif - if(!checkPeriodicStatsUpdateTime(&tv)) return; /* Not yet the time to perform an update */ diff --git a/src/ParserInterface.cpp b/src/ParserInterface.cpp index 6d12da0517..f2eea28712 100755 --- a/src/ParserInterface.cpp +++ b/src/ParserInterface.cpp @@ -50,8 +50,6 @@ void ParserInterface::processFlow(ParsedFlow *zflow) { now = time(NULL); now_tv.tv_sec = now; - flowsToDump_total++; - // ntop->getTrace()->traceEvent(TRACE_WARNING, "%s()", __FUNCTION__); if(unlikely(ntop->getPrefs()->get_num_simulated_ips())) { @@ -170,7 +168,20 @@ void ParserInterface::processFlow(ParsedFlow *zflow) { PROFILING_SECTION_EXIT(0); if(flow == NULL) { - flowsToDump_nomem++; + +#ifdef NTOPNG_PRO + /* Update drop stats in case of direct flow dump */ + if(ntop->getPrefs()->do_dump_flows_direct() && ( + ntop->getPrefs()->is_flows_dump_enabled() +#ifndef HAVE_NEDGE + || ntop->get_export_interface() +#endif + )) { + NetworkInterface *d_if = isViewed() ? viewedBy() : static_cast(this); + d_if->incDBNumDroppedFlows(); + } +#endif + return; } @@ -440,20 +451,23 @@ void ParserInterface::processFlow(ParsedFlow *zflow) { zflow->pkt_sampling_rate*(zflow->in_pkts + zflow->out_pkts)); #ifdef NTOPNG_PRO - if((ntop->getPrefs()->is_flows_dump_enabled() + /* Check if direct flow dump is enabled */ + if(ntop->getPrefs()->do_dump_flows_direct() && ( + ntop->getPrefs()->is_flows_dump_enabled() #ifndef HAVE_NEDGE - || ntop->get_export_interface() + || ntop->get_export_interface() #endif - ) - && ntop->getPrefs()->do_dump_flows_direct()) { + )) { NetworkInterface *d_if = isViewed() ? viewedBy() : static_cast(this); struct timeval tv; bool rc; + /* Dump flow */ tv.tv_sec = zflow->last_switched, tv.tv_usec = 0; - rc = flow->dumpFlow(&tv, d_if, false /* no_time_left */, true); - if(!rc) d_if->incDBNumDroppedFlows(1); + + /* Update drop stats */ + if(!rc) d_if->incDBNumDroppedFlows(); } #endif