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/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))