This commit is contained in:
a.pivkin
2025-12-22 07:57:42 +03:00
parent af4a1c46e1
commit 2e19663a63
37 changed files with 935 additions and 258 deletions
+2 -2
View File
@@ -28,7 +28,7 @@ func PoolFactory(cephConn CephConnector, poolName string) (Pool, error) {
}
return Pool{
Name: poolName,
hasRBD: len(imageList) != 0,
HasRBD: len(imageList) != 0,
RBDlist: rbdlist,
}, nil
}
@@ -36,7 +36,7 @@ func PoolFactory(cephConn CephConnector, poolName string) (Pool, error) {
func RBDFacroty(ioctx IOContexter, rbdname string) (RBD, error) {
defer func() {
if v := recover(); v != nil {
fmt.Println("Shit happened")
fmt.Println("Shit happened in RBDFactory")
}
}()
+2 -2
View File
@@ -20,12 +20,12 @@ func connect() (_ CephConnection, err error) {
return CephConnection{}, err
}
err = cephConn.conn.ReadConfigFile(params.config)
err = cephConn.conn.ReadConfigFile(params.Config)
if err != nil {
return CephConnection{}, err
}
err = cephConn.conn.SetConfigOption("keyring", params.keyring)
err = cephConn.conn.SetConfigOption("keyring", params.Keyring)
if err != nil {
return CephConnection{}, err
}
+2 -2
View File
@@ -16,8 +16,8 @@ func init() {
_keyring := flag.String("keyring", "/etc/ceph/ceph.client.admin.keyring", "placement of ceph keyring file")
flag.Parse()
params.config = *config_file
params.keyring = *_keyring
params.Config = *config_file
params.Keyring = *_keyring
logger = loggerInit()
logger.Info("Setting up logger is complete successfully")
+2 -11
View File
@@ -3,19 +3,11 @@ module main.go
go 1.25.5
require (
github.com/ceph/go-ceph v0.36.0
github.com/ceph/go-ceph v0.37.0
github.com/prometheus/client_golang v1.23.2
go.uber.org/zap v1.27.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@@ -23,9 +15,8 @@ require (
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/stretchr/testify v1.11.1
go.uber.org/multierr v1.10.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/sys v0.36.0 // indirect
golang.org/x/sys v0.38.0 // indirect
google.golang.org/protobuf v1.36.8 // indirect
)
+6 -8
View File
@@ -1,13 +1,13 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/ceph/go-ceph v0.36.0 h1:IDE4vEF+4fmjve+CPjD1WStgfQ+Lh6vD+9PMUI712KI=
github.com/ceph/go-ceph v0.36.0/go.mod h1:fGCbndVDLuHW7q2954d6y+tgPFOBnRLqJRe2YXyngw4=
github.com/ceph/go-ceph v0.37.0 h1:KXliBe3ZDr3/AtfY7n9d1MG7ippYNCVhMPcAgm05CFI=
github.com/ceph/go-ceph v0.37.0/go.mod h1:3y2tOlITlyuVFhy8v6PpCEfjMwKPfXJiH0/2hKZZQRE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofrs/uuid/v5 v5.3.2 h1:2jfO8j3XgSwlz/wHqemAEugfnTlikAYHhnqQ8Xh4fE0=
github.com/gofrs/uuid/v5 v5.3.2/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0=
github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
@@ -32,8 +32,6 @@ github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzM
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -44,8 +42,8 @@ go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+3 -4
View File
@@ -6,7 +6,6 @@ import (
"net/http"
"os"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
@@ -19,7 +18,7 @@ func getMetrics(cephConn CephConnector) {
metrics := InitMetrics()
prometheus.MustRegister(
metrics.total_rbd_requested_size_per_pool,
metrics.Total_rbd_requested_size_per_pool,
)
ticker := time.NewTicker(2 * time.Second)
@@ -39,9 +38,9 @@ func getMetrics(cephConn CephConnector) {
result = append(result, x)
}
metrics.total_rbd_requested_size_per_pool.Reset()
metrics.Total_rbd_requested_size_per_pool.Reset()
for _,v := range result {
if !v.hasRBD {continue}
if !v.HasRBD {continue}
FillMetrics(v,metrics)
}
fmt.Println("====================")
+3 -3
View File
@@ -6,7 +6,7 @@ import (
func InitMetrics() *Metrics {
m := &Metrics{
total_rbd_requested_size_per_pool: prometheus.NewGaugeVec(
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",
@@ -30,11 +30,11 @@ func FillMetrics(pool Pool,metrics *Metrics) {
logger.Debugf("Processing pool %s",pool.Name)
for _,v := range pool.RBDlist {
totalSizePerPool += uint64(v.getSize())
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,
metrics.Total_rbd_requested_size_per_pool.WithLabelValues(pool.Name,
).Set(
float64(totalSizePerPool))
-66
View File
@@ -1,66 +0,0 @@
package main
import (
"github.com/ceph/go-ceph/rbd"
"github.com/stretchr/testify/mock"
)
// MockCephConnector
type MockCephConnector struct {
mock.Mock
}
func (m *MockCephConnector) ListPools() ([]string, error) {
args := m.Called()
return args.Get(0).([]string), args.Error(1)
}
func (m *MockCephConnector) OpenIOContext(poolName string) (IOContexter, error) {
args := m.Called(poolName)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(IOContexter), args.Error(1)
}
// MockIOContexter
type MockIOContexter struct {
mock.Mock
}
func (m *MockIOContexter) Destroy() {
m.Called()
}
func (m *MockIOContexter) GetImageNames() ([]string, error) {
args := m.Called()
return args.Get(0).([]string), args.Error(1)
}
func (m *MockIOContexter) GetImage(name string) RBDImager {
args := m.Called(name)
return args.Get(0).(RBDImager)
}
// MockRBDImager
type MockRBDImager struct {
mock.Mock
}
func (m *MockRBDImager) Open() error {
args := m.Called()
return args.Error(0)
}
func (m *MockRBDImager) Close() error {
args := m.Called()
return args.Error(0)
}
func (m *MockRBDImager) Stat() (*rbd.ImageInfo, error) {
args := m.Called()
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*rbd.ImageInfo), args.Error(1)
}
+9 -9
View File
@@ -7,8 +7,8 @@ import (
)
type Params struct {
config string
keyring string
Config string
Keyring string
}
type CephConnector interface {
@@ -82,8 +82,8 @@ func (riw RBDImageWrapper) Stat() (*rbd.ImageInfo,error) {
}
type iRBD interface {
getName() string
getSize() int64
GetName() string
GetSize() int64
}
type RBDUsage struct {
@@ -95,21 +95,21 @@ type RBD struct {
rbd.ImageInfo
}
func (r RBD) getName() string {
func (r RBD) GetName() string {
return r.Name
}
func (r RBD) getSize() int64 {
func (r RBD) GetSize() int64 {
return int64(r.Size)
}
type Pool struct {
Name string
hasRBD bool
HasRBD bool
RBDlist []iRBD
}
type Metrics struct {
total_rbd_requested_size_per_pool *prometheus.GaugeVec
total_rbd_requested_size prometheus.Gauge
Total_rbd_requested_size_per_pool *prometheus.GaugeVec
Total_rbd_requested_size prometheus.Gauge
}