go-pingbot/website/routes/api/status.go

37 lines
699 B
Go
Raw Normal View History

2021-07-11 21:19:37 +00:00
package api
import (
"fmt"
2021-07-11 21:19:37 +00:00
"net/http"
"runtime"
2021-07-11 21:19:37 +00:00
"github.com/gin-gonic/gin"
"gitlab.com/gaming0skar123/go/pingbot/backend"
"gitlab.com/gaming0skar123/go/pingbot/config"
2021-07-11 21:19:37 +00:00
)
func Status(c *gin.Context) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
2021-07-11 21:19:37 +00:00
c.JSON(http.StatusOK, gin.H{
"success": true,
"ping": gin.H{
"all": backend.AmountSuccess + backend.AmountErr,
2021-07-11 21:19:37 +00:00
"success": backend.AmountSuccess,
"err": backend.AmountErr,
},
"mem": gin.H{
"alloc": MB(m.Alloc),
"totalalloc": MB(m.TotalAlloc),
"sys": MB(m.Sys),
"numgc": m.NumGC,
},
"v": config.Version,
2021-07-11 21:19:37 +00:00
})
}
func MB(b uint64) string {
return fmt.Sprintf("%d MB", b/1000/1000)
}