2023-05-12 08:44:21 +00:00
|
|
|
package metrics
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
import (
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
2023-05-12 08:44:21 +00:00
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
type ReplicatorMetrics interface {
|
|
|
|
IncInFlightRequest()
|
|
|
|
DecInFlightRequest()
|
|
|
|
IncProcessedObjects()
|
|
|
|
AddPayloadSize(size int64)
|
|
|
|
}
|
|
|
|
|
2023-05-12 08:44:21 +00:00
|
|
|
type replicatorMetrics struct {
|
2023-05-31 09:25:32 +00:00
|
|
|
inFlightRequests prometheus.Gauge
|
|
|
|
processedObjects prometheus.Counter
|
|
|
|
totalReplicatedPayloadSize prometheus.Counter
|
2023-05-12 08:44:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *replicatorMetrics) IncInFlightRequest() {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.inFlightRequests.Inc()
|
2023-05-12 08:44:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *replicatorMetrics) DecInFlightRequest() {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.inFlightRequests.Dec()
|
2023-05-12 08:44:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *replicatorMetrics) IncProcessedObjects() {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.processedObjects.Inc()
|
2023-05-12 08:44:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func (m *replicatorMetrics) AddPayloadSize(size int64) {
|
2023-05-31 09:25:32 +00:00
|
|
|
m.totalReplicatedPayloadSize.Add(float64(size))
|
2023-05-12 08:44:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 07:05:51 +00:00
|
|
|
func newReplicatorMetrics() *replicatorMetrics {
|
|
|
|
return &replicatorMetrics{
|
2023-06-14 07:16:19 +00:00
|
|
|
inFlightRequests: newReplicatorGauge("in_flight_requests_total", "Number of in-flight requests"),
|
|
|
|
processedObjects: newReplicatorCounter("processed_objects_total", "Number of objects processed since the node startup"),
|
|
|
|
totalReplicatedPayloadSize: newReplicatorCounter("total_replicated_payload_size_bytes", "Total size of payloads replicated"),
|
2023-05-12 08:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
func newReplicatorCounter(name, help string) prometheus.Counter {
|
|
|
|
return metrics.NewCounter(prometheus.CounterOpts{
|
2023-05-12 08:44:21 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: replicatorSubsystem,
|
|
|
|
Name: name,
|
|
|
|
Help: help,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-31 09:25:32 +00:00
|
|
|
func newReplicatorGauge(name, help string) prometheus.Gauge {
|
|
|
|
return metrics.NewGauge(prometheus.GaugeOpts{
|
2023-05-12 08:44:21 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: replicatorSubsystem,
|
|
|
|
Name: name,
|
|
|
|
Help: help,
|
|
|
|
})
|
|
|
|
}
|