2021-07-11 21:19:37 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-07-13 13:09:04 +00:00
|
|
|
"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"
|
2021-07-13 13:09:04 +00:00
|
|
|
"gitlab.com/gaming0skar123/go/pingbot/config"
|
2021-09-08 20:18:35 +00:00
|
|
|
"gitlab.com/gaming0skar123/go/pingbot/ping"
|
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-08-15 14:30:38 +00:00
|
|
|
mem := stats.Memory()
|
|
|
|
cpu, err := stats.CPU()
|
|
|
|
common.CheckErr(err, "cpu stat")
|
2021-07-22 08:23:49 +00:00
|
|
|
|
2021-09-08 20:18:35 +00:00
|
|
|
var p json
|
2021-07-31 20:59:43 +00:00
|
|
|
|
|
|
|
if config.Toml.Backend.Enabled {
|
2021-09-08 20:18:35 +00:00
|
|
|
p = json{
|
|
|
|
"all": ping.Status.Error + ping.Status.Success,
|
|
|
|
"success": ping.Status.Success,
|
2021-09-15 19:31:01 +00:00
|
|
|
"error": ping.Status.Error,
|
2021-07-31 20:59:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-09-08 20:18:35 +00:00
|
|
|
p = nil
|
2021-07-31 20:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, json{
|
2021-09-08 20:18:35 +00:00
|
|
|
"ping": p,
|
2021-07-24 09:50:17 +00:00
|
|
|
"sys": json{
|
2021-09-09 18:55:36 +00:00
|
|
|
"uptime": common.Uptime(config.StartTime),
|
|
|
|
"pid": cpu.PID,
|
|
|
|
"os": runtime.GOOS,
|
2021-09-15 19:31:01 +00:00
|
|
|
"memory": json{
|
2021-08-15 14:30:38 +00:00
|
|
|
"alloc": mem.Alloc,
|
|
|
|
"totalalloc": mem.TotalAlloc,
|
|
|
|
"sys": mem.Sys,
|
|
|
|
"numgc": mem.NumGC,
|
2021-07-22 08:23:49 +00:00
|
|
|
},
|
|
|
|
"cpu": json{
|
2021-08-15 14:30:38 +00:00
|
|
|
"usage": cpu.Usage,
|
|
|
|
"num": cpu.Num,
|
2021-08-15 17:49:57 +00:00
|
|
|
"arch": cpu.Arch,
|
2021-07-22 08:23:49 +00:00
|
|
|
},
|
2021-07-13 13:09:04 +00:00
|
|
|
},
|
2021-07-24 09:50:17 +00:00
|
|
|
"v": json{
|
|
|
|
"go": runtime.Version(),
|
|
|
|
"release": config.Version,
|
2021-08-01 15:48:24 +00:00
|
|
|
"build": config.Build,
|
2021-07-24 09:50:17 +00:00
|
|
|
},
|
2021-07-11 21:19:37 +00:00
|
|
|
})
|
|
|
|
}
|