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 }