代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。