diff --git a/src/dbshow.c b/src/dbshow.c index d1b0413..da6d6cd 100644 --- a/src/dbshow.c +++ b/src/dbshow.c @@ -869,7 +869,6 @@ void showhours(const interfaceinfo *interface) timeused_debug(__func__, 0); } -// TODO: xml? needs new function due to different format // TODO: alert needs new function due to different format // TODO: image? output below doesn't have much graphics potential, line in 5 minute graph could be one alternative // TODO: tests diff --git a/src/dbxml.c b/src/dbxml.c index 3ebf07b..c993e6a 100644 --- a/src/dbxml.c +++ b/src/dbxml.c @@ -1,5 +1,6 @@ #include "common.h" #include "dbsql.h" +#include "percentile.h" #include "dbxml.h" void showxml(const char *interface, const char mode, const char *databegin, const char *dataend) @@ -28,6 +29,13 @@ void showxml(const char *interface, const char mode, const char *databegin, cons xmldate(&info.updated, 2); printf("\n"); + if (mode == 'p') { + xmlpercentile(&info); + printf(" \n"); + timeused_debug(__func__, 0); + return; + } + printf(" \n"); printf(" %" PRIu64 "%" PRIu64 "\n", info.rxtotal, info.txtotal); @@ -96,6 +104,57 @@ void xmldump(const interfaceinfo *interface, const char *tablename, const int da printf(" \n", tablename); } +void xmlpercentile(const interfaceinfo *interface) +{ + percentiledata pdata; + + if (!getpercentiledata(&pdata, interface->name)) { + exit(EXIT_FAILURE); + } + + printf(" \n"); + + printf(" "); + xmldate(&pdata.monthbegin, 1); + printf("\n"); + + printf(" "); + xmldate(&pdata.databegin, 2); + printf("\n"); + + printf(" "); + xmldate(&pdata.dataend, 2); + printf("\n"); + + printf(" %" PRIu32 "%" PRIu32 "%" PRIu32 "\n", pdata.count, pdata.countexpectation, pdata.countexpectation-pdata.count); + + printf(" "); + printf("%" PRIu64 "", (uint64_t)(pdata.minrx / (double)300)); + printf("%" PRIu64 "", (uint64_t)(pdata.mintx / (double)300)); + printf("%" PRIu64 "", (uint64_t)(pdata.min / (double)300)); + printf("\n"); + + printf(" "); + printf("%" PRIu64 "", (uint64_t)(pdata.sumrx / (double)(pdata.count * 300))); + printf("%" PRIu64 "", (uint64_t)(pdata.sumtx / (double)(pdata.count * 300))); + printf("%" PRIu64 "", (uint64_t)(pdata.sumrx + pdata.sumtx / (double)(pdata.count * 300))); + printf("\n"); + + printf(" "); + printf("%" PRIu64 "", (uint64_t)(pdata.maxrx / (double)300)); + printf("%" PRIu64 "", (uint64_t)(pdata.maxtx / (double)300)); + printf("%" PRIu64 "", (uint64_t)(pdata.max / (double)300)); + printf("\n"); + + printf(" <95th_percentile>"); + printf("%" PRIu64 "", (uint64_t)(pdata.rxpercentile / (double)300)); + printf("%" PRIu64 "", (uint64_t)(pdata.txpercentile / (double)300)); + printf("%" PRIu64 "", (uint64_t)(pdata.sumpercentile / (double)300)); + printf("\n"); + + printf(" \n"); +} + void xmldate(const time_t *date, const int type) { struct tm *d; diff --git a/src/dbxml.h b/src/dbxml.h index 1faa3f0..a0b49ab 100644 --- a/src/dbxml.h +++ b/src/dbxml.h @@ -3,6 +3,7 @@ void showxml(const char *interface, const char mode, const char *databegin, const char *dataend); void xmldump(const interfaceinfo *interface, const char *tablename, const int datetype, const char *databegin, const char *dataend); +void xmlpercentile(const interfaceinfo *interface); void xmldate(const time_t *date, const int type); void xmlheader(void); void xmlfooter(void); diff --git a/src/vnstat_func.c b/src/vnstat_func.c index 8d4ed5b..a5e2a9a 100644 --- a/src/vnstat_func.c +++ b/src/vnstat_func.c @@ -347,11 +347,11 @@ void parseargs(PARAMS *p, const int argc, char **argv) cfg.qmode = 8; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { p->xmlmode = argv[currentarg + 1][0]; - if (strlen(argv[currentarg + 1]) != 1 || strchr("asfhdmyt", p->xmlmode) == NULL) { + if (strlen(argv[currentarg + 1]) != 1 || strchr("asfhdmytp", p->xmlmode) == NULL) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for --xml:\n"); - printf(" a - all (default)\n"); + printf(" a - all except 95th percentile (default)\n"); printf(" s - summary\n"); printf(" f - only 5 minutes\n"); printf(" h - only hours\n"); @@ -359,6 +359,7 @@ void parseargs(PARAMS *p, const int argc, char **argv) printf(" m - only months\n"); printf(" y - only years\n"); printf(" t - only top\n"); + printf(" p - 95th percentile\n"); // TODO: documentation exit(EXIT_FAILURE); } if (p->xmlmode == 's') {