代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"gitee.com/liucxer/ceph-tools/pkg/ceph_cluster"
"gitee.com/liucxer/ceph-tools/pkg/csv"
"gitee.com/liucxer/ceph-tools/pkg/tools"
"github.com/sirupsen/logrus"
"os"
"strconv"
"sync"
"time"
)
func GetCephStatus(ipAddr string, count int) (ceph_cluster.CephStatusList, error) {
var (
err error
cephStatusList ceph_cluster.CephStatusList
cephStatusListMutex sync.Mutex
)
client, err := ceph_cluster.NewCluster(ipAddr)
if err != nil {
return cephStatusList, err
}
var wg sync.WaitGroup
for i := 0; i < count; i++ {
wg.Add(1)
time.Sleep(time.Second)
go func() {
defer func() { wg.Done() }()
cephStatus, err := client.CurrentCephStatus()
if err != nil {
return
}
logrus.Infof("cephStatus:%+v", cephStatus)
cephStatusListMutex.Lock()
cephStatusList = append(cephStatusList, *cephStatus)
cephStatusListMutex.Unlock()
}()
}
wg.Wait()
return cephStatusList, err
}
func main() {
tools.InitLog()
if len(os.Args) != 3 {
fmt.Println("Usage:\n ./cmd ipaddr count")
return
}
count, err := strconv.Atoi(os.Args[2])
if err != nil {
logrus.Errorf("strconv.Atoi(os.Args[2]) err:%v", err)
return
}
res, err := GetCephStatus(os.Args[1], count)
if err != nil {
return
}
logrus.Debugf("res:%+v", res)
logrus.Debugf("AvgRecoveringBytesPerSec:%f", res.AvgRecoveringBytesPerSec())
logrus.Debugf("AvgWriteOpPerSec:%f", res.AvgWriteOpPerSec())
logrus.Debugf("AvgReadOpPerSec:%f", res.AvgReadOpPerSec())
logrus.Debugf("RecoveryDistribution:%+v", res.RecoveryDistribution())
csvStr, err := csv.ObjectListToCsv(res)
if err != nil {
return
}
fmt.Println(csvStr)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。