fixed some errors from linter
This commit is contained in:
parent
20a59dceae
commit
54ce83f458
|
|
@ -34,12 +34,11 @@ func loggerInit() *zap.SugaredLogger {
|
||||||
|
|
||||||
// This func runs even before main()
|
// This func runs even before main()
|
||||||
func init() {
|
func init() {
|
||||||
|
configFile := flag.String("config", "/etc/ceph/ceph.conf", "placement of ceph config file")
|
||||||
config_file := flag.String("config", "/etc/ceph/ceph.conf", "placement of ceph config file")
|
|
||||||
_keyring := flag.String("keyring", "/etc/ceph/ceph.client.admin.keyring", "placement of ceph keyring file")
|
_keyring := flag.String("keyring", "/etc/ceph/ceph.client.admin.keyring", "placement of ceph keyring file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
params.Config = *config_file
|
params.Config = *configFile
|
||||||
params.Keyring = *_keyring
|
params.Keyring = *_keyring
|
||||||
|
|
||||||
mainlogger = loggerInit()
|
mainlogger = loggerInit()
|
||||||
|
|
@ -63,7 +62,7 @@ func main() {
|
||||||
|
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
|
||||||
// HTTP runs in separate thread cuz it blocks futher execution of main
|
// HTTP runs in separate thread cuz it blocks further execution of main
|
||||||
go func() {
|
go func() {
|
||||||
mainlogger.Info("Starting http server")
|
mainlogger.Info("Starting http server")
|
||||||
// Here I check for errors if HTTP fails
|
// Here I check for errors if HTTP fails
|
||||||
|
|
@ -77,5 +76,4 @@ func main() {
|
||||||
go metrics.GetMetrics(cephConn)
|
go metrics.GetMetrics(cephConn)
|
||||||
|
|
||||||
select {}
|
select {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"rbd_exporter/rbdfactory"
|
||||||
"rbd_exporter/RBDFactory"
|
|
||||||
"rbd_exporter/mytypes"
|
"rbd_exporter/mytypes"
|
||||||
"rbd_exporter/logger"
|
"rbd_exporter/logger"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -11,7 +10,6 @@ import (
|
||||||
|
|
||||||
|
|
||||||
func GetMetrics(cephConn mytypes.CephConnector) {
|
func GetMetrics(cephConn mytypes.CephConnector) {
|
||||||
|
|
||||||
metrics := InitMetrics()
|
metrics := InitMetrics()
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
metrics.Total_rbd_requested_size_per_pool,
|
metrics.Total_rbd_requested_size_per_pool,
|
||||||
|
|
@ -30,7 +28,7 @@ func GetMetrics(cephConn mytypes.CephConnector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range poolList {
|
for _, v := range poolList {
|
||||||
x, _ := RBDFactory.PoolFactory(cephConn, v)
|
x, _ := rbdfactory.PoolFactory(cephConn, v)
|
||||||
result = append(result, x)
|
result = append(result, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,9 +37,8 @@ func GetMetrics(cephConn mytypes.CephConnector) {
|
||||||
if !v.HasRBD {continue}
|
if !v.HasRBD {continue}
|
||||||
FillMetrics(v,metrics)
|
FillMetrics(v,metrics)
|
||||||
}
|
}
|
||||||
fmt.Println("====================")
|
logger.Logger.Debug("====================")
|
||||||
// fmt.Println(result)
|
// fmt.Println(result)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,5 +76,4 @@ func FillMetrics(pool mytypes.Pool,metrics *mytypes.Metrics) {
|
||||||
metrics.Total_rbd_requested_size_per_pool.WithLabelValues(pool.Name,
|
metrics.Total_rbd_requested_size_per_pool.WithLabelValues(pool.Name,
|
||||||
).Set(
|
).Set(
|
||||||
float64(totalSizePerPool))
|
float64(totalSizePerPool))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package RBDFactory
|
package rbdfactory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -18,12 +18,12 @@ func PoolFactory(cephConn mytypes.CephConnector, poolName string) (mytypes.Pool,
|
||||||
|
|
||||||
imageList, err := ioctx.GetImageNames()
|
imageList, err := ioctx.GetImageNames()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mytypes.Pool{}, fmt.Errorf("Couldn't get list of rbds %w", err)
|
return mytypes.Pool{}, fmt.Errorf("couldn't get list of rbds %w", err)
|
||||||
}
|
}
|
||||||
for _, rbdname := range imageList {
|
for _, rbdname := range imageList {
|
||||||
stat, err := RBDFacroty(ioctx, rbdname)
|
stat, err := RBDFacroty(ioctx, rbdname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("Coundn't get stat from disk %s %w", rbdname, err)
|
fmt.Errorf("coundn't get stat from disk %s %w", rbdname, err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
rbdlist = append(rbdlist, stat)
|
rbdlist = append(rbdlist, stat)
|
||||||
|
|
@ -38,7 +38,7 @@ func PoolFactory(cephConn mytypes.CephConnector, poolName string) (mytypes.Pool,
|
||||||
func RBDFacroty(ioctx mytypes.IOContexter, rbdname string) (mytypes.RBD, error) {
|
func RBDFacroty(ioctx mytypes.IOContexter, rbdname string) (mytypes.RBD, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if v := recover(); v != nil {
|
if v := recover(); v != nil {
|
||||||
logger.Logger.Errorf("No such RBD exists (probably just deleted)")
|
logger.Logger.Errorf("no such RBD exists (probably just deleted)")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ func RBDFacroty(ioctx mytypes.IOContexter, rbdname string) (mytypes.RBD, error)
|
||||||
|
|
||||||
info,err := image.Stat()
|
info,err := image.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mytypes.RBD{},fmt.Errorf("Couldn't get stats for image %s %w",rbdname,err)
|
return mytypes.RBD{},fmt.Errorf("couldn't get stats for image %s %w",rbdname,err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mytypes.RBD{
|
return mytypes.RBD{
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"rbd_exporter/RBDFactory"
|
"rbd_exporter/rbdfactory"
|
||||||
mock "rbd_exporter/mytypes/mock"
|
mock "rbd_exporter/mytypes/mock"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ func TestRBDFactory(t *testing.T) {
|
||||||
MockRBDImager.EXPECT().Stat().Return(expectedImageInfo,nil)
|
MockRBDImager.EXPECT().Stat().Return(expectedImageInfo,nil)
|
||||||
|
|
||||||
|
|
||||||
result,err := RBDFactory.RBDFacroty(MockIOContexter,rbdName)
|
result,err := rbdfactory.RBDFacroty(MockIOContexter,rbdName)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, rbdName, result.Name)
|
assert.Equal(t, rbdName, result.Name)
|
||||||
|
|
@ -62,7 +62,7 @@ func TestPoolFactory(t *testing.T) {
|
||||||
mockImage.EXPECT().Stat().Return(expectedImageInfo, nil)
|
mockImage.EXPECT().Stat().Return(expectedImageInfo, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := RBDFactory.PoolFactory(mockCephConn, poolName)
|
result, err := rbdfactory.PoolFactory(mockCephConn, poolName)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, poolName, result.Name)
|
assert.Equal(t, poolName, result.Name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user