From 50e978cf769d438eb4d6e46bda97e55f91f00615 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Thu, 8 Jan 2015 18:15:58 +0200 Subject: [PATCH] add BandwidthDetectionInterval configuration keyword --- cfg/vnstat.conf | 6 +++++- src/cfg.c | 14 ++++++++++++++ src/common.h | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cfg/vnstat.conf b/cfg/vnstat.conf index 56c71e3..f0c6276 100644 --- a/cfg/vnstat.conf +++ b/cfg/vnstat.conf @@ -1,4 +1,4 @@ -# vnStat 1.12 config file +# vnStat 1.13 config file ## # default interface @@ -93,6 +93,10 @@ SaveInterval 5 # how often (in minutes) data is saved when all interface are offline OfflineSaveInterval 30 +# how often (in minutes) bandwidth detection is redone when +# BandwidthDetection is enabled (0 = disabled) +BandwidthDetectionInterval 5 + # force data save when interface status changes (1 = enabled, 0 = disabled) SaveOnStatusChange 1 diff --git a/src/cfg.c b/src/cfg.c index 8de9443..2e77c06 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -106,6 +106,10 @@ void printcfgfile(void) printf("# how often (in minutes) data is saved when all interface are offline\n"); printf("OfflineSaveInterval %d\n\n", cfg.offsaveinterval); + printf("# how often (in minutes) bandwidth detection is redone when\n"); + printf("# BandwidthDetection is enabled (0 = disabled)\n"); + printf("BandwidthDetectionInterval %d\n\n", cfg.bwdetectioninterval); + printf("# force data save when interface status changes (1 = enabled, 0 = disabled)\n"); printf("SaveOnStatusChange %d\n\n", cfg.savestatus); @@ -196,6 +200,7 @@ int loadcfg(const char *cfgfile) { "PollInterval", 0, &cfg.pollinterval, 0, 0 }, { "SaveInterval", 0, &cfg.saveinterval, 0, 0 }, { "OfflineSaveInterval", 0, &cfg.offsaveinterval, 0, 0 }, + { "BandwidthDetectionInterval", 0, &cfg.bwdetectioninterval, 0, 0 }, { "SaveOnStatusChange", 0, &cfg.savestatus, 0, 0 }, { "UseLogging", 0, &cfg.uselogging, 0, 0 }, { "CreateDirs", 0, &cfg.createdirs, 0, 0 }, @@ -315,6 +320,8 @@ int loadcfg(const char *cfgfile) } /* while */ + fclose(fd); + /* validate config */ validatecfg(); @@ -485,6 +492,12 @@ void validatecfg(void) snprintf(errorstring, 512, "Invalid value for BandwidthDetection, resetting to \"%d\".", cfg.bwdetection); printe(PT_Config); } + + if (cfg.bwdetectioninterval<0 || cfg.bwdetectioninterval>30) { + cfg.bwdetectioninterval = BWDETECTINTERVAL; + snprintf(errorstring, 512, "Invalid value for BandwidthDetectionInterval, resetting to \"%d\".", cfg.bwdetectioninterval); + printe(PT_Config); + } } void defaultcfg(void) @@ -499,6 +512,7 @@ void defaultcfg(void) cfg.ostyle = OSTYLE; cfg.rateunit = RATEUNIT; cfg.bwdetection = BWDETECT; + cfg.bwdetectioninterval = BWDETECTINTERVAL; cfg.maxbw = DEFMAXBW; cfg.spacecheck = USESPACECHECK; cfg.flock = USEFLOCK; diff --git a/src/common.h b/src/common.h index ee8a177..0d6f6f7 100644 --- a/src/common.h +++ b/src/common.h @@ -106,6 +106,7 @@ and most can be changed later from the config file. /* bandwidth detection, 0 = feature disabled */ #define BWDETECT 1 +#define BWDETECTINTERVAL 5 /* default maximum bandwidth (Mbit) for all interfaces */ /* 0 = feature disabled */ @@ -220,7 +221,7 @@ typedef struct { char logfile[512], pidfile[512]; char daemonuser[33], daemongroup[33]; short updateinterval, pollinterval, saveinterval, offsaveinterval, savestatus, uselogging; - short createdirs, updatefileowner, bwdetection; + short createdirs, updatefileowner, bwdetection, bwdetectioninterval; } CFG; /* internal interface information structure */ -- 2.40.0