aboutsummaryrefslogtreecommitdiffstats
path: root/metrics/metrics.go
diff options
context:
space:
mode:
authorClayton Jacobs <clayton.michael.jacobs@gmail.com>2018-06-11 19:45:25 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-06-11 19:45:25 +0800
commitb487bdf0ba21f1877501a9bdd97f84701273e022 (patch)
treeb25f768f3c78c47c97cadaadedc812426464972b /metrics/metrics.go
parent9f7592c802838b5be7b95b3b8b063178813bb3bb (diff)
downloadgo-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.tar
go-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.tar.gz
go-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.tar.bz2
go-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.tar.lz
go-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.tar.xz
go-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.tar.zst
go-tangerine-b487bdf0ba21f1877501a9bdd97f84701273e022.zip
metrics: removed repetitive calculations (#16944)
Diffstat (limited to 'metrics/metrics.go')
-rw-r--r--metrics/metrics.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/metrics/metrics.go b/metrics/metrics.go
index e24324814..11203ccdc 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -68,17 +68,20 @@ func CollectProcessMetrics(refresh time.Duration) {
}
// Iterate loading the different stats and updating the meters
for i := 1; ; i++ {
- runtime.ReadMemStats(memstats[i%2])
- memAllocs.Mark(int64(memstats[i%2].Mallocs - memstats[(i-1)%2].Mallocs))
- 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))
+ location1 := i%2
+ location2 := (i-1)%2
- if ReadDiskStats(diskstats[i%2]) == nil {
- diskReads.Mark(diskstats[i%2].ReadCount - diskstats[(i-1)%2].ReadCount)
- diskReadBytes.Mark(diskstats[i%2].ReadBytes - diskstats[(i-1)%2].ReadBytes)
- diskWrites.Mark(diskstats[i%2].WriteCount - diskstats[(i-1)%2].WriteCount)
- diskWriteBytes.Mark(diskstats[i%2].WriteBytes - diskstats[(i-1)%2].WriteBytes)
+ runtime.ReadMemStats(memstats[location1])
+ memAllocs.Mark(int64(memstats[location1].Mallocs - memstats[location2].Mallocs))
+ memFrees.Mark(int64(memstats[location1].Frees - memstats[location2].Frees))
+ memInuse.Mark(int64(memstats[location1].Alloc - memstats[location2].Alloc))
+ 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)
}