telemetry: Add memory and goroutine metrics, rename container

And fix a typo in a comment, sigh
This commit is contained in:
Matthew Holt 2018-05-09 22:36:23 -06:00
parent 86fd2f22fb
commit df7cdc3fae
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
2 changed files with 18 additions and 3 deletions

View file

@ -40,6 +40,7 @@ import (
"log"
"math/rand"
"net/http"
"runtime"
"strconv"
"strings"
"sync"
@ -66,6 +67,9 @@ func emit(final bool) error {
return fmt.Errorf("telemetry not enabled")
}
// some metrics are updated/set at time of emission
setEmitTimeMetrics()
// ensure only one update happens at a time;
// skip update if previous one still in progress
updateMu.Lock()
@ -228,6 +232,17 @@ func stopUpdateTimer() {
updateTimerMu.Unlock()
}
// setEmitTimeMetrics sets some metrics that should
// be recorded just before emitting.
func setEmitTimeMetrics() {
Set("goroutines", runtime.NumGoroutine())
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
SetNested("memory", "heap_alloc", mem.HeapAlloc)
SetNested("memory", "sys", mem.Sys)
}
// makePayloadAndResetBuffer prepares a payload
// by emptying the collection buffer. It returns
// the bytes of the payload to send to the server.