1 Star 0 Fork 0

liucxer/ceph-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
liu.changxi@datatom.com 提交于 2021-11-21 16:30 . global逻辑处理
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)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liucxer/ceph-tools.git
git@gitee.com:liucxer/ceph-tools.git
liucxer
ceph-tools
ceph-tools
3b55481ed94f

搜索帮助