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