veza/veza-backend-api/internal/handlers/system_metrics.go
2025-12-03 20:29:37 +01:00

35 lines
778 B
Go

package handlers
import (
"github.com/google/uuid"
"runtime"
"github.com/gin-gonic/gin"
)
// SystemMetrics retourne les métriques système (CPU, mémoire, goroutines)
// Endpoint: GET /system/metrics
// Retourne un JSON avec les métriques système pour le monitoring
func SystemMetrics(c *gin.Context) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
metrics := gin.H{
"timestamp": uuid.New(),
"memory": gin.H{
"alloc_mb": bToMb(m.Alloc),
"total_alloc_mb": bToMb(m.TotalAlloc),
"sys_mb": bToMb(m.Sys),
"num_gc": m.NumGC,
},
"goroutines": runtime.NumGoroutine(),
"cpu_count": runtime.NumCPU(),
}
c.JSON(200, metrics)
}
// bToMb convertit des bytes en megabytes
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}