[#324] Add replicator metrics
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
6055b18362
commit
a6ee7a3087
6 changed files with 86 additions and 0 deletions
59
pkg/metrics/replicator.go
Normal file
59
pkg/metrics/replicator.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package metrics
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
const replicatorSubsystem = "replicator"
|
||||
|
||||
type replicatorMetrics struct {
|
||||
inFlightRequests metric[prometheus.Gauge]
|
||||
processedObjects metric[prometheus.Counter]
|
||||
totalReplicatedPayloadSize metric[prometheus.Counter]
|
||||
}
|
||||
|
||||
func (m replicatorMetrics) IncInFlightRequest() {
|
||||
m.inFlightRequests.value.Inc()
|
||||
}
|
||||
|
||||
func (m replicatorMetrics) DecInFlightRequest() {
|
||||
m.inFlightRequests.value.Dec()
|
||||
}
|
||||
|
||||
func (m replicatorMetrics) IncProcessedObjects() {
|
||||
m.processedObjects.value.Inc()
|
||||
}
|
||||
|
||||
func (m replicatorMetrics) AddPayloadSize(size int64) {
|
||||
m.totalReplicatedPayloadSize.value.Add(float64(size))
|
||||
}
|
||||
|
||||
func newReplicatorMetrics() replicatorMetrics {
|
||||
return replicatorMetrics{
|
||||
inFlightRequests: newReplicatorGauge("in_flight_requests", "Number of in-flight requests"),
|
||||
processedObjects: newReplicatorCounter("processed_objects", "Number of objects processed since the node startup"),
|
||||
totalReplicatedPayloadSize: newReplicatorCounter("total_replicated_payload_size", "Total size of payloads replicated"),
|
||||
}
|
||||
}
|
||||
|
||||
func (m replicatorMetrics) register() {
|
||||
mustRegister(m.inFlightRequests)
|
||||
mustRegister(m.processedObjects)
|
||||
mustRegister(m.totalReplicatedPayloadSize)
|
||||
}
|
||||
|
||||
func newReplicatorCounter(name, help string) metric[prometheus.Counter] {
|
||||
return newCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: replicatorSubsystem,
|
||||
Name: name,
|
||||
Help: help,
|
||||
})
|
||||
}
|
||||
|
||||
func newReplicatorGauge(name, help string) metric[prometheus.Gauge] {
|
||||
return newGauge(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: replicatorSubsystem,
|
||||
Name: name,
|
||||
Help: help,
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue