make sleep time configurable

This commit is contained in:
2025-10-21 09:43:42 +02:00
parent f1a07a1f63
commit e9a4c46044
2 changed files with 8 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ const (
Usage = `io-exporter [options] <file> Usage = `io-exporter [options] <file>
Options: Options:
-t --timeout <int> When should the operation timeout in seconds -t --timeout <int> When should the operation timeout in seconds
-s --sleeptime <int> Time to sleep between checks (default: 5s)
-l --label <label=value> Add label to exported metric -l --label <label=value> Add label to exported metric
-h --help Show help -h --help Show help
-v --version Show program version` -v --version Show program version`
@@ -32,6 +33,7 @@ type Config struct {
Label []string `koanf:"label"` // -v Label []string `koanf:"label"` // -v
Timeout int `koanf:"timeout"` // -t Timeout int `koanf:"timeout"` // -t
Port int `koanf:"port"` // -p Port int `koanf:"port"` // -p
Sleeptime int `koanf:"sleep"` // -s
File string File string
Labels []Label Labels []Label
@@ -55,6 +57,7 @@ func InitConfig(output io.Writer) (*Config, error) {
flagset.StringArrayP("label", "l", nil, "additional labels") flagset.StringArrayP("label", "l", nil, "additional labels")
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds") flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
flagset.IntP("port", "p", 9187, "prometheus metrics port to listen to") 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 { if err := flagset.Parse(os.Args[1:]); err != nil {
return nil, fmt.Errorf("failed to parse program arguments: %w", err) return nil, fmt.Errorf("failed to parse program arguments: %w", err)

View File

@@ -35,7 +35,7 @@ func Run() {
metrics.Set(result, elapsed) metrics.Set(result, elapsed)
time.Sleep(SLEEP * time.Second) time.Sleep(time.Duration(conf.Sleeptime) * time.Second)
} }
}() }()