Commit df7cdc3f authored by Matthew Holt's avatar Matthew Holt

telemetry: Add memory and goroutine metrics, rename container

And fix a typo in a comment, sigh
parent 86fd2f22
......@@ -172,7 +172,7 @@ func Run() {
AESNI: cpuid.CPU.AesNi(),
})
if containerized := detectContainer(); containerized {
telemetry.Set("in_container", containerized)
telemetry.Set("container", containerized)
}
telemetry.StartEmitting()
......@@ -299,7 +299,7 @@ func setCPU(cpu string) error {
return nil
}
// detectContainer attemps to determine whether the process is
// detectContainer attempts to determine whether the process is
// being run inside a container. References:
// https://tuhrig.de/how-to-know-you-are-inside-a-docker-container/
// https://stackoverflow.com/a/20012536/1048862
......@@ -397,7 +397,7 @@ func initTelemetry() error {
// initialize telemetry
telemetry.Init(id, disabledMetricsSlice)
// if any metrics were disabled, report it
// if any metrics were disabled, report which ones (so we know how representative the data is)
if len(disabledMetricsSlice) > 0 {
telemetry.Set("disabled_metrics", disabledMetricsSlice)
log.Printf("[NOTICE] The following telemetry metrics are disabled: %s", disabledMetrics)
......
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment