From b33e083b9344869c55ec8c7dee1f49c0f0807ae8 Mon Sep 17 00:00:00 2001 From: Teymur Date: Sun, 10 Mar 2024 12:58:59 +0400 Subject: [PATCH 1/2] move sleep to result handler --- main.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index a7128da..cfa5edd 100644 --- a/main.go +++ b/main.go @@ -95,7 +95,7 @@ func main() { timeout = config.Exporter.DefaultProbeTimeout } targetLogger := logger.With(slog.String("target",target)) - resultHandler := func(result bool, err error) { + resultHandler := func(result bool, err error, interval int) { if result { targetLogger.Info("OK") probeResult.WithLabelValues(target, module, address).Set(1) @@ -105,25 +105,23 @@ func main() { } probeResult.WithLabelValues(target, module, address).Set(0) } + time.Sleep(time.Duration(interval) * time.Second) } switch module { case "tcp": for { result,err := modules.ProbeTCP(address,timeout) - resultHandler(result,err) - time.Sleep(time.Duration(interval) * time.Second) + resultHandler(result,err,interval) } case "http": for { result,err := modules.ProbeHTTP(address,timeout) - resultHandler(result,err) - time.Sleep(time.Duration(interval) * time.Second) + resultHandler(result,err,interval) } case "icmp": for { result,err := modules.ProbeICMP(address) - resultHandler(result,err) - time.Sleep(time.Duration(interval) * time.Second) + resultHandler(result,err,interval) } default: targetLogger.Error("Unknown module") From 56c869e91affca3ad935be1c2c38a5db9a285132 Mon Sep 17 00:00:00 2001 From: Teymur Date: Sun, 10 Mar 2024 13:06:40 +0400 Subject: [PATCH 2/2] upd changelog --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0614dc6..f1bf85c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,19 @@ -## [0.2.0] - 2024-02-01 +# Changelog + +## [0.2.1] - 2024-03-10 + +### Changed + +- Moved sleep function under resultHandler function + +## [0.2.0] - 2024-02-26 ### Added - ICMP checks ### Changed + - probe_success metric renamed to probe_result - Minimized code