Move stats flag to stats module

This commit is contained in:
2021-04-23 19:23:44 +02:00
parent 5cb6c1af9b
commit c7dff7c496
2 changed files with 16 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
package stats
import (
"flag"
"fmt"
"github.com/dustin/go-humanize"
"time"
@@ -15,6 +16,14 @@ type Stat struct {
// statPipe is a channel used to
var stats Stat
// printStats sets whether we should print stats or not
var printStats bool
// RegisterStatsFlags registers all flags required by the stats module
func RegisterStatsFlags() {
flag.BoolVar(&printStats, "print-stats", true, "Print traffic statistics every few seconds")
}
// PushStat pushes the given stat
func PushStat(s Stat) {
stats.SentBytes += s.SentBytes
@@ -23,6 +32,11 @@ func PushStat(s Stat) {
// PrintStats periodically prints the collected statistics
func PrintStats() {
// Check if we should print stats
if !printStats {
return
}
t := time.NewTicker(2 * time.Second)
for {