diff --git a/doc/json_schema.json b/doc/json_schema.json index ef6bc41b1..a22deae4b 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1410,6 +1410,11 @@ "type": "boolean", "default": true }, + "detectTotal": { + "description": "Detect total bytes instead of current rate", + "type": "boolean", + "default": false + }, "key": { "$ref": "#/$defs/key" }, diff --git a/src/data/help.json b/src/data/help.json index 5ddcedb89..23b701a80 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1255,6 +1255,14 @@ "default": true } }, + { + "long": "netio-detect-total", + "desc": "Detect total bytes instead of current rate", + "arg": { + "type": "bool", + "default": false + } + }, { "long": "publicip-timeout", "desc": "Time in milliseconds to wait for the public ip server to respond", diff --git a/src/detection/netio/netio.c b/src/detection/netio/netio.c index 5a07af8e2..f72ecb452 100644 --- a/src/detection/netio/netio.c +++ b/src/detection/netio/netio.c @@ -9,6 +9,8 @@ static uint64_t time1; void ffPrepareNetIO(FFNetIOOptions* options) { + if (options->detectTotal) return; + ffListInit(&ioCounters1, sizeof(FFNetIOResult)); ffNetIOGetIoCounters(&ioCounters1, options); time1 = ffTimeGetNow(); @@ -17,6 +19,15 @@ void ffPrepareNetIO(FFNetIOOptions* options) const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options) { const char* error = NULL; + + if (options->detectTotal) + { + error = ffNetIOGetIoCounters(result, options); + if (error) + return error; + return NULL; + } + if (time1 == 0) { ffListInit(&ioCounters1, sizeof(FFNetIOResult)); diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index be3db91a1..11e584196 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -60,10 +60,14 @@ void ffPrintNetIO(FFNetIOOptions* options) ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); ffParseSize(inf->rxBytes, &buffer); - ffStrbufAppendS(&buffer, "/s (IN) - "); + if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s"); + ffStrbufAppendS(&buffer, " (IN) - "); + ffParseSize(inf->txBytes, &buffer); - ffStrbufAppendS(&buffer, "/s (OUT)"); - if (!options->defaultRouteOnly && inf->defaultRoute) + if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s"); + ffStrbufAppendS(&buffer, " (OUT)"); + + if (inf->defaultRoute) ffStrbufAppendS(&buffer, " *"); ffStrbufPutTo(&buffer, stdout); } @@ -71,9 +75,9 @@ void ffPrintNetIO(FFNetIOOptions* options) { ffStrbufClear(&buffer2); ffParseSize(inf->rxBytes, &buffer); - ffStrbufAppendS(&buffer, "/s"); + if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s"); ffParseSize(inf->txBytes, &buffer2); - ffStrbufAppendS(&buffer2, "/s"); + if (!options->detectTotal) ffStrbufAppendS(&buffer2, "/s"); ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETIO_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &buffer}, @@ -118,6 +122,12 @@ bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const return true; } + if (ffStrEqualsIgnCase(subKey, "detect-total")) + { + options->detectTotal = ffOptionParseBoolean(value); + return true; + } + return false; } @@ -146,6 +156,12 @@ void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "detectTotal")) + { + options->detectTotal = yyjson_get_bool(val); + continue; + } + ffPrintError(FF_NETIO_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } @@ -162,6 +178,9 @@ void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj if (options->defaultRouteOnly != defaultOptions.defaultRouteOnly) yyjson_mut_obj_add_bool(doc, module, "defaultRouteOnly", options->defaultRouteOnly); + + if (options->detectTotal != defaultOptions.detectTotal) + yyjson_mut_obj_add_bool(doc, module, "detectTotal", options->detectTotal); } void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -200,18 +219,18 @@ void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj void ffPrintNetIOHelpFormat(void) { ffPrintModuleFormatHelp(FF_NETIO_MODULE_NAME, "{1} (IN) - {2} (OUT)", FF_NETIO_NUM_FORMAT_ARGS, (const char* []) { - "Size of data received per second (formatted)", - "Size of data sent per second (formatted)", + "Size of data received [per second] (formatted)", + "Size of data sent [per second] (formatted)", "Interface name", "Is default route", - "Size of data received per second (in bytes)", - "Size of data sent per second (in bytes)", - "Number of packets received per second", - "Number of packets sent per second", - "Number of errors received per second", - "Number of errors sent per second", - "Number of packets dropped when receiving per second", - "Number of packets dropped when sending per second", + "Size of data received [per second] (in bytes)", + "Size of data sent [per second] (in bytes)", + "Number of packets received [per second]", + "Number of packets sent [per second]", + "Number of errors received [per second]", + "Number of errors sent [per second]", + "Number of packets dropped when receiving [per second]", + "Number of packets dropped when sending [per second]", }); } diff --git a/src/modules/netio/option.h b/src/modules/netio/option.h index 62b493d29..3cd0ad5fb 100644 --- a/src/modules/netio/option.h +++ b/src/modules/netio/option.h @@ -11,4 +11,5 @@ typedef struct FFNetIOOptions FFstrbuf namePrefix; bool defaultRouteOnly; + bool detectTotal; } FFNetIOOptions;