"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/dbshow.c" between
vnstat-2.8.tar.gz and vnstat-2.9.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

dbshow.c  (vnstat-2.8):dbshow.c  (vnstat-2.9)
skipping to change at line 890 skipping to change at line 890
} }
return width; return width;
} }
void indent(int i) void indent(int i)
{ {
if ((cfg.ostyle > 0) && (i > 0)) { if ((cfg.ostyle > 0) && (i > 0)) {
printf("%*s", i, " "); printf("%*s", i, " ");
} }
} }
int showalert(const char *interface, const AlertOutput output, const AlertExit e
xit, const AlertType type, const AlertCondition condition, const uint64_t limit)
{
interfaceinfo ifaceinfo;
int i, l, ret = 0, limitexceeded = 0, estimateexceeded = 0;
short ongoing = 1;
double percentage = 0.0;
char tablename[6], typeoutput[8], conditionname[16];
char datebuff[DATEBUFFLEN];
ListType listtype = LT_None;
uint64_t bytes = 0, e_rx = 0, e_tx = 0, e_bytes = 0, periodseconds = 0;
dbdatalist *datalist = NULL;
dbdatalistinfo datainfo;
timeused_debug(__func__, 1);
if (!db_getinterfaceinfo(interface, &ifaceinfo)) {
return 1;
}
switch (type) {
case AT_None:
return 0;
case AT_Hour:
listtype = LT_Hour;
snprintf(tablename, 6, "hour");
snprintf(typeoutput, 8, "hourly");
break;
case AT_Day:
listtype = LT_Day;
snprintf(tablename, 6, "day");
snprintf(typeoutput, 8, "daily");
break;
case AT_Month:
listtype = LT_Month;
snprintf(tablename, 6, "month");
snprintf(typeoutput, 8, "monthly");
break;
case AT_Year:
listtype = LT_Year;
snprintf(tablename, 6, "year");
snprintf(typeoutput, 8, "yearly");
break;
}
if (!db_getdata(&datalist, &datainfo, interface, tablename, 1)) {
printf("Error: Failed to fetch %s data for interface %s.\n", tabl
ename, interface);
return 1;
}
if (!datalist) {
printf("Error: No %s data available for interface %s.\n", tablena
me, interface);
return 1;
}
switch (condition) {
case AC_None:
break;
case AC_RX:
bytes = datalist->rx;
snprintf(conditionname, 16, "rx");
getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &
datalist);
e_bytes = e_rx;
break;
case AC_TX:
bytes = datalist->tx;
snprintf(conditionname, 16, "tx");
getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &
datalist);
e_bytes = e_tx;
break;
case AC_Total:
bytes = datalist->rx + datalist->tx;
snprintf(conditionname, 16, "total");
getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &
datalist);
e_bytes = e_rx + e_tx;
break;
case AC_RX_Estimate:
ongoing = 0;
getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &
datalist);
bytes = e_rx;
snprintf(conditionname, 16, "rx estimate");
break;
case AC_TX_Estimate:
ongoing = 0;
getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &
datalist);
bytes = e_tx;
snprintf(conditionname, 16, "tx estimate");
break;
case AC_Total_Estimate:
ongoing = 0;
getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &
datalist);
bytes = e_rx + e_tx;
snprintf(conditionname, 16, "total estimate");
break;
}
if (bytes > limit) {
limitexceeded = 1;
}
if (ongoing == 1 && e_bytes > limit) {
estimateexceeded = 1;
}
if (limitexceeded && exit == AE_Exit_1_On_Limit) {
ret = 1;
} else if (estimateexceeded && exit == AE_Exit_1_On_Estimate) {
ret = 1;
}
if (output != AO_No_Output) {
if (output == AO_Always_Output || (output == AO_Output_On_Estimat
e && estimateexceeded) || ((output == AO_Output_On_Limit || output == AO_Output_
On_Estimate) && limitexceeded)) {
if (strlen(ifaceinfo.alias)) {
printf("\n %s (%s)", ifaceinfo.alias, ifaceinfo
.name);
} else {
printf("\n %s", interface);
}
if (ifaceinfo.updated) {
strftime(datebuff, DATEBUFFLEN, DATETIMEFORMAT, l
ocaltime(&ifaceinfo.updated));
printf(" at %s", datebuff);
}
if (datalist->timestamp) {
printf(" for %s ", tablename);
switch (type) {
case AT_None:
break;
case AT_Hour:
strftime(datebuff, DATEBUFFLEN, "
%H", localtime(&datalist->timestamp));
printf("%s of ", datebuff);
strftime(datebuff, DATEBUFFLEN, c
fg.dformat, localtime(&datalist->timestamp));
printf("%s", datebuff);
break;
case AT_Day:
strftime(datebuff, DATEBUFFLEN, c
fg.dformat, localtime(&datalist->timestamp));
printf("%s", datebuff);
break;
case AT_Month:
strftime(datebuff, DATEBUFFLEN, c
fg.mformat, localtime(&datalist->timestamp));
printf("%s", datebuff);
break;
case AT_Year:
strftime(datebuff, DATEBUFFLEN, "
%Y", localtime(&datalist->timestamp));
printf("%s", datebuff);
break;
}
}
printf("\n\n");
}
if ((output == AO_Always_Output || output == AO_Output_On_Limit |
| output == AO_Output_On_Estimate) && limitexceeded) {
printf(" Alert limit exceeded!\n
\n");
} else if (output == AO_Always_Output || (output == AO_Output_On_
Estimate && estimateexceeded)) {
if (estimateexceeded) {
printf(" Warning: Limit will be excee
ded at current rate\n\n");
}
printf(" [");
l = (int)lrint((double)(bytes) / (double)limit * ALERTUSA
GELEN);
if (l > ALERTUSAGELEN) {
l = ALERTUSAGELEN;
}
for (i = 0; i < l; i++) {
printf("=");
}
if (ongoing) {
if (!estimateexceeded) {
l = (int)lrint((double)(e_bytes) / (doubl
e)limit * ALERTUSAGELEN);
for (; i < l; i++) {
printf("-");
}
} else {
for (; i < ALERTUSAGELEN; i++) {
printf("-");
}
}
}
for (; i < ALERTUSAGELEN; i++) {
printf(".");
}
printf("]\n\n");
}
if (output == AO_Always_Output || (output == AO_Output_On_Estimat
e && estimateexceeded) || ((output == AO_Output_On_Limit || output == AO_Output_
On_Estimate) && limitexceeded)) {
printf(" %8s |", typeoutput);
if (ongoing) {
printf(" %9s |", conditionname);
} else {
printf(" %14s |", conditionname);
}
percentage = (double)(bytes) / (double)limit * 100.0;
printf(" percentage | avg. rate\n");
printf(" ----------+------------------+--------------
--+--------------\n");
printf(" used | %16s |", getvalue(bytes, 16, RT_
Normal));
periodseconds = getperiodseconds(listtype, datalist->time
stamp, ifaceinfo.updated, ongoing);
if (ongoing && periodseconds == 0) {
periodseconds = getperiodseconds(listtype, datali
st->timestamp, ifaceinfo.updated, 0);
}
if (percentage <= 100000.0) {
printf(" %13.1f%% | %13s\n", percentage, gettraff
icrate(bytes, (time_t)periodseconds, 13));
} else {
printf(" %14s | %13s\n", ">100000%", gettrafficra
te(bytes, (time_t)periodseconds, 13));
}
printf(" limit | %16s |", getvalue(limit, 16, RT_
Normal));
printf(" | %13s\n", gettrafficrate(limit,
(time_t)getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, 0), 1
3));
if (limitexceeded) {
printf(" excess | %16s | |\
n", getvalue(bytes - limit, 16, RT_Normal));
printf(" ----------+------------------+------
----------+--------------\n");
} else {
printf(" remaining | %16s | %13.1f%% |\n", ge
tvalue(limit - bytes, 16, RT_Normal), 100.0 - percentage);
printf(" ----------+------------------+------
----------+--------------\n");
}
if (ongoing && e_bytes > 0) {
printf(" estimated | %16s |", getvalue(e_byte
s, 16, RT_Normal));
percentage = (double)(e_bytes) / (double)limit *
100.0;
if (percentage <= 100000.0) {
printf(" %13.1f%%", percentage);
} else {
printf(" %14s", ">100000%");
}
if (e_bytes > limit) {
printf(", +%s\n", getvalue(e_bytes - limi
t, 0, RT_Normal));
} else {
/* rate for estimated is always to same a
s for used so "bytes" intentionally used here instead of "e_bytes" */
printf(" | %13s\n", gettrafficrate(bytes,
(time_t)periodseconds, 13));
}
}
}
}
dbdatalistfree(&datalist);
timeused_debug(__func__, 0);
return ret;
}
 End of changes. 1 change blocks. 
0 lines changed or deleted 0 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)