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

64 lines
1.2 KiB
Go
Raw Normal View History

2021-07-11 21:19:37 +00:00
package api
import (
"net/http"
"os"
"runtime"
2021-07-11 21:19:37 +00:00
2021-08-12 19:26:54 +00:00
"github.com/MedzikUser/go-utils/common"
2021-08-15 14:30:38 +00:00
"github.com/MedzikUser/go-utils/stats"
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-08-15 14:30:38 +00:00
mem := stats.Memory()
cpu, err := stats.CPU()
common.CheckErr(err, "cpu stat")
var ping json
if config.Toml.Backend.Enabled {
ping = json{
2021-07-29 18:51:15 +00:00
"all": backend.Status.Error + backend.Status.Success,
"success": backend.Status.Success,
"err": backend.Status.Error,
}
} else {
ping = nil
}
c.JSON(http.StatusOK, json{
"ping": ping,
"sys": json{
2021-08-15 14:30:38 +00:00
"pid": os.Getpid(),
"os": runtime.GOOS,
"mem": json{
2021-08-15 14:30:38 +00:00
"alloc": mem.Alloc,
"totalalloc": mem.TotalAlloc,
"sys": mem.Sys,
"numgc": mem.NumGC,
},
"cpu": json{
2021-08-15 14:30:38 +00:00
"usage": cpu.Usage,
"num": cpu.Num,
"arch": cpu.Usage,
},
},
"v": json{
"go": runtime.Version(),
"release": config.Version,
"build": config.Build,
},
"node": json{
"cluster": config.Toml.Cluster.ID,
"node": config.Toml.Cluster.Node,
2021-08-12 21:00:37 +00:00
"uptime": common.Uptime(config.StartTime),
},
2021-07-11 21:19:37 +00:00
})
}