Skip to content

Commit 4bc389a

Browse files
committed
fix n/a being visible in --alert rates at the beginning of the selected time period
1 parent 141d21c commit 4bc389a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/dbshow.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ int showalert(const char *interface, const AlertOutput output, const AlertExit e
897897
char tablename[6], typeoutput[8], conditionname[16];
898898
char datebuff[DATEBUFFLEN];
899899
ListType listtype = LT_None;
900-
uint64_t bytes = 0, e_rx = 0, e_tx = 0, e_bytes = 0;
900+
uint64_t bytes = 0, e_rx = 0, e_tx = 0, e_bytes = 0, periodseconds = 0;
901901
dbdatalist *datalist = NULL;
902902
dbdatalistinfo datainfo;
903903

@@ -1079,10 +1079,14 @@ int showalert(const char *interface, const AlertOutput output, const AlertExit e
10791079
printf(" percentage | avg. rate\n");
10801080
printf(" ----------+------------------+----------------+--------------\n");
10811081
printf(" used | %16s |", getvalue(bytes, 16, RT_Normal));
1082+
periodseconds = getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, ongoing);
1083+
if (ongoing && periodseconds == 0) {
1084+
periodseconds = getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, 0);
1085+
}
10821086
if (percentage <= 100000.0) {
1083-
printf(" %13.1f%% | %13s\n", percentage, gettrafficrate(bytes, (time_t)getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, ongoing), 13));
1087+
printf(" %13.1f%% | %13s\n", percentage, gettrafficrate(bytes, (time_t)periodseconds, 13));
10841088
} else {
1085-
printf(" %14s | %13s\n", ">100000%", gettrafficrate(bytes, (time_t)getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, ongoing), 13));
1089+
printf(" %14s | %13s\n", ">100000%", gettrafficrate(bytes, (time_t)periodseconds, 13));
10861090
}
10871091
printf(" limit | %16s |", getvalue(limit, 16, RT_Normal));
10881092
printf(" | %13s\n", gettrafficrate(limit, (time_t)getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, 0), 13));
@@ -1105,7 +1109,8 @@ int showalert(const char *interface, const AlertOutput output, const AlertExit e
11051109
if (e_bytes > limit) {
11061110
printf(", +%s\n", getvalue(e_bytes - limit, 0, RT_Normal));
11071111
} else {
1108-
printf(" | %13s\n", gettrafficrate(bytes, (time_t)getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, ongoing), 13));
1112+
/* rate for estimated is always to same as for used so "bytes" intentionally used here instead of "e_bytes" */
1113+
printf(" | %13s\n", gettrafficrate(bytes, (time_t)periodseconds, 13));
11091114
}
11101115
}
11111116
}

0 commit comments

Comments
 (0)