1 Star 0 Fork 0

liucxer/ceph-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
liu.changxi@datatom.com 提交于 3年前 . update
package main
import (
"encoding/json"
"fmt"
"gitee.com/liucxer/ceph-tools/pkg/ceph_cluster"
"gitee.com/liucxer/ceph-tools/pkg/csv"
"gitee.com/liucxer/ceph-tools/pkg/tools"
"io/ioutil"
"os"
"time"
"gitee.com/liucxer/ceph-tools/pkg/ceph"
"github.com/sirupsen/logrus"
)
type ExecConfig struct {
ThreadNums int64 `json:"threadNums"`
OsdNum []int64 `json:"osdNum"`
IpAddr string `json:"ipAddr"`
Runtime int64 `json:"runtime"`
*ceph_cluster.CephCluster
*ceph.CephConf
}
func (execConfig *ExecConfig) ReadExecConfig(configFilePath string) error {
bts, err := ioutil.ReadFile(configFilePath)
if err != nil {
logrus.Errorf("ioutil.ReadFile err:%v", err)
return err
}
err = json.Unmarshal(bts, execConfig)
if err != nil {
logrus.Errorf("json.Unmarshal err:%v", err)
return err
}
return nil
}
func (execConfig *ExecConfig) Run() (ceph.JobCostList, error) {
var (
err error
jobcostList ceph.JobCostList
)
jobcostList, err = ceph.GetJobCostListByOsdNums(execConfig.Master, execConfig.OsdNum, execConfig.ThreadNums)
if err != nil {
return jobcostList, err
}
return jobcostList, err
}
func main() {
tools.InitLog()
if len(os.Args) != 2 {
fmt.Println("Usage:\n ./cmd config.json")
return
}
execConfig := ExecConfig{}
err := execConfig.ReadExecConfig(os.Args[1])
if err != nil {
return
}
cluster, err := ceph_cluster.NewCluster(execConfig.IpAddr)
if err != nil {
return
}
defer func() { _ = cluster.Close() }()
execConfig.CephCluster = cluster
execConfig.CephConf, err = ceph.NewCephConf(execConfig.Master, execConfig.OsdNum)
if err != nil {
return
}
var jobCostList ceph.JobCostList
for i := 0; i < int(execConfig.Runtime); i++ {
item, err := execConfig.Run()
if err != nil {
continue
}
jobCostList = append(jobCostList, item...)
time.Sleep(10 * time.Second)
}
res, err := csv.ObjectListToCsv(jobCostList)
if err != nil {
return
}
resultPath := "result.csv"
err = ioutil.WriteFile(resultPath, []byte(res), os.ModePerm)
if err != nil {
return
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liucxer/ceph-tools.git
git@gitee.com:liucxer/ceph-tools.git
liucxer
ceph-tools
ceph-tools
ed01591ec671

搜索帮助