learning_go/go_exporter/metrics.go
a.pivkin 2e19663a63 puk
2025-12-22 07:57:42 +03:00

41 lines
965 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
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))
}