From e9a4c46044c0941bd81f339f073ea11b604bde58 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Tue, 21 Oct 2025 09:43:42 +0200 Subject: [PATCH] make sleep time configurable --- cmd/config.go | 11 +++++++---- cmd/root.go | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index c2f9cfe..10ea9e4 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -19,10 +19,11 @@ const ( SLEEP = 5 Usage = `io-exporter [options] Options: --t --timeout When should the operation timeout in seconds --l --label Add label to exported metric --h --help Show help --v --version Show program version` +-t --timeout When should the operation timeout in seconds +-s --sleeptime Time to sleep between checks (default: 5s) +-l --label Add label to exported metric +-h --help Show help +-v --version Show program version` ) // config via commandline flags @@ -32,6 +33,7 @@ type Config struct { Label []string `koanf:"label"` // -v Timeout int `koanf:"timeout"` // -t Port int `koanf:"port"` // -p + Sleeptime int `koanf:"sleep"` // -s File string Labels []Label @@ -55,6 +57,7 @@ func InitConfig(output io.Writer) (*Config, error) { flagset.StringArrayP("label", "l", nil, "additional labels") flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds") flagset.IntP("port", "p", 9187, "prometheus metrics port to listen to") + flagset.IntP("sleeptime", "s", 5, "time to sleep between checks (default: 5s)") if err := flagset.Parse(os.Args[1:]); err != nil { return nil, fmt.Errorf("failed to parse program arguments: %w", err) diff --git a/cmd/root.go b/cmd/root.go index e321d13..5a70e44 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -35,7 +35,7 @@ func Run() { metrics.Set(result, elapsed) - time.Sleep(SLEEP * time.Second) + time.Sleep(time.Duration(conf.Sleeptime) * time.Second) } }()