Add per-disk IO performance monitoring
This commit is contained in:
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -17,6 +19,22 @@ func TestIsPhysicalDiskName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadDiskIOStats(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "diskstats")
|
||||
data := " 8 0 sda 100 2 300 40 50 3 700 80 4 90 120 0 0 0 0 0 0\n 7 0 loop0 999 0 999 0 999 0 999 0 0 0 0\n"
|
||||
if err := os.WriteFile(path, []byte(data), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stats := readDiskIOStats(path)
|
||||
disk, ok := stats["sda"]
|
||||
if !ok || disk.reads != 100 || disk.readSectors != 300 || disk.writes != 50 || disk.writeSectors != 700 || disk.inFlight != 4 || disk.ioMS != 90 || disk.weightedMS != 120 {
|
||||
t.Fatalf("unexpected stats: %+v", disk)
|
||||
}
|
||||
if _, exists := stats["loop0"]; exists {
|
||||
t.Fatal("virtual device must be ignored")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSumFilesystemUsage(t *testing.T) {
|
||||
device := lsblkDevice{Children: []lsblkDevice{
|
||||
{FSUsed: json.RawMessage(`100`), FSAvail: json.RawMessage(`300`)},
|
||||
|
||||
Reference in New Issue
Block a user