mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-28 13:48:49 +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:
commit
12199ad2d7
@ -5,6 +5,7 @@ package disk
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -280,6 +281,11 @@ func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|||||||
ret := make(map[string]IOCountersStat, 0)
|
ret := make(map[string]IOCountersStat, 0)
|
||||||
empty := IOCountersStat{}
|
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 {
|
for _, line := range lines {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) < 14 {
|
if len(fields) < 14 {
|
||||||
|
@ -25,6 +25,8 @@ func TestDisk_partitions(t *testing.T) {
|
|||||||
if err != nil || len(ret) == 0 {
|
if err != nil || len(ret) == 0 {
|
||||||
t.Errorf("error %v", err)
|
t.Errorf("error %v", err)
|
||||||
}
|
}
|
||||||
|
t.Log(ret)
|
||||||
|
|
||||||
empty := PartitionStat{}
|
empty := PartitionStat{}
|
||||||
if len(ret) == 0 {
|
if len(ret) == 0 {
|
||||||
t.Errorf("ret is empty")
|
t.Errorf("ret is empty")
|
||||||
@ -46,6 +48,7 @@ func TestDisk_io_counters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
empty := IOCountersStat{}
|
empty := IOCountersStat{}
|
||||||
for part, io := range ret {
|
for part, io := range ret {
|
||||||
|
t.Log(part, io)
|
||||||
if io == empty {
|
if io == empty {
|
||||||
t.Errorf("io_counter error %v, %v", part, io)
|
t.Errorf("io_counter error %v, %v", part, io)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user