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 | |
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
-rw-r--r-- | caddy/caddymain/run.go | 6 | ||||
-rw-r--r-- | telemetry/telemetry.go | 15 |
2 files changed, 18 insertions, 3 deletions
diff --git a/caddy/caddymain/run.go b/caddy/caddymain/run.go index e684c6fe3..4c8adcb4f 100644 --- a/caddy/caddymain/run.go +++ b/caddy/caddymain/run.go @@ -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) 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. |