forked from TrueCloudLab/frostfs-node
[#375] Add log metrics
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
83d600ed77
commit
0c40d98f7a
4 changed files with 48 additions and 0 deletions
|
@ -61,6 +61,7 @@ func main() {
|
||||||
cfg, err = newConfig()
|
cfg, err = newConfig()
|
||||||
exitErr(err)
|
exitErr(err)
|
||||||
|
|
||||||
|
logPrm.MetricsNamespace = "frostfs-ir"
|
||||||
err = logPrm.SetLevelString(
|
err = logPrm.SetLevelString(
|
||||||
cfg.GetString("logger.level"),
|
cfg.GetString("logger.level"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -542,6 +542,8 @@ func initCfg(appCfg *config.Config) *cfg {
|
||||||
logPrm, err := c.loggerPrm()
|
logPrm, err := c.loggerPrm()
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
|
logPrm.MetricsNamespace = "frostfs-node"
|
||||||
|
|
||||||
log, err := logger.NewLogger(logPrm)
|
log, err := logger.NewLogger(logPrm)
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ type Prm struct {
|
||||||
// support runtime rereading
|
// support runtime rereading
|
||||||
level zapcore.Level
|
level zapcore.Level
|
||||||
|
|
||||||
|
// MetricsNamespace is the namespace string used for log counter metrics
|
||||||
|
MetricsNamespace string
|
||||||
|
|
||||||
// do not support runtime rereading
|
// do not support runtime rereading
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +82,15 @@ func NewLogger(prm *Prm) (*Logger, error) {
|
||||||
|
|
||||||
lvl := zap.NewAtomicLevelAt(prm.level)
|
lvl := zap.NewAtomicLevelAt(prm.level)
|
||||||
|
|
||||||
|
m := newLogMetrics(prm.MetricsNamespace)
|
||||||
|
|
||||||
c := zap.NewProductionConfig()
|
c := zap.NewProductionConfig()
|
||||||
c.Level = lvl
|
c.Level = lvl
|
||||||
c.Encoding = "console"
|
c.Encoding = "console"
|
||||||
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||||
|
c.Sampling.Hook = func(e zapcore.Entry, sd zapcore.SamplingDecision) {
|
||||||
|
m.Inc(e.Level, sd == zapcore.LogDropped)
|
||||||
|
}
|
||||||
|
|
||||||
lZap, err := c.Build(
|
lZap, err := c.Build(
|
||||||
zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)),
|
zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)),
|
||||||
|
|
37
pkg/util/logger/metrics.go
Normal file
37
pkg/util/logger/metrics.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
logSubsystem = "log"
|
||||||
|
logLevelLabel = "level"
|
||||||
|
logDroppedLabel = "dropped"
|
||||||
|
)
|
||||||
|
|
||||||
|
type logMetrics struct {
|
||||||
|
logCount *prometheus.CounterVec
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLogMetrics(namespace string) *logMetrics {
|
||||||
|
return &logMetrics{
|
||||||
|
logCount: metrics.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: logSubsystem,
|
||||||
|
Name: "log_count",
|
||||||
|
Help: "Total log entries emitted or dropped by severity level",
|
||||||
|
}, []string{logLevelLabel, logDroppedLabel}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *logMetrics) Inc(level zapcore.Level, dropped bool) {
|
||||||
|
m.logCount.With(prometheus.Labels{
|
||||||
|
logLevelLabel: level.String(),
|
||||||
|
logDroppedLabel: strconv.FormatBool(dropped),
|
||||||
|
}).Inc()
|
||||||
|
}
|
Loading…
Reference in a new issue