From 76a7cf7e80086305d259bd203de98b5662abfb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Thu, 14 Oct 2021 10:35:01 +0200 Subject: [PATCH] chore: include runtime metrics --- routes/api/metrics.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/routes/api/metrics.go b/routes/api/metrics.go index 67e7f15..fce6499 100644 --- a/routes/api/metrics.go +++ b/routes/api/metrics.go @@ -36,7 +36,9 @@ const ( DescAdminTotalUsers = "Total number of registered users." DescAdminActiveUsers = "Number of active users." - DescGoroutines = "Total number of running goroutines" + DescMemAllocTotal = "Total number of bytes allocated for heap" + DescMemSysTotal = "Total number of bytes obtained from the OS" + DescGoroutines = "Total number of running goroutines" ) type MetricsHandler struct { @@ -211,6 +213,10 @@ func (h *MetricsHandler) getUserMetrics(user *models.User) (*mm.Metrics, error) }) } + // Runtime metrics + var memStats runtime.MemStats + runtime.ReadMemStats(&memStats) + metrics = append(metrics, &mm.CounterMetric{ Name: MetricsPrefix + "_goroutines_total", Desc: DescGoroutines, @@ -218,6 +224,20 @@ func (h *MetricsHandler) getUserMetrics(user *models.User) (*mm.Metrics, error) Labels: []mm.Label{}, }) + metrics = append(metrics, &mm.CounterMetric{ + Name: MetricsPrefix + "_mem_alloc_total", + Desc: DescMemAllocTotal, + Value: int(memStats.Alloc), + Labels: []mm.Label{}, + }) + + metrics = append(metrics, &mm.CounterMetric{ + Name: MetricsPrefix + "_mem_sys_total", + Desc: DescMemSysTotal, + Value: int(memStats.Sys), + Labels: []mm.Label{}, + }) + return &metrics, nil }