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: "switches_total", 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: "notifications_total", 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()) }