puk
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"rbd_exporter/RBDFactory"
|
||||
"rbd_exporter/mytypes"
|
||||
"rbd_exporter/logger"
|
||||
"time"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
|
||||
func GetMetrics(cephConn mytypes.CephConnector) {
|
||||
|
||||
metrics := InitMetrics()
|
||||
prometheus.MustRegister(
|
||||
metrics.Total_rbd_requested_size_per_pool,
|
||||
)
|
||||
|
||||
ticker := time.NewTicker(2 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for range ticker.C {
|
||||
var result []mytypes.Pool = []mytypes.Pool{}
|
||||
poolList, err := cephConn.ListPools()
|
||||
if err != nil {
|
||||
logger.Logger.Error("Cannot get list of pools")
|
||||
// do not exit but continue checking
|
||||
continue
|
||||
}
|
||||
|
||||
for _, v := range poolList {
|
||||
x, _ := RBDFactory.PoolFactory(cephConn, v)
|
||||
result = append(result, x)
|
||||
}
|
||||
|
||||
metrics.Total_rbd_requested_size_per_pool.Reset()
|
||||
for _,v := range result {
|
||||
if !v.HasRBD {continue}
|
||||
FillMetrics(v,metrics)
|
||||
}
|
||||
fmt.Println("====================")
|
||||
// fmt.Println(result)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func InitMetrics() *mytypes.Metrics {
|
||||
m := &mytypes.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 mytypes.Pool,metrics *mytypes.Metrics) {
|
||||
var totalSizePerPool uint64 = 0
|
||||
|
||||
logger.Logger.Debugf("Processing pool %s",pool.Name)
|
||||
for _,v := range pool.RBDlist {
|
||||
totalSizePerPool += uint64(v.GetSize())
|
||||
}
|
||||
logger.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))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user