2023-06-08 13:37:46 +00:00
|
|
|
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,
|
2023-06-14 07:16:19 +00:00
|
|
|
Name: "switches_total",
|
2023-06-08 13:37:46 +00:00
|
|
|
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,
|
2023-06-14 07:16:19 +00:00
|
|
|
Name: "notifications_total",
|
2023-06-08 13:37:46 +00:00
|
|
|
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())
|
|
|
|
}
|