1 Star 0 Fork 0

liucxer / ceph-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cluster.go 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
liu.changxi@datatom.com 提交于 2021-11-03 11:08 . init
package ceph
import (
"encoding/json"
"gitee.com/liucxer/ceph-tools/pkg/ceph_cluster"
"gitee.com/liucxer/ceph-tools/pkg/interfacer"
"github.com/sirupsen/logrus"
"sync"
"time"
)
func GetCephStatus(worker interfacer.Worker) (ceph_cluster.CephStatus, error) {
var (
err error
res ceph_cluster.CephStatus
)
type CephStatusResp struct {
PGMap ceph_cluster.CephStatus `json:"pgmap"`
}
resp, err := worker.ExecCmd("ceph status -f json")
if err != nil {
return res, err
}
var cephStatusResp CephStatusResp
err = json.Unmarshal(resp, &cephStatusResp)
if err != nil {
logrus.Errorf("CurrentCephStatus json.Unmarshal. err:%v", err)
return res, err
}
res = cephStatusResp.PGMap
return res, nil
}
func ListCephStatus(worker interfacer.Worker, runtime int64) (*ceph_cluster.CephStatusList, error) {
var (
err error
cephStatusList ceph_cluster.CephStatusList
cephStatusListMutex sync.Mutex
)
var wg sync.WaitGroup
for i := 0; i < int(runtime); i++ {
wg.Add(1)
time.Sleep(time.Second)
go func() {
defer func() { wg.Done() }()
cephStatus, err := GetCephStatus(worker)
if err != nil {
return
}
cephStatusListMutex.Lock()
cephStatusList = append(cephStatusList, cephStatus)
cephStatusListMutex.Unlock()
}()
}
wg.Wait()
return &cephStatusList, err
}
1
https://gitee.com/liucxer/ceph-tools.git
git@gitee.com:liucxer/ceph-tools.git
liucxer
ceph-tools
ceph-tools
db53517fcc53

搜索帮助