mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-24 22:22:35 +02:00
fix(systeminfo): divide by zero on disk I/O speed calculation
This commit is contained in:
parent
3dbab118af
commit
fc8592ab45
1 changed files with 3 additions and 3 deletions
|
@ -166,11 +166,11 @@ func (s *SystemInfo) collectDisksInfo(ctx context.Context, lastResult *SystemInf
|
||||||
}
|
}
|
||||||
s.DisksIO = ioCounters
|
s.DisksIO = ioCounters
|
||||||
if lastResult != nil {
|
if lastResult != nil {
|
||||||
interval := float64(time.Now().Unix() - lastResult.Timestamp)
|
interval := time.Now().Unix() - lastResult.Timestamp
|
||||||
for name, disk := range s.DisksIO {
|
for name, disk := range s.DisksIO {
|
||||||
if lastUsage, ok := lastResult.DisksIO[name]; ok {
|
if lastUsage, ok := lastResult.DisksIO[name]; ok {
|
||||||
disk.ReadSpeed = float64(disk.ReadBytes-lastUsage.ReadBytes) / interval
|
disk.ReadSpeed = float64(disk.ReadBytes-lastUsage.ReadBytes) / float64(interval)
|
||||||
disk.WriteSpeed = float64(disk.WriteBytes-lastUsage.WriteBytes) / interval
|
disk.WriteSpeed = float64(disk.WriteBytes-lastUsage.WriteBytes) / float64(interval)
|
||||||
disk.Iops = (disk.ReadCount + disk.WriteCount - lastUsage.ReadCount - lastUsage.WriteCount) / uint64(interval)
|
disk.Iops = (disk.ReadCount + disk.WriteCount - lastUsage.ReadCount - lastUsage.WriteCount) / uint64(interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue