2023-06-08 13:37:46 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type morphClientMetrics struct {
|
|
|
|
switchCount prometheus.Counter
|
|
|
|
lastBlock prometheus.Gauge
|
|
|
|
notificationCount *prometheus.CounterVec
|
|
|
|
invokeDuration *prometheus.HistogramVec
|
|
|
|
}
|
|
|
|
|
2023-10-04 07:03:37 +00:00
|
|
|
func newMorphClientMetrics() *morphClientMetrics {
|
2023-06-08 13:37:46 +00:00
|
|
|
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",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{notificationTypeLabel}),
|
2023-06-08 13:37:46 +00:00
|
|
|
invokeDuration: metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: morphSubsystem,
|
|
|
|
Name: "invoke_duration_seconds",
|
|
|
|
Help: "Cummulative duration of contract invocations",
|
2023-06-16 07:13:22 +00:00
|
|
|
}, []string{invokeTypeLabel, contractLabel, methodLabel, successLabel}),
|
2023-06-08 13:37:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2023-06-16 07:13:22 +00:00
|
|
|
notificationTypeLabel: typ,
|
2023-06-08 13:37:46 +00:00
|
|
|
},
|
|
|
|
).Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *morphClientMetrics) ObserveInvoke(typ string, contract string, method string, success bool, d time.Duration) {
|
|
|
|
m.invokeDuration.With(
|
|
|
|
prometheus.Labels{
|
2023-06-16 07:13:22 +00:00
|
|
|
invokeTypeLabel: typ,
|
|
|
|
contractLabel: contract,
|
|
|
|
methodLabel: method,
|
|
|
|
successLabel: strconv.FormatBool(success),
|
2023-06-08 13:37:46 +00:00
|
|
|
},
|
|
|
|
).Observe(d.Seconds())
|
|
|
|
}
|