##### TODO
* `grep TODO src/* tests/*`
- * rewrite version 1.18 feature which didn't merge properly
- * output of 5 minute resolution statistics (vnstat and vnstati)
+ * output of 5 minute resolution statistics (vnstati)
* possibly not included in first 2.x release
* query of specific time range date
* most likely not included in first 2.x release
* extending the length of the current outputs is however already supported
- * hourly output is the only exception
* feature configurability
* freeze database structure
* plan ahead and figure out how to migrate data to new structure if necessary?
case 9:
showoneline(&info);
break;
+ case 11:
+ showlist(&info, "hour");
+ break;
+ case 12:
+ showlist(&info, "fiveminute");
+ break;
default:
printf("Error: Not such query mode: %d\n", qmode);
break;
int32_t limit;
int listtype, offset = 0, i = 1;
struct tm *d;
- char datebuff[DATEBUFFLEN], titlename[16], colname[8], stampformat[64];
+ char datebuff[DATEBUFFLEN], daybuff[DATEBUFFLEN];
+ char titlename[16], colname[8], stampformat[64];
uint64_t e_rx, e_tx, e_secs, div, mult;
dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo;
strncpy_nt(stampformat, cfg.tformat, 64);
limit = cfg.listtop;
offset = 6;
+ } else if (strcmp(listname, "hour") == 0) {
+ listtype = 5;
+ strncpy_nt(colname, listname, 8);
+ snprintf(titlename, 16, "hourly");
+ strncpy_nt(stampformat, "%H:%M", 64);
+ limit = cfg.listhours;
+ } else if (strcmp(listname, "fiveminute") == 0) {
+ listtype = 6;
+ strncpy_nt(colname, "time", 8);
+ snprintf(titlename, 16, "5 minute");
+ strncpy_nt(stampformat, "%H:%M", 64);
+ limit = cfg.listfivemins;
} else {
return;
}
limit = 0;
}
+ daybuff[0] = '\0';
e_rx = e_tx = e_secs = 0;
if (!db_getdata(&datalist, &datainfo, interface->name, listname, (uint32_t)limit)) {
while (datalist_i != NULL) {
d = localtime(&datalist_i->timestamp);
+
+ if (listtype == 5 || listtype == 6) {
+ strftime(datebuff, DATEBUFFLEN, cfg.dformat, d);
+ if (strcmp(daybuff, datebuff) != 0) {
+ if (cfg.ostyle == 3) {
+ indent(4);
+ }
+ printf(" %s\n", datebuff);
+ strcpy(daybuff, datebuff);
+ }
+ }
+
strftime(datebuff, DATEBUFFLEN, stampformat, d);
if (cfg.ostyle == 3) {
indent(1);
e_secs = (uint64_t)(d->tm_yday*86400+d->tm_sec+(d->tm_min*60)+(d->tm_hour*3600));
} else if (listtype == 4) { // top
e_secs = 86400;
+ } else if (listtype == 5) { // hour
+ e_secs = (uint64_t)(d->tm_sec+(d->tm_min*60));
+ } else if (listtype == 6) { // 5min
+ e_secs = 300;
}
} else {
if (listtype == 1 || listtype == 4) { // day
e_secs = (uint64_t)(dmonth(d->tm_mon) * 86400);
} else if (listtype == 3) { // year
e_secs = (uint64_t)((365 + isleapyear(d->tm_year+1900)) * 86400);
+ } else if (listtype == 5) { // hour
+ e_secs = 3600;
+ } else if (listtype == 6) { // 5min
+ e_secs = 300;
}
}
printf(" | %s", gettrafficrate(datalist_i->rx+datalist_i->tx, (time_t)e_secs, 14));
}
printf("\n");
}
- if (datainfo.count > 0 && listtype != 4) {
+ if (datainfo.count > 0 && listtype < 4) {
/* use database update time for estimates */
d = localtime(&interface->updated);
if ( datalist_i->rx==0 || datalist_i->tx==0 ) {
int i, l, width = len;
if ( (rx + tx) < max) {
- width = (int)( (rx + tx) / (float)max ) * len;
+ width = (int)( ((rx + tx) / (float)max) * len );
} else if ((rx + tx) > max) {
return 0;
}
}
} else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours")==0)) {
cfg.qmode=7;
+ } else if ((strcmp(argv[currentarg],"-hl")==0) || (strcmp(argv[currentarg],"--hourslist")==0)) {
+ cfg.qmode=11;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listhours = atoi(argv[currentarg+1]);
+ if (cfg.listhours < 0) {
+ printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+ return 1;
+ }
+ currentarg++;
+ }
+ } else if ((strcmp(argv[currentarg],"-5")==0) || (strcmp(argv[currentarg],"--fiveminutes")==0)) {
+ cfg.qmode=12;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listfivemins = atoi(argv[currentarg+1]);
+ if (cfg.listfivemins < 0) {
+ printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg+1], argv[currentarg]);
+ return 1;
+ }
+ currentarg++;
+ }
} else if ((strcmp(argv[currentarg],"--exportdb")==0) || (strcmp(argv[currentarg],"--dumpdb")==0)) {
cfg.qmode=4;
} else if (strcmp(argv[currentarg],"--oneline")==0) {
printf(" vnStat %s by Teemu Toivola <tst at iki dot fi>\n\n", getversion());
printf(" -q, --query query database\n");
+ printf(" -5, --fiveminutes show 5 minutes\n");
printf(" -h, --hours show hours\n");
+ printf(" -hl, --hourslist show hours list\n");
printf(" -d, --days show days\n");
printf(" -m, --months show months\n");
printf(" -y, --years show years\n");
printf(" Query:\n");
printf(" -q, --query query database\n");
- printf(" -h, --hours show hours\n");
+ printf(" -5, --fiveminutes show 5 minutes\n");
+ printf(" -h, --hours show hours\n");
+ printf(" -hl, --hourslist show hours list\n");
printf(" -d, --days show days\n");
printf(" -m, --months show months\n");
printf(" -y, --years show years\n");
showdb("something", 7);
showdb("something", 8);
showdb("something", 9);
+ showdb("something", 10);
+ showdb("something", 11);
+ showdb("something", 12);
xmlheader();
showxml("something", 'd');
showdb("something", 7);
showdb("something", 8);
showdb("something", 9);
+ showdb("something", 10);
+ showdb("something", 11);
+ showdb("something", 12);
xmlheader();
showxml("something", 'd');
}
END_TEST
+START_TEST(showbar_with_half_and_half_of_half)
+{
+ int pipe, len;
+ char buffer[512];
+ memset(&buffer, '\0', sizeof(buffer));
+
+ defaultcfg();
+ cfg.rxchar[0] = 'r';
+ cfg.txchar[0] = 't';
+ pipe = pipe_output();
+ len = showbar(1, 1, 4, 12);
+ ck_assert_int_eq(len, 6);
+ fflush(stdout);
+
+ len = (int)read(pipe, buffer, 512);
+ ck_assert_str_eq(buffer, " rrrttt");
+}
+END_TEST
+
void add_database_tests(Suite *s)
{
TCase *tc_db = tcase_create("Database");
tcase_add_test(tc_db, showbar_with_one_tenth);
tcase_add_test(tc_db, showbar_with_small_rx_shows_all_tx);
tcase_add_test(tc_db, showbar_with_max_smaller_than_real_max);
+ tcase_add_test(tc_db, showbar_with_half_and_half_of_half);
suite_add_tcase(s, tc_db);
}