aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-06-17 15:53:17 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-06-17 15:53:17 +0800
commit5298eb7519ab6b3762f561b1473815bc8cb24265 (patch)
treee54962f4655b0ff3672635daa42b7799e1d74b42
parent79c90dce200185b6199076ef7ae87f2ad71c3008 (diff)
downloadgo-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.tar
go-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.tar.gz
go-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.tar.bz2
go-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.tar.lz
go-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.tar.xz
go-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.tar.zst
go-tangerine-5298eb7519ab6b3762f561b1473815bc8cb24265.zip
metrics: gather and export threads and goroutines
-rw-r--r--metrics/metrics.go42
1 files changed, 21 insertions, 21 deletions
diff --git a/metrics/metrics.go b/metrics/metrics.go
index 98e8ced25..8ab4e28f2 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -73,28 +73,26 @@ func CollectProcessMetrics(refresh time.Duration) {
diskstats[i] = new(DiskStats)
}
// Define the various metrics to collect
- cpuSysLoad := GetOrRegisterGauge("system/cpu/sysload", DefaultRegistry)
- cpuSysWait := GetOrRegisterGauge("system/cpu/syswait", DefaultRegistry)
- cpuProcLoad := GetOrRegisterGauge("system/cpu/procload", DefaultRegistry)
-
- memPauses := GetOrRegisterMeter("system/memory/pauses", DefaultRegistry)
- memAllocs := GetOrRegisterMeter("system/memory/allocs", DefaultRegistry)
- memFrees := GetOrRegisterMeter("system/memory/frees", DefaultRegistry)
- memHeld := GetOrRegisterGauge("system/memory/held", DefaultRegistry)
- memUsed := GetOrRegisterGauge("system/memory/used", DefaultRegistry)
-
- var diskReads, diskReadBytes, diskWrites, diskWriteBytes Meter
- var diskReadBytesCounter, diskWriteBytesCounter Counter
- if err := ReadDiskStats(diskstats[0]); err == nil {
- diskReads = GetOrRegisterMeter("system/disk/readcount", DefaultRegistry)
- diskReadBytes = GetOrRegisterMeter("system/disk/readdata", DefaultRegistry)
- diskReadBytesCounter = GetOrRegisterCounter("system/disk/readbytes", DefaultRegistry)
- diskWrites = GetOrRegisterMeter("system/disk/writecount", DefaultRegistry)
- diskWriteBytes = GetOrRegisterMeter("system/disk/writedata", DefaultRegistry)
+ var (
+ cpuSysLoad = GetOrRegisterGauge("system/cpu/sysload", DefaultRegistry)
+ cpuSysWait = GetOrRegisterGauge("system/cpu/syswait", DefaultRegistry)
+ cpuProcLoad = GetOrRegisterGauge("system/cpu/procload", DefaultRegistry)
+ cpuThreads = GetOrRegisterGauge("system/cpu/threads", DefaultRegistry)
+ cpuGoroutines = GetOrRegisterGauge("system/cpu/goroutines", DefaultRegistry)
+
+ memPauses = GetOrRegisterMeter("system/memory/pauses", DefaultRegistry)
+ memAllocs = GetOrRegisterMeter("system/memory/allocs", DefaultRegistry)
+ memFrees = GetOrRegisterMeter("system/memory/frees", DefaultRegistry)
+ memHeld = GetOrRegisterGauge("system/memory/held", DefaultRegistry)
+ memUsed = GetOrRegisterGauge("system/memory/used", DefaultRegistry)
+
+ diskReads = GetOrRegisterMeter("system/disk/readcount", DefaultRegistry)
+ diskReadBytes = GetOrRegisterMeter("system/disk/readdata", DefaultRegistry)
+ diskReadBytesCounter = GetOrRegisterCounter("system/disk/readbytes", DefaultRegistry)
+ diskWrites = GetOrRegisterMeter("system/disk/writecount", DefaultRegistry)
+ diskWriteBytes = GetOrRegisterMeter("system/disk/writedata", DefaultRegistry)
diskWriteBytesCounter = GetOrRegisterCounter("system/disk/writebytes", DefaultRegistry)
- } else {
- log.Debug("Failed to read disk metrics", "err", err)
- }
+ )
// Iterate loading the different stats and updating the meters
for i := 1; ; i++ {
location1 := i % 2
@@ -104,6 +102,8 @@ func CollectProcessMetrics(refresh time.Duration) {
cpuSysLoad.Update((cpuStats[location1].GlobalTime - cpuStats[location2].GlobalTime) / refreshFreq)
cpuSysWait.Update((cpuStats[location1].GlobalWait - cpuStats[location2].GlobalWait) / refreshFreq)
cpuProcLoad.Update((cpuStats[location1].LocalTime - cpuStats[location2].LocalTime) / refreshFreq)
+ cpuThreads.Update(int64(threadCreateProfile.Count()))
+ cpuGoroutines.Update(int64(runtime.NumGoroutine()))
runtime.ReadMemStats(memstats[location1])
memPauses.Mark(int64(memstats[location1].PauseTotalNs - memstats[location2].PauseTotalNs))