2023-06-09 08:47:39 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-06-13 12:27:38 +00:00
|
|
|
logSubsystem = "logger"
|
2023-06-09 08:47:39 +00:00
|
|
|
logLevelLabel = "level"
|
|
|
|
logDroppedLabel = "dropped"
|
|
|
|
)
|
|
|
|
|
2023-10-04 07:03:37 +00:00
|
|
|
type LogMetrics struct {
|
2023-06-09 08:47:39 +00:00
|
|
|
logCount *prometheus.CounterVec
|
|
|
|
}
|
|
|
|
|
2023-10-04 07:03:37 +00:00
|
|
|
func NewLogMetrics(namespace string) *LogMetrics {
|
|
|
|
return &LogMetrics{
|
2023-06-09 08:47:39 +00:00
|
|
|
logCount: metrics.NewCounterVec(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: logSubsystem,
|
2023-06-13 12:27:38 +00:00
|
|
|
Name: "entry_count",
|
2023-06-09 08:47:39 +00:00
|
|
|
Help: "Total log entries emitted or dropped by severity level",
|
|
|
|
}, []string{logLevelLabel, logDroppedLabel}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-04 07:03:37 +00:00
|
|
|
func (m *LogMetrics) Inc(level zapcore.Level, dropped bool) {
|
2023-06-09 08:47:39 +00:00
|
|
|
m.logCount.With(prometheus.Labels{
|
|
|
|
logLevelLabel: level.String(),
|
|
|
|
logDroppedLabel: strconv.FormatBool(dropped),
|
|
|
|
}).Inc()
|
|
|
|
}
|