Skip to content

Commit

Permalink
add --noremove option to daemon for disabling the automatic removal o…
Browse files Browse the repository at this point in the history
…f interfaces from database that aren't currently visible and haven't seen any traffic
  • Loading branch information
vergoh committed Dec 28, 2023
1 parent c5718a3 commit c9bfab2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
regardless of the number of interfaces in the database
- Add --startempty option to daemon for starting and keeping the daemon
running even if no interfaces were discovered and the database is empty
- Add --noremove option to daemon for disabling the automatic removal of
interfaces from database that aren't currently visible and haven't seen
any traffic


2.11 / 19-Aug-2023
Expand Down
6 changes: 6 additions & 0 deletions man/vnstatd.8
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ vnstatd \- daemon based database updating for vnStat
.RB [ \-\-initdb ]
.RB [ \-\-noadd ]
.RB [ \-\-nodaemon ]
.RB [ \-\-noremove ]
.RB [ \-\-pidfile
.IR file ]
.RB [ \-\-startempty ]
Expand Down Expand Up @@ -150,6 +151,11 @@ added regardless of this option.
Stay in foreground attached to the current terminal and start the update
process.

.TP
.B "--noremove"
Disable automatic removal of interfaces from database that aren't currently visible
and haven't seen any traffic.

.TP
.BI "-p, --pidfile " file
Write the process id to
Expand Down
3 changes: 2 additions & 1 deletion src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ void initdstate(DSTATE *s)
s->sync = 0;
s->forcesave = 0;
s->noadd = 0;
s->noremove = 0;
s->initdb = 0;
s->startempty = 0;
s->iflisthash = 0;
Expand Down Expand Up @@ -674,7 +675,7 @@ void flushcachetodisk(DSTATE *s)
}
}

if (!iterator->active && !logcount) {
if (!s->noremove && !iterator->active && !logcount) {
/* throw away if interface hasn't seen any data and is disabled */
if (!iterator->currx && !iterator->curtx) {
ret = db_getinterfaceinfo(iterator->interface, &info);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
typedef struct {
int updateinterval, saveinterval;
short running, dodbsave, rundaemon;
short dbsaved, showhelp, sync, forcesave, noadd, initdb, startempty;
short dbsaved, showhelp, sync, forcesave, noadd, noremove, initdb, startempty;
short bootdetected, cleanuphour, dbretrycount;
uint32_t iflisthash;
uint64_t dbifcount;
Expand Down
3 changes: 3 additions & 0 deletions src/vnstatd.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ void showhelp(void)
printf(" --alwaysadd [mode] automatically start monitoring all new interfaces\n");
printf(" --noadd disable discovery of interfaces when database\n");
printf(" contains none\n");
printf(" --noremove disable removal of never seen interfaces\n");
printf(" --startempty start even when database is empty\n\n");

printf("See also \"man vnstatd\".\n");
Expand Down Expand Up @@ -318,6 +319,8 @@ void parseargs(DSTATE *s, int argc, char **argv)
}
} else if (strcmp(argv[currentarg], "--noadd") == 0) {
s->noadd = 1;
} else if (strcmp(argv[currentarg], "--noremove") == 0) {
s->noremove = 1;
} else if (strcmp(argv[currentarg], "--alwaysadd") == 0) {
if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) {
if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) {
Expand Down

0 comments on commit c9bfab2

Please sign in to comment.