From ba22b101131ce67aa8189409272d97fd03f4c3a5 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 25 Jul 2018 15:51:27 +0200 Subject: [PATCH] prometheus: log virtual memory limits Signed-off-by: Simon Pasquier --- ...{fdlimits_default.go => limits_default.go} | 28 +++++++++++++++---- ...{fdlimits_windows.go => limits_windows.go} | 5 ++++ cmd/prometheus/main.go | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) rename cmd/prometheus/{fdlimits_default.go => limits_default.go} (59%) rename cmd/prometheus/{fdlimits_windows.go => limits_windows.go} (89%) diff --git a/cmd/prometheus/fdlimits_default.go b/cmd/prometheus/limits_default.go similarity index 59% rename from cmd/prometheus/fdlimits_default.go rename to cmd/prometheus/limits_default.go index 197810e28..f93fc6207 100644 --- a/cmd/prometheus/fdlimits_default.go +++ b/cmd/prometheus/limits_default.go @@ -21,12 +21,30 @@ import ( "syscall" ) -// FdLimits returns the soft and hard limits for file descriptors -func FdLimits() string { - flimit := syscall.Rlimit{} - err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &flimit) +var unlimited int64 = syscall.RLIM_INFINITY + +func limitToString(v uint64) string { + if v == uint64(unlimited) { + return "unlimited" + } + return fmt.Sprintf("%d", v) +} + +func getLimits(resource int) string { + rlimit := syscall.Rlimit{} + err := syscall.Getrlimit(resource, &rlimit) if err != nil { log.Fatal("Error!") } - return fmt.Sprintf("(soft=%d, hard=%d)", flimit.Cur, flimit.Max) + return fmt.Sprintf("(soft=%s, hard=%s)", limitToString(rlimit.Cur), limitToString(rlimit.Max)) +} + +// FdLimits returns the soft and hard limits for file descriptors. +func FdLimits() string { + return getLimits(syscall.RLIMIT_NOFILE) +} + +// VmLimits returns the soft and hard limits for virtual memory. +func VmLimits() string { + return getLimits(syscall.RLIMIT_AS) } diff --git a/cmd/prometheus/fdlimits_windows.go b/cmd/prometheus/limits_windows.go similarity index 89% rename from cmd/prometheus/fdlimits_windows.go rename to cmd/prometheus/limits_windows.go index 3fcff4905..d18d58041 100644 --- a/cmd/prometheus/fdlimits_windows.go +++ b/cmd/prometheus/limits_windows.go @@ -19,3 +19,8 @@ package main func FdLimits() string { return "N/A" } + +// VmLimits not supported on Windows +func VmLimits() string { + return "N/A" +} diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 5a44e21f7..271cc939b 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -223,6 +223,7 @@ func main() { level.Info(logger).Log("build_context", version.BuildContext()) level.Info(logger).Log("host_details", Uname()) level.Info(logger).Log("fd_limits", FdLimits()) + level.Info(logger).Log("vm_limits", VmLimits()) var ( localStorage = &tsdb.ReadyStorage{}