2021-07-11 21:19:37 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-07-13 13:09:04 +00:00
|
|
|
"fmt"
|
2021-07-11 21:19:37 +00:00
|
|
|
"net/http"
|
2021-07-13 13:09:04 +00:00
|
|
|
"runtime"
|
2021-07-11 21:19:37 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"gitlab.com/gaming0skar123/go/pingbot/backend"
|
2021-07-13 13:09:04 +00:00
|
|
|
"gitlab.com/gaming0skar123/go/pingbot/config"
|
2021-07-11 21:19:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Status(c *gin.Context) {
|
2021-07-13 13:09:04 +00:00
|
|
|
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{
|
2021-07-12 10:52:44 +00:00
|
|
|
"all": backend.AmountSuccess + backend.AmountErr,
|
2021-07-11 21:19:37 +00:00
|
|
|
"success": backend.AmountSuccess,
|
|
|
|
"err": backend.AmountErr,
|
|
|
|
},
|
2021-07-13 13:09:04 +00:00
|
|
|
"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
|
|
|
})
|
|
|
|
}
|
2021-07-13 13:09:04 +00:00
|
|
|
|
|
|
|
func MB(b uint64) string {
|
|
|
|
return fmt.Sprintf("%d MB", b/1000/1000)
|
|
|
|
}
|