mirror of
https://codeberg.org/scip/io-exporter.git
synced 2025-12-16 20:11:00 +01:00
fix sleep time default, add debug flag
This commit is contained in:
@@ -23,6 +23,7 @@ Options:
|
||||
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
||||
-l --label <label=value> Add label to exported metric
|
||||
-i --internals Also add labels about resource usage
|
||||
-d --debug Enable debug log level
|
||||
-h --help Show help
|
||||
-v --version Show program version`
|
||||
)
|
||||
@@ -32,10 +33,11 @@ type Config struct {
|
||||
Showversion bool `koanf:"version"` // -v
|
||||
Showhelp bool `koanf:"help"` // -h
|
||||
Internals bool `koanf:"internals"` // -i
|
||||
Debug bool `koanf:"debug"` // -d
|
||||
Label []string `koanf:"label"` // -v
|
||||
Timeout int `koanf:"timeout"` // -t
|
||||
Port int `koanf:"port"` // -p
|
||||
Sleeptime int `koanf:"sleep"` // -s
|
||||
Sleeptime int `koanf:"sleeptime"` // -s
|
||||
|
||||
File string
|
||||
Labels []Label
|
||||
@@ -56,6 +58,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
||||
// parse commandline flags
|
||||
flagset.BoolP("version", "v", false, "show program version")
|
||||
flagset.BoolP("help", "h", false, "show help")
|
||||
flagset.BoolP("debug", "d", false, "enable debug logs")
|
||||
flagset.BoolP("internals", "i", false, "add internal metrics")
|
||||
flagset.StringArrayP("label", "l", nil, "additional labels")
|
||||
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
||||
|
||||
@@ -7,14 +7,18 @@ import (
|
||||
"github.com/lmittmann/tint"
|
||||
)
|
||||
|
||||
func setLogger(output io.Writer) {
|
||||
func setLogger(output io.Writer, debug bool) {
|
||||
logLevel := &slog.LevelVar{}
|
||||
opts := &tint.Options{
|
||||
Level: logLevel,
|
||||
AddSource: false,
|
||||
}
|
||||
|
||||
logLevel.Set(slog.LevelDebug)
|
||||
if debug {
|
||||
logLevel.Set(slog.LevelDebug)
|
||||
} else {
|
||||
logLevel.Set(slog.LevelInfo)
|
||||
}
|
||||
|
||||
handler := tint.NewHandler(output, opts)
|
||||
logger := slog.New(handler)
|
||||
|
||||
@@ -21,7 +21,7 @@ func Run() {
|
||||
metrics := NewMetrics(conf)
|
||||
alloc := NewAlloc()
|
||||
|
||||
setLogger(os.Stdout)
|
||||
setLogger(os.Stdout, conf.Debug)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
@@ -32,6 +32,7 @@ func Run() {
|
||||
// ns => s
|
||||
now := time.Now()
|
||||
elapsed := float64(now.Sub(start).Nanoseconds()) / 10000000000
|
||||
slog.Debug("elapsed time", "elapsed", elapsed, "result", result)
|
||||
|
||||
metrics.Set(result, elapsed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user