mirror of
https://github.com/MedzikUser/go-pingbot
synced 2024-08-14 23:57:07 +00:00
chore(utils): update 2/2
This commit is contained in:
parent
ae22397b9e
commit
4095092cca
3 changed files with 12 additions and 30 deletions
1
go.mod
1
go.mod
|
@ -18,7 +18,6 @@ require (
|
|||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/struCoder/pidusage v0.2.1
|
||||
github.com/ugorji/go v1.2.6 // indirect
|
||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -61,8 +61,6 @@ github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzF
|
|||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
|
||||
github.com/gin-gonic/gin v1.7.3 h1:aMBzLJ/GMEYmv1UWs2FFTcPISLrQH2mRgL9Glz8xows=
|
||||
github.com/gin-gonic/gin v1.7.3/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
||||
github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
|
||||
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/MedzikUser/go-utils/common"
|
||||
"github.com/MedzikUser/go-utils/stats"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/struCoder/pidusage"
|
||||
"gitlab.com/gaming0skar123/go/pingbot/backend"
|
||||
"gitlab.com/gaming0skar123/go/pingbot/config"
|
||||
)
|
||||
|
@ -18,7 +16,9 @@ func Status(c *gin.Context) {
|
|||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
|
||||
pid := os.Getpid()
|
||||
mem := stats.Memory()
|
||||
cpu, err := stats.CPU()
|
||||
common.CheckErr(err, "cpu stat")
|
||||
|
||||
var ping json
|
||||
|
||||
|
@ -35,18 +35,18 @@ func Status(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, json{
|
||||
"ping": ping,
|
||||
"sys": json{
|
||||
"pid": pid,
|
||||
"pid": os.Getpid(),
|
||||
"os": runtime.GOOS,
|
||||
"mem": json{
|
||||
"alloc": mb(m.Alloc),
|
||||
"totalalloc": mb(m.TotalAlloc),
|
||||
"sys": mb(m.Sys),
|
||||
"numgc": m.NumGC,
|
||||
"alloc": mem.Alloc,
|
||||
"totalalloc": mem.TotalAlloc,
|
||||
"sys": mem.Sys,
|
||||
"numgc": mem.NumGC,
|
||||
},
|
||||
"cpu": json{
|
||||
"usage": cpu(pid),
|
||||
"num": runtime.NumCPU(),
|
||||
"arch": runtime.GOARCH,
|
||||
"usage": cpu.Usage,
|
||||
"num": cpu.Num,
|
||||
"arch": cpu.Usage,
|
||||
},
|
||||
},
|
||||
"v": json{
|
||||
|
@ -61,18 +61,3 @@ func Status(c *gin.Context) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func mb(b uint64) string {
|
||||
return fmt.Sprintf("%d MB", b/1000/1000)
|
||||
}
|
||||
|
||||
func cpu(pid int) *string {
|
||||
sysInfo, err := pidusage.GetStat(pid)
|
||||
if common.CheckErr(err, "get cpu stat") {
|
||||
return nil
|
||||
}
|
||||
|
||||
s := fmt.Sprint(math.Round(sysInfo.CPU*100)/100, "%")
|
||||
|
||||
return &s
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue