1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

Merge pull request #481 from shirou/feature/use_basename_for_iocounters

[disk]linux: use basename such as sda1 for IOCounters
This commit is contained in:
shirou 2018-01-09 11:17:27 +09:00 committed by GitHub
commit 12199ad2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -5,6 +5,7 @@ package disk
import (
"fmt"
"os/exec"
"path/filepath"
"strconv"
"strings"
@ -280,6 +281,11 @@ func IOCounters(names ...string) (map[string]IOCountersStat, error) {
ret := make(map[string]IOCountersStat, 0)
empty := IOCountersStat{}
// use only basename such as "/dev/sda1" to "sda1"
for i, name := range names {
names[i] = filepath.Base(name)
}
for _, line := range lines {
fields := strings.Fields(line)
if len(fields) < 14 {

View File

@ -25,6 +25,8 @@ func TestDisk_partitions(t *testing.T) {
if err != nil || len(ret) == 0 {
t.Errorf("error %v", err)
}
t.Log(ret)
empty := PartitionStat{}
if len(ret) == 0 {
t.Errorf("ret is empty")
@ -46,6 +48,7 @@ func TestDisk_io_counters(t *testing.T) {
}
empty := IOCountersStat{}
for part, io := range ret {
t.Log(part, io)
if io == empty {
t.Errorf("io_counter error %v, %v", part, io)
}