This commit is contained in:
a.pivkin 2025-11-27 17:36:23 +03:00
parent 1e62c5483d
commit 6762716a12
3 changed files with 56 additions and 19 deletions

View File

View File

@ -5,6 +5,10 @@ metadata:
namespace: rook-ceph
labels:
app: export-deploy
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9040"
prometheus.io/path: "/metrics"
spec:
replicas: 1
selector:
@ -17,7 +21,7 @@ spec:
spec:
containers:
- name: export
image: serviceplant/goexp:0.0.23
image: serviceplant/goexp:0.0.28
ports:
- containerPort: 9040
name: metrics
@ -58,6 +62,7 @@ spec:
real_path=$(realpath ${MON_CONFIG})
initial_time=$(stat -c %Z "${real_path}")
while true; do
echo "I am watching!!!"
real_path=$(realpath ${MON_CONFIG})
latest_time=$(stat -c %Z "${real_path}")
@ -86,8 +91,8 @@ spec:
write_endpoints
# continuously update the mon endpoints if they fail over
exec /home/exporter
watch_endpoints &
exec /home/exporter &
watch_endpoints
imagePullPolicy: IfNotPresent
tty: true
securityContext:
@ -137,7 +142,7 @@ metadata:
rook_cluster: rook-ceph
spec:
selector:
app: export
app: export-box
ports:
- name: metrics
port: 9040

View File

@ -30,14 +30,16 @@ type RBDImageUsage struct {
UsedSize uint64 `json: "used_size"`
}
var fooMetric = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "foo_metric",
Help: "Show whether a foo has occured in a cluster",
})
var 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"},
)
var barMetric = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "bar_metric",
Help: "Show whether a bar has happened in a cluster",
var total_rbd_requested_size = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "total_rbd_requested_size",
Help: "total size of all RBDs in the cluster",
})
// Here I initialize logger and set some custom settings
@ -58,11 +60,12 @@ func init() {
logger = loggerInit()
logger.Info("Setting up logger is complete successfully")
logger.Info("Registering prom metrics")
prometheus.MustRegister(fooMetric)
prometheus.MustRegister(barMetric)
prometheus.MustRegister(
total_rbd_requested_size_per_pool,
total_rbd_requested_size,
)
fooMetric.Set(0)
barMetric.Set(1)
}
// List pools with application rbd enabled
@ -141,7 +144,7 @@ func getRBD(poolList []string) map[string][]string {
}
// Here I check total provisioned size of each RBD image in a pool
func RbdChecker(rbdMap map[string][]string) {
func RbdChecker(rbdMap map[string][]string) map[string][]RBDUsage{
total := make(map[string][]RBDUsage)
for pool, rbdlist := range rbdMap {
@ -152,12 +155,12 @@ func RbdChecker(rbdMap map[string][]string) {
}
}
fmt.Println(total)
logger.Debugf("Final map is %v",total)
return total
}
// Grabbing info about specific image
func GetRBDStats(pool string, rbdname string) RBDUsage {
logger.Infof("Calculating %s/%s", pool, rbdname)
rbdPath := fmt.Sprintf("%s/%s", pool, rbdname)
args := []string{"du", "--format", "json", rbdPath}
@ -177,6 +180,32 @@ func GetRBDStats(pool string, rbdname string) RBDUsage {
}
func FormMetrirs(rbdStats map[string][]RBDUsage) {
// this is requested size overall cluster
var totalSize uint64 = 0
// Iterate over pools
for poolName := range rbdStats {
var totalSizePerPool uint64 = 0
logger.Debugf("Forming metrics for pool %s",poolName)
//Iterate over all RBDs in the pool
for _,rbdName := range rbdStats[poolName] {
logger.Debugf("Processings rbd %v",rbdName)
totalSizePerPool = totalSizePerPool + rbdName.Images[0].RequestedSize
// logger.Debugf("RBD name is %s and its size is %d",rbdName.Images[0].Name,rbdName.Images[0].RequestedSize)
}
logger.Debugf("Total size requested by RBDs of a pool %s is %d bytes",poolName,totalSizePerPool)
total_rbd_requested_size_per_pool.WithLabelValues(
poolName,
).Set(float64(totalSizePerPool))
totalSize = totalSize + totalSizePerPool
}
logger.Debugf("Total size of all RBDs in a cluster is %d",totalSize)
total_rbd_requested_size.Set(float64(totalSize))
}
// the main loop for monitoting
func startCheking() {
@ -192,7 +221,10 @@ func startCheking() {
}
// Get the map of all RBDs in all pools
rbdMap := getRBD(poolList)
RbdChecker(rbdMap)
//Get all RBDs info
RBDStats := RbdChecker(rbdMap)
//Fill out metrics
FormMetrirs(RBDStats)
}
}