Fix disk/network IO measurements
This commit is contained in:
parent
6a384732e7
commit
bccc177374
13
main.go
13
main.go
@ -55,6 +55,8 @@ var (
|
|||||||
blockers []string
|
blockers []string
|
||||||
currentStatus ResourceUsage
|
currentStatus ResourceUsage
|
||||||
nvmlAvailable bool
|
nvmlAvailable bool
|
||||||
|
networkBytesIO uint64
|
||||||
|
diskBytesIO uint64
|
||||||
lastBlockedTime time.Time
|
lastBlockedTime time.Time
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -267,12 +269,19 @@ func updateCurrentUsage() {
|
|||||||
for _, stat := range diskStats {
|
for _, stat := range diskStats {
|
||||||
totalIO += stat.ReadBytes + stat.WriteBytes
|
totalIO += stat.ReadBytes + stat.WriteBytes
|
||||||
}
|
}
|
||||||
usage.DiskIO = float64(totalIO)
|
|
||||||
|
previousDiskBytesIO := diskBytesIO
|
||||||
|
diskBytesIO = totalIO
|
||||||
|
diff := diskBytesIO - previousDiskBytesIO
|
||||||
|
usage.DiskIO = float64(diff) / checkInterval.Seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get network I/O
|
// Get network I/O
|
||||||
if netStats, err := net.IOCounters(false); err == nil && len(netStats) > 0 {
|
if netStats, err := net.IOCounters(false); err == nil && len(netStats) > 0 {
|
||||||
usage.NetworkIO = float64(netStats[0].BytesSent + netStats[0].BytesRecv)
|
previousNetworkBytesIO := networkBytesIO
|
||||||
|
networkBytesIO = netStats[0].BytesSent + netStats[0].BytesRecv
|
||||||
|
diff := networkBytesIO - previousNetworkBytesIO
|
||||||
|
usage.NetworkIO = float64(diff) / checkInterval.Seconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count SSH connections
|
// Count SSH connections
|
||||||
|
Loading…
x
Reference in New Issue
Block a user