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

View File

@ -30,14 +30,16 @@ type RBDImageUsage struct {
UsedSize uint64 `json: "used_size"` UsedSize uint64 `json: "used_size"`
} }
var fooMetric = prometheus.NewGauge(prometheus.GaugeOpts{ var total_rbd_requested_size_per_pool = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "foo_metric", Name: "total_rbd_requested_size_per_pool",
Help: "Show whether a foo has occured in a cluster", Help: "total size of all requested RBDs in a specific pool",
}) },
[]string{"poolname"},
)
var barMetric = prometheus.NewGauge(prometheus.GaugeOpts{ var total_rbd_requested_size = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "bar_metric", Name: "total_rbd_requested_size",
Help: "Show whether a bar has happened in a cluster", Help: "total size of all RBDs in the cluster",
}) })
// Here I initialize logger and set some custom settings // Here I initialize logger and set some custom settings
@ -58,11 +60,12 @@ func init() {
logger = loggerInit() logger = loggerInit()
logger.Info("Setting up logger is complete successfully") logger.Info("Setting up logger is complete successfully")
logger.Info("Registering prom metrics") 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 // 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 // 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) total := make(map[string][]RBDUsage)
for pool, rbdlist := range rbdMap { 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 // Grabbing info about specific image
func GetRBDStats(pool string, rbdname string) RBDUsage { func GetRBDStats(pool string, rbdname string) RBDUsage {
logger.Infof("Calculating %s/%s", pool, rbdname)
rbdPath := fmt.Sprintf("%s/%s", pool, rbdname) rbdPath := fmt.Sprintf("%s/%s", pool, rbdname)
args := []string{"du", "--format", "json", rbdPath} 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 // the main loop for monitoting
func startCheking() { func startCheking() {
@ -192,7 +221,10 @@ func startCheking() {
} }
// Get the map of all RBDs in all pools // Get the map of all RBDs in all pools
rbdMap := getRBD(poolList) rbdMap := getRBD(poolList)
RbdChecker(rbdMap) //Get all RBDs info
RBDStats := RbdChecker(rbdMap)
//Fill out metrics
FormMetrirs(RBDStats)
} }
} }