From 897970aa3fc100e0ed5fd6ddcea6bd9867c029d3 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sat, 1 Apr 2023 10:34:28 +0200 Subject: Add more metrics Number of connected / onion location / connection attempts. --- .main.go.swp | Bin 0 -> 20480 bytes main.go | 12 ++++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .main.go.swp diff --git a/.main.go.swp b/.main.go.swp new file mode 100644 index 0000000..36e0a39 Binary files /dev/null and b/.main.go.swp differ diff --git a/main.go b/main.go index 9725d98..fcd8bbf 100644 --- a/main.go +++ b/main.go @@ -146,10 +146,9 @@ func workAggregator(ctx context.Context, opts options.Options, answerCh chan qna numConnect := 0 numOnions := 0 numAll := 0 - output := func() { - log.Printf("SUMMARY: %d/%d connected, %d sites configured Onion-Location\n", numConnect, numAll, numOnions) + output := func(prefix string) { + log.Printf("%s: %d/%d connected, %d sites configured Onion-Location\n", prefix, numConnect, numAll, numOnions) } - handleAnswer := func(a qna.Answer) { numAll += 1 if !a.OK { @@ -163,7 +162,10 @@ func workAggregator(ctx context.Context, opts options.Options, answerCh chan qna } } - defer output() + metrics := time.NewTicker(opts.MetricsInterval) + defer metrics.Stop() + + defer output("SUMMARY") for { select { case <-ctx.Done(): @@ -178,6 +180,8 @@ func workAggregator(ctx context.Context, opts options.Options, answerCh chan qna } case a := <-answerCh: handleAnswer(a) + case <-metrics.C: + output("INFO") } } } -- cgit v1.2.3