From c567919f806016a4e1382a0dac8fb73adc3d9ed2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 1 Dec 2019 18:37:49 +0200 Subject: [PATCH] lib/logger: track the number of log messages by `(level, file, line)` in the `vm_log_messages_count` metric --- lib/logger/logger.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/logger/logger.go b/lib/logger/logger.go index c2c8478e8..c705bd6e2 100644 --- a/lib/logger/logger.go +++ b/lib/logger/logger.go @@ -11,6 +11,9 @@ import ( "sync" "sync/atomic" "time" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo" + "github.com/VictoriaMetrics/metrics" ) var loggerLevel = flag.String("loggerLevel", "INFO", "Minimum level of errors to log. Possible values: INFO, ERROR, FATAL, PANIC") @@ -119,6 +122,10 @@ func logMessage(level, msg string, skipframes int) { fmt.Fprint(os.Stderr, logMsg) mu.Unlock() + // Increment vm_log_messages_count + counterName := fmt.Sprintf(`vm_log_messages_count{app_version=%q, level=%q, file=%q, line="%d"}`, buildinfo.Version, levelLowercase, file, line) + metrics.GetOrCreateCounter(counterName).Inc() + switch level { case "PANIC": panic(errors.New(msg))