-
Notifications
You must be signed in to change notification settings - Fork 338
/
metrics.go
74 lines (68 loc) · 1.89 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2022 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package log
import (
m "github.com/ethersphere/bee/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
// metrics groups various metrics counters for statistical reasons.
type metrics struct {
ErrorCount prometheus.Counter
WarnCount prometheus.Counter
InfoCount prometheus.Counter
DebugCount prometheus.Counter
TraceCount prometheus.Counter
}
// Fire implements Hook interface.
func (m metrics) Fire(v Level) error {
switch v {
case VerbosityError:
m.ErrorCount.Inc()
case VerbosityWarning:
m.WarnCount.Inc()
case VerbosityInfo:
m.InfoCount.Inc()
case VerbosityDebug:
m.DebugCount.Inc()
default:
m.TraceCount.Inc()
}
return nil
}
// newLogMetrics returns pointer to a new metrics instance ready to use.
func newLogMetrics() *metrics {
const subsystem = "log"
return &metrics{
ErrorCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "error_count",
Help: "Number ERROR log messages.",
}),
WarnCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "warn_count",
Help: "Number WARN log messages.",
}),
InfoCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "info_count",
Help: "Number INFO log messages.",
}),
DebugCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "debug_count",
Help: "Number DEBUG log messages.",
}),
TraceCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "trace_count",
Help: "Number TRACE log messages.",
}),
}
}