From 3eb433d632b4d5eaf3b365575dad3fda71333aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Fri, 20 Dec 2024 22:36:54 +0100 Subject: [PATCH] wip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- cmd/windows_exporter/main.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/windows_exporter/main.go b/cmd/windows_exporter/main.go index 63a47d10c..16296b33b 100644 --- a/cmd/windows_exporter/main.go +++ b/cmd/windows_exporter/main.go @@ -20,9 +20,6 @@ package main //goland:noinspection GoUnsortedImport //nolint:gofumpt import ( - // Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts. - "github.com/prometheus-community/windows_exporter/internal/windowsservice" - "context" "errors" "fmt" @@ -33,10 +30,14 @@ import ( "os/signal" "os/user" "runtime" + "runtime/debug" "slices" "strings" "time" + // Its important that we do these first so that we can register with the Windows service control ASAP to avoid timeouts. + "github.com/prometheus-community/windows_exporter/internal/windowsservice" + "github.com/alecthomas/kingpin/v2" "github.com/prometheus-community/windows_exporter/internal/config" "github.com/prometheus-community/windows_exporter/internal/httphandler" @@ -103,6 +104,10 @@ func run() int { "process.priority", "Priority of the exporter process. Higher priorities may improve exporter responsiveness during periods of system load. Can be one of [\"realtime\", \"high\", \"abovenormal\", \"normal\", \"belownormal\", \"low\"]", ).Default("normal").String() + memoryLimit = app.Flag( + "process.memory-limit", + "Limit memory usage in bytes. This is a soft-limit and not guaranteed. 0 means no limit. Read more at https://pkg.go.dev/runtime/debug#SetMemoryLimit .", + ).Default("200000000").Int64() ) logFile := &log.AllowedFile{} @@ -132,6 +137,8 @@ func run() int { return 1 } + debug.SetMemoryLimit(*memoryLimit) + logger, err := log.New(logConfig) if err != nil { //nolint:sloglint // we do not have an logger yet