forked from TrueCloudLab/frostfs-node
[#17] Add morph client metrics
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
90e9247b69
commit
4887f489a1
11 changed files with 182 additions and 15 deletions
82
pkg/metrics/morph.go
Normal file
82
pkg/metrics/morph.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
morphmetrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/metrics"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
morphSubsystem = "morph"
|
||||
morphNotificationTypeLabel = "notification_type"
|
||||
morphInvokeTypeLabel = "invoke_type"
|
||||
morphContractLabel = "contract"
|
||||
morphMethodLabel = "method"
|
||||
morphSuccessLabel = "success"
|
||||
)
|
||||
|
||||
type morphClientMetrics struct {
|
||||
switchCount prometheus.Counter
|
||||
lastBlock prometheus.Gauge
|
||||
notificationCount *prometheus.CounterVec
|
||||
invokeDuration *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
func NewMorphClientMetrics() morphmetrics.Register {
|
||||
return &morphClientMetrics{
|
||||
switchCount: metrics.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: morphSubsystem,
|
||||
Name: "switch_count",
|
||||
Help: "Number of endpoint switches",
|
||||
}),
|
||||
lastBlock: metrics.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: morphSubsystem,
|
||||
Name: "last_block",
|
||||
Help: "Index of the last received block",
|
||||
}),
|
||||
notificationCount: metrics.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: morphSubsystem,
|
||||
Name: "notification_count",
|
||||
Help: "Number of notifications received by notification type",
|
||||
}, []string{morphNotificationTypeLabel}),
|
||||
invokeDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: morphSubsystem,
|
||||
Name: "invoke_duration_seconds",
|
||||
Help: "Cummulative duration of contract invocations",
|
||||
}, []string{morphInvokeTypeLabel, morphContractLabel, morphMethodLabel, morphSuccessLabel}),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *morphClientMetrics) IncSwitchCount() {
|
||||
m.switchCount.Inc()
|
||||
}
|
||||
|
||||
func (m *morphClientMetrics) SetLastBlock(index uint32) {
|
||||
m.lastBlock.Set(float64(index))
|
||||
}
|
||||
|
||||
func (m *morphClientMetrics) IncNotificationCount(typ string) {
|
||||
m.notificationCount.With(
|
||||
prometheus.Labels{
|
||||
morphNotificationTypeLabel: typ,
|
||||
},
|
||||
).Inc()
|
||||
}
|
||||
|
||||
func (m *morphClientMetrics) ObserveInvoke(typ string, contract string, method string, success bool, d time.Duration) {
|
||||
m.invokeDuration.With(
|
||||
prometheus.Labels{
|
||||
morphInvokeTypeLabel: typ,
|
||||
morphContractLabel: contract,
|
||||
morphMethodLabel: method,
|
||||
morphSuccessLabel: strconv.FormatBool(success),
|
||||
},
|
||||
).Observe(d.Seconds())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue