learning_go/go_exporter/metrics.go
2025-12-17 10:02:26 +03:00

42 lines
1016 B
Go

package main
import (
"github.com/prometheus/client_golang/prometheus"
)
func InitMetrics() *Metrics {
m := &Metrics{
total_rbd_requested_size_per_pool: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "total_rbd_requested_size_per_pool",
Help: "total size of all requested RBDs in a specific pool",
},
[]string{"poolname"},
),
// total_rbd_requested_size: prometheus.NewGauge(
// prometheus.GaugeOpts{
// Name: "total_rbd_requested_size",
// Help: "total size of all RBDs in the cluster",
// },
// ),
}
return m
}
func FillMetrics(pool Pool,metrics *Metrics) {
var totalSizePerPool uint64 = 0
metrics.total_rbd_requested_size_per_pool.Reset()
logger.Debugf("Processing pool %s",pool.Name)
for _,v := range pool.RBDlist {
totalSizePerPool += uint64(v.getSize())
}
logger.Debugf("Total size of RBDs in pool %s is %d",pool.Name,totalSizePerPool)
metrics.total_rbd_requested_size_per_pool.WithLabelValues(pool.Name,
).Set(
float64(totalSizePerPool))
}