Merge pull request #2 from vitalif/master

Use strings.Repeat because fmt.Sprintf counts escape chars
master
rumanzo 2019-02-28 00:14:16 +03:00 committed by GitHub
commit 3d86dbc33b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 13 deletions

View File

@ -73,26 +73,48 @@ func bench(cephconn *Cephconnection, osddevice Device, buffs *[][]byte, startbuf
green := color.New(color.FgHiGreen).SprintFunc() green := color.New(color.FgHiGreen).SprintFunc()
darkgreen := color.New(color.FgGreen).SprintFunc() darkgreen := color.New(color.FgGreen).SprintFunc()
buffer.WriteString(fmt.Sprintf("Bench result for %v\n", osddevice.Name)) buffer.WriteString(fmt.Sprintf("Bench result for %v\n", osddevice.Name))
infos := map[string]string{"front_addr": strings.Split(osddevice.Info.FrontAddr, "/")[0], infos := map[string]string{
"ceph_release/version": osddevice.Info.CephRelease + "/" + osddevice.Info.CephVersionShort, "cpu": osddevice.Info.CPU, "front_addr": strings.Split(osddevice.Info.FrontAddr, "/")[0],
"hostname": osddevice.Info.Hostname, "default_device_class": osddevice.Info.DefaultDeviceClass, "devices": osddevice.Info.Devices, "ceph_release/version": osddevice.Info.CephRelease + "/" + osddevice.Info.CephVersionShort,
"distro_description": osddevice.Info.DistroDescription, "journal_rotational": osddevice.Info.JournalRotational, "cpu": osddevice.Info.CPU,
"rotational": osddevice.Info.Rotational, "kernel_version": osddevice.Info.KernelVersion, "mem_swap_kb": osddevice.Info.MemSwapKb, "hostname": osddevice.Info.Hostname,
"mem_total_kb": osddevice.Info.MemTotalKb, "osd_data": osddevice.Info.OsdData, "osd_objectstore": osddevice.Info.OsdObjectstore} "default_device_class": osddevice.Info.DefaultDeviceClass,
infonum := 1 "devices": osddevice.Info.Devices,
"distro_description": osddevice.Info.DistroDescription,
"journal_rotational": osddevice.Info.JournalRotational,
"rotational": osddevice.Info.Rotational,
"kernel_version": osddevice.Info.KernelVersion,
"mem_swap_kb": osddevice.Info.MemSwapKb,
"mem_total_kb": osddevice.Info.MemTotalKb,
"osd_data": osddevice.Info.OsdData,
"osd_objectstore": osddevice.Info.OsdObjectstore,
}
var infokeys []string var infokeys []string
width := []int{0, 0, 0, 0, 0, 0}
for k := range infos { for k := range infos {
infokeys = append(infokeys, k) infokeys = append(infokeys, k)
} }
sort.Strings(infokeys) sort.Strings(infokeys)
buffer.WriteString(fmt.Sprintf("%-30v %-45v", darkgreen("osdname"), red(osddevice.Name))) for n, key := range infokeys {
for _, key := range infokeys { if width[n % 3] < len(key) {
infonum++ width[n % 3] = len(key)
buffer.WriteString(fmt.Sprintf("%-30v %-45v", darkgreen(key), yellow(infos[key]))) }
if (infonum % 3) == 0 { if width[3 + n % 3] < len(infos[key]) {
buffer.WriteString("\n") width[3 + n % 3] = len(infos[key])
} }
} }
buffer.WriteString(
darkgreen("osdname") + strings.Repeat(" ", width[2]-len("osdname")+2) +
red(osddevice.Name) + strings.Repeat(" ", width[5]-len(osddevice.Name)+2))
for infonum, key := range infokeys {
if (infonum % 3) == 2 {
buffer.WriteString("\n")
}
buffer.WriteString(
darkgreen(key) + strings.Repeat(" ", width[infonum % 3]-len(key)+2) +
yellow(infos[key]) + strings.Repeat(" ", width[3 + infonum % 3]-len(infos[key])+2))
}
buffer.WriteString("\n\n")
latencytotal = latencytotal / int64(len(osdlatencies)) latencytotal = latencytotal / int64(len(osdlatencies))
// iops = 1s / latency // iops = 1s / latency