62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package stat
|
|
|
|
import (
|
|
"io"
|
|
"bufio"
|
|
"strings"
|
|
"fmt"
|
|
)
|
|
|
|
type DiskIOStat struct {
|
|
device,
|
|
readCompleted,
|
|
readMerged,
|
|
sectorRead,
|
|
timeSpentReading,
|
|
writesCompleted,
|
|
writesMerged,
|
|
sectorsWritten,
|
|
timeSpentWriting,
|
|
ioInProg,
|
|
timeSpentIO,
|
|
weightedTimeSpentIO string
|
|
}
|
|
|
|
func (diskio DiskIOStat) Command() string {
|
|
return "cat /proc/diskstats"
|
|
}
|
|
|
|
func (diskio DiskIOStat) Parse(r io.Reader) ([]DiskIOStat, error) {
|
|
var (
|
|
DiskIOStats = []DiskIOStat{}
|
|
scanner = bufio.NewScanner(r)
|
|
)
|
|
|
|
for scanner.Scan() {
|
|
parts := strings.Fields(scanner.Text())
|
|
if len(parts) < 4 {
|
|
return nil, fmt.Errorf("invalid line in %s: %s", "/proc/diskstats", scanner.Text())
|
|
}
|
|
deviceName := parts[2]
|
|
if !strings.HasPrefix(deviceName, "sd") {
|
|
continue
|
|
}
|
|
DiskIOStats = append(DiskIOStats, DiskIOStat{
|
|
device: deviceName,
|
|
readCompleted: parts[3],
|
|
readMerged: parts[4],
|
|
sectorRead: parts[5],
|
|
timeSpentReading: parts[6],
|
|
writesCompleted: parts[7],
|
|
writesMerged: parts[8],
|
|
sectorsWritten: parts[9],
|
|
timeSpentWriting: parts[10],
|
|
ioInProg: parts[11],
|
|
timeSpentIO: parts[12],
|
|
weightedTimeSpentIO: parts[13],
|
|
})
|
|
|
|
}
|
|
|
|
return DiskIOStats, scanner.Err()
|
|
} |