forked from cerc-io/plugeth
metrics: removed repetitive calculations (#16944)
This commit is contained in:
parent
9f7592c802
commit
b487bdf0ba
@ -68,17 +68,20 @@ func CollectProcessMetrics(refresh time.Duration) {
|
|||||||
}
|
}
|
||||||
// Iterate loading the different stats and updating the meters
|
// Iterate loading the different stats and updating the meters
|
||||||
for i := 1; ; i++ {
|
for i := 1; ; i++ {
|
||||||
runtime.ReadMemStats(memstats[i%2])
|
location1 := i%2
|
||||||
memAllocs.Mark(int64(memstats[i%2].Mallocs - memstats[(i-1)%2].Mallocs))
|
location2 := (i-1)%2
|
||||||
memFrees.Mark(int64(memstats[i%2].Frees - memstats[(i-1)%2].Frees))
|
|
||||||
memInuse.Mark(int64(memstats[i%2].Alloc - memstats[(i-1)%2].Alloc))
|
|
||||||
memPauses.Mark(int64(memstats[i%2].PauseTotalNs - memstats[(i-1)%2].PauseTotalNs))
|
|
||||||
|
|
||||||
if ReadDiskStats(diskstats[i%2]) == nil {
|
runtime.ReadMemStats(memstats[location1])
|
||||||
diskReads.Mark(diskstats[i%2].ReadCount - diskstats[(i-1)%2].ReadCount)
|
memAllocs.Mark(int64(memstats[location1].Mallocs - memstats[location2].Mallocs))
|
||||||
diskReadBytes.Mark(diskstats[i%2].ReadBytes - diskstats[(i-1)%2].ReadBytes)
|
memFrees.Mark(int64(memstats[location1].Frees - memstats[location2].Frees))
|
||||||
diskWrites.Mark(diskstats[i%2].WriteCount - diskstats[(i-1)%2].WriteCount)
|
memInuse.Mark(int64(memstats[location1].Alloc - memstats[location2].Alloc))
|
||||||
diskWriteBytes.Mark(diskstats[i%2].WriteBytes - diskstats[(i-1)%2].WriteBytes)
|
memPauses.Mark(int64(memstats[location1].PauseTotalNs - memstats[location2].PauseTotalNs))
|
||||||
|
|
||||||
|
if ReadDiskStats(diskstats[location1]) == nil {
|
||||||
|
diskReads.Mark(diskstats[location1].ReadCount - diskstats[location2].ReadCount)
|
||||||
|
diskReadBytes.Mark(diskstats[location1].ReadBytes - diskstats[location2].ReadBytes)
|
||||||
|
diskWrites.Mark(diskstats[location1].WriteCount - diskstats[location2].WriteCount)
|
||||||
|
diskWriteBytes.Mark(diskstats[location1].WriteBytes - diskstats[location2].WriteBytes)
|
||||||
}
|
}
|
||||||
time.Sleep(refresh)
|
time.Sleep(refresh)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user