chore: include runtime metrics

This commit is contained in:
Ferdinand Mütsch 2021-10-14 10:35:01 +02:00
parent 7cae3c43d0
commit 76a7cf7e80
1 changed files with 21 additions and 1 deletions

View File

@ -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
}