lib/logger: track the number of log messages by (level, file, line) in the vm_log_messages_count metric

This commit is contained in:
Aliaksandr Valialkin 2019-12-01 18:37:49 +02:00
parent 761645b20a
commit c567919f80

View file

@ -11,6 +11,9 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "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") 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) fmt.Fprint(os.Stderr, logMsg)
mu.Unlock() 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 { switch level {
case "PANIC": case "PANIC":
panic(errors.New(msg)) panic(errors.New(msg))