diff options
author | Matthew Holt <[email protected]> | 2018-05-09 22:36:23 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2018-05-09 22:36:23 -0600 |
commit | df7cdc3faea8e2b85172b697ef8a8f95a0cc50d7 (patch) | |
tree | f1c15f5dea952b769d14eeb8a7dc2b1f87053610 /telemetry/telemetry.go | |
parent | 86fd2f22fb0752a5c977300f224ef93e1d9cf5b1 (diff) | |
download | caddy-df7cdc3faea8e2b85172b697ef8a8f95a0cc50d7.tar.gz caddy-df7cdc3faea8e2b85172b697ef8a8f95a0cc50d7.zip |
telemetry: Add memory and goroutine metrics, rename container
And fix a typo in a comment, sigh
Diffstat (limited to 'telemetry/telemetry.go')
-rw-r--r-- | telemetry/telemetry.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 183ee6ea7..df29ad336 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -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. |