# log days without traffic to daily list (1 = enabled, 0 = disabled)
TrafficlessDays 1
-# data retention durations (-1 = unlimited, 0 = log disabled)
+# default list output entry count (0 = all)
+List5Mins 24
+ListHours 24
+ListDays 30
+ListMonths 12
+ListYears 0
+ListTop 10
+
+# data retention durations (-1 = unlimited, 0 = feature disabled)
5MinuteHours 48
HourlyDays 2
DailyDays 30
printf("# log days without traffic to daily list (1 = enabled, 0 = disabled)\n");
printf("TrafficlessDays %d\n\n", cfg.traflessday);
- printf("# data retention durations (-1 = unlimited, 0 = log disabled)\n");
+ printf("# default list output entry count (0 = all)\n");
+ printf("List5Mins %2d\n", cfg.listfivemins);
+ printf("ListHours %2d\n", cfg.listhours);
+ printf("ListDays %2d\n", cfg.listdays);
+ printf("ListMonths %2d\n", cfg.listmonths);
+ printf("ListYears %2d\n", cfg.listyears);
+ printf("ListTop %2d\n\n", cfg.listtop);
+
+ printf("# data retention durations (-1 = unlimited, 0 = feature disabled)\n");
printf("5MinuteHours %2d\n", cfg.fiveminutehours);
printf("HourlyDays %2d\n", cfg.hourlydays);
printf("DailyDays %2d\n", cfg.dailydays);
{ "UseFileLocking", 0, &cfg.flock, 0, 0 },
{ "BootVariation", 0, &cfg.bvar, 0, 0 },
{ "TrafficlessDays", 0, &cfg.traflessday, 0, 0 },
+ { "List5Mins", 0, &cfg.listfivemins, 0, 0 },
+ { "ListHours", 0, &cfg.listhours, 0, 0 },
+ { "ListDays", 0, &cfg.listdays, 0, 0 },
+ { "ListMonths", 0, &cfg.listmonths, 0, 0 },
+ { "ListYears", 0, &cfg.listyears, 0, 0 },
+ { "ListTop", 0, &cfg.listtop, 0, 0 },
{ "5MinuteHours", 0, &cfg.fiveminutehours, 0, 0 },
{ "HourlyDays", 0, &cfg.hourlydays, 0, 0 },
{ "DailyDays", 0, &cfg.dailydays, 0, 0 },
printe(PT_Config);
}
+ if (cfg.listfivemins<0) {
+ cfg.listfivemins = LISTFIVEMINS;
+ snprintf(errorstring, 512, "%s List5Mins, %s \"%d\".", invalidvalue, resettingto, cfg.listfivemins);
+ printe(PT_Config);
+ }
+
+ if (cfg.listhours<0) {
+ cfg.listhours = LISTHOURS;
+ snprintf(errorstring, 512, "%s ListHours, %s \"%d\".", invalidvalue, resettingto, cfg.listhours);
+ printe(PT_Config);
+ }
+
+ if (cfg.listdays<0) {
+ cfg.listdays = LISTDAYS;
+ snprintf(errorstring, 512, "%s ListDays, %s \"%d\".", invalidvalue, resettingto, cfg.listdays);
+ printe(PT_Config);
+ }
+
+ if (cfg.listmonths<0) {
+ cfg.listmonths = LISTMONTHS;
+ snprintf(errorstring, 512, "%s ListMonths, %s \"%d\".", invalidvalue, resettingto, cfg.listmonths);
+ printe(PT_Config);
+ }
+
+ if (cfg.listyears<0) {
+ cfg.listyears = LISTYEARS;
+ snprintf(errorstring, 512, "%s ListYears, %s \"%d\".", invalidvalue, resettingto, cfg.listyears);
+ printe(PT_Config);
+ }
+
+ if (cfg.listtop<0) {
+ cfg.listtop = LISTTOP;
+ snprintf(errorstring, 512, "%s ListTop, %s \"%d\".", invalidvalue, resettingto, cfg.listtop);
+ printe(PT_Config);
+ }
+
if (cfg.fiveminutehours<-1) {
cfg.fiveminutehours = FIVEMINUTEHOURS;
snprintf(errorstring, 512, "%s 5MinuteHours, %s \"%d\".", invalidvalue, resettingto, cfg.fiveminutehours);
cfg.traflessday = TRAFLESSDAY;
cfg.utflocale = UTFLOCALE;
+ cfg.listfivemins = LISTFIVEMINS;
+ cfg.listhours = LISTHOURS;
+ cfg.listdays = LISTDAYS;
+ cfg.listmonths = LISTMONTHS;
+ cfg.listyears = LISTYEARS;
+ cfg.listtop = LISTTOP;
+
cfg.fiveminutehours = FIVEMINUTEHOURS;
cfg.hourlydays = HOURLYDAYS;
cfg.dailydays = DAILYDAYS;
#define DATABASEDIR "/var/lib/vnstat"
#endif
#endif
+
+/* database file name */
#define DATABASEFILE "vnstat.db"
/* on which day should months change */
/* log trafficless days by default */
#define TRAFLESSDAY 1
+/* list outputs */
+#define LISTFIVEMINS 24
+#define LISTHOURS 24
+#define LISTDAYS 30
+#define LISTMONTHS 12
+#define LISTYEARS 0
+#define LISTTOP 10
+
/* data retention defaults */
#define FIVEMINUTEHOURS 48
#define HOURLYDAYS 2
int32_t updateinterval, pollinterval, saveinterval, offsaveinterval, savestatus, uselogging;
int32_t createdirs, updatefileowner, bwdetection, bwdetectioninterval, utflocale;
int32_t fiveminutehours, hourlydays, dailydays, monthlymonths, yearlyyears, topdayentries;
+ int32_t listfivemins, listhours, listdays, listmonths, listyears, listtop;
} CFG;
/* internal interface information structure */
strncpy_nt(colname, listname, 8);
snprintf(titlename, 8, "daily");
strncpy_nt(stampformat, cfg.dformat, 64);
- limit = 30;
+ limit = cfg.listdays;
} else if (strcmp(listname, "month") == 0) {
listtype = 2;
strncpy_nt(colname, listname, 8);
snprintf(titlename, 8, "monthly");
strncpy_nt(stampformat, cfg.mformat, 64);
- limit = 12;
+ limit = cfg.listmonths;
} else if (strcmp(listname, "year") == 0) {
listtype = 3;
strncpy_nt(colname, listname, 8);
snprintf(titlename, 8, "yearly");
strncpy_nt(stampformat, "%Y", 64);
- limit = -1;
+ limit = cfg.listyears;
} else if (strcmp(listname, "top") == 0) {
listtype = 4;
snprintf(colname, 8, "day");
- snprintf(titlename, 8, "top 10");
strncpy_nt(stampformat, cfg.tformat, 64);
- limit = 10;
+ limit = cfg.listtop;
offset = 6;
} else {
return;
}
+ if (limit == 0) {
+ limit = -1;
+ }
+
e_rx = e_tx = e_secs = 0;
+ if (!db_getdata(&datalist, &datainfo, interface->name, listname, limit)) {
+ printf("Error: Failed to fetch %s data.\n", titlename);
+ return;
+ }
+
+ if (listtype == 4) {
+ if (limit > 0 && datainfo.count < (uint32_t)limit) {
+ limit = datainfo.count;
+ }
+ if (limit <= 0 || datainfo.count > 999) {
+ snprintf(titlename, 8, "top");
+ } else {
+ snprintf(titlename, 8, "top %d", limit);
+ }
+ }
+
printf("\n");
if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) {
printf(" %s", interface->name);
printf("\n");
}
- if (!db_getdata(&datalist, &datainfo, interface->name, listname, limit)) {
- printf("Error: Failed to fetch %s data.\n", titlename);
- return;
- }
-
datalist_i = datalist;
while (datalist_i != NULL) {
strncpy_nt(colname, listname, 8);
snprintf(titlename, 8, "daily");
strncpy_nt(stampformat, cfg.dformat, 64);
- limit = 30;
+ limit = cfg.listdays;
} else if (strcmp(listname, "month") == 0) {
listtype = 2;
strncpy_nt(colname, listname, 8);
snprintf(titlename, 8, "monthly");
strncpy_nt(stampformat, cfg.mformat, 64);
- limit = 12;
+ limit = cfg.listmonths;
} else if (strcmp(listname, "year") == 0) {
listtype = 3;
strncpy_nt(colname, listname, 8);
snprintf(titlename, 8, "yearly");
strncpy_nt(stampformat, "%Y", 64);
- limit = -1;
+ limit = cfg.listyears;
} else if (strcmp(listname, "top") == 0) {
listtype = 4;
snprintf(colname, 8, "day");
- snprintf(titlename, 8, "top 10");
strncpy_nt(stampformat, cfg.tformat, 64);
- limit = 10;
+ limit = cfg.listtop;
offsetx = 30;
offsety = -16;
} else {
return;
}
+ if (limit == 0) {
+ limit = -1;
+ }
+
if (!db_getdata(&datalist, &datainfo, ic->interface.name, listname, limit)) {
printf("Error: Failed to fetch %s data.\n", "day");
return;
}
+ if (listtype == 4) {
+ if (limit > 0 && datainfo.count < (uint32_t)limit) {
+ limit = datainfo.count;
+ }
+ if (limit <= 0 || datainfo.count > 999) {
+ snprintf(titlename, 8, "top");
+ } else {
+ snprintf(titlename, 8, "top %d", limit);
+ }
+ }
+
datalist_i = datalist;
width = 500;
p.query=0;
} else if ((strcmp(argv[currentarg],"-u")==0) || (strcmp(argv[currentarg],"--update")==0)) {
printf("Error: The \"%s\" parameter is not supported in this version.\n", argv[currentarg]);
- exit(EXIT_FAILURE);
+ return 1;
} else if ((strcmp(argv[currentarg],"-q")==0) || (strcmp(argv[currentarg],"--query")==0)) {
p.query=1;
} else if ((strcmp(argv[currentarg],"-D")==0) || (strcmp(argv[currentarg],"--debug")==0)) {
debug=1;
} else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--days")==0)) {
cfg.qmode=1;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listdays = atoi(argv[currentarg+1]);
+ if (cfg.listdays < 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],"-m")==0) || (strcmp(argv[currentarg],"--months")==0)) {
cfg.qmode=2;
- } else if ((strcmp(argv[currentarg],"-t")==0) || (strcmp(argv[currentarg],"--top10")==0)) {
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listmonths = atoi(argv[currentarg+1]);
+ if (cfg.listmonths < 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],"-t")==0) || (strcmp(argv[currentarg],"--top")==0)) {
cfg.qmode=3;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listtop = atoi(argv[currentarg+1]);
+ if (cfg.listtop < 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],"-s")==0) || (strcmp(argv[currentarg],"--short")==0)) {
cfg.qmode=5;
} else if ((strcmp(argv[currentarg],"-y")==0) || (strcmp(argv[currentarg],"--years")==0)) {
cfg.qmode=6;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listyears = atoi(argv[currentarg+1]);
+ if (cfg.listyears < 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],"-h")==0) || (strcmp(argv[currentarg],"--hours")==0)) {
cfg.qmode=7;
} else if ((strcmp(argv[currentarg],"--exportdb")==0) || (strcmp(argv[currentarg],"--dumpdb")==0)) {
printf(" -d, --days show days\n");
printf(" -m, --months show months\n");
printf(" -y, --years show years\n");
- printf(" -t, --top10 show top 10 days\n");
+ printf(" -t, --top show top days\n");
printf(" -s, --short use short output\n");
printf(" -i, --iface select interface (default: %s)\n", p->definterface);
printf(" -?, --help short help\n");
printf(" -d, --days show days\n");
printf(" -m, --months show months\n");
printf(" -y, --years show years\n");
- printf(" -t, --top10 show top 10 days\n");
+ printf(" -t, --top show top days\n");
printf(" -s, --short use short output\n");
printf(" -ru, --rateunit swap configured rate unit\n");
printf(" --oneline show simple parseable format\n");
debug = 1;
} else if ((strcmp(argv[currentarg],"-d")==0) || (strcmp(argv[currentarg],"--days"))==0) {
cfg.qmode = 1;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listdays = atoi(argv[currentarg+1]);
+ if (cfg.listdays < 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],"-m")==0) || (strcmp(argv[currentarg],"--months"))==0) {
cfg.qmode = 2;
- } else if ((strcmp(argv[currentarg],"-t")==0) || (strcmp(argv[currentarg],"--top10"))==0) {
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listmonths = atoi(argv[currentarg+1]);
+ if (cfg.listmonths < 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],"-t")==0) || (strcmp(argv[currentarg],"--top"))==0) {
cfg.qmode = 3;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listtop = atoi(argv[currentarg+1]);
+ if (cfg.listtop < 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],"-y")==0) || (strcmp(argv[currentarg],"--years"))==0) {
cfg.qmode = 4;
+ if (currentarg+1<argc && isdigit(argv[currentarg+1][0])) {
+ cfg.listyears = atoi(argv[currentarg+1]);
+ if (cfg.listyears < 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],"-s")==0) || (strcmp(argv[currentarg],"--summary"))==0) {
cfg.qmode = 5;
} else if ((strcmp(argv[currentarg],"-h")==0) || (strcmp(argv[currentarg],"--hours"))==0) {