mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 02:09:28 +08:00
refactor findMaxReadsDevice to use disk.IOCounters
This commit is contained in:
@@ -658,36 +658,17 @@ func (a *Agent) closeIdleConnections(err error) (isTimeout bool) {
|
|||||||
// Returns the device with the most reads in /proc/diskstats
|
// Returns the device with the most reads in /proc/diskstats
|
||||||
// (fallback in case the root device is not supplied or detected)
|
// (fallback in case the root device is not supplied or detected)
|
||||||
func findMaxReadsDevice() string {
|
func findMaxReadsDevice() string {
|
||||||
content, err := os.ReadFile("/proc/diskstats")
|
var maxReadBytes uint64
|
||||||
if err != nil {
|
maxReadDevice := "/"
|
||||||
return "/"
|
counters, err := disk.IOCounters()
|
||||||
}
|
|
||||||
|
|
||||||
lines := strings.Split(string(content), "\n")
|
|
||||||
var maxReadsSectors int64
|
|
||||||
var maxReadsDevice string
|
|
||||||
|
|
||||||
for _, line := range lines {
|
|
||||||
fields := strings.Fields(line)
|
|
||||||
if len(fields) < 7 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceName := fields[2]
|
|
||||||
readsSectors, err := strconv.ParseInt(fields[5], 10, 64)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
return maxReadDevice
|
||||||
}
|
}
|
||||||
|
for _, d := range counters {
|
||||||
if readsSectors > maxReadsSectors {
|
if d.ReadBytes > maxReadBytes {
|
||||||
maxReadsSectors = readsSectors
|
maxReadBytes = d.ReadBytes
|
||||||
maxReadsDevice = deviceName
|
maxReadDevice = d.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return maxReadDevice
|
||||||
if maxReadsDevice == "" {
|
|
||||||
return "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
return maxReadsDevice
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user