mirror of https://github.com/MedzikUser/go-pingbot
chore(utils): update 2/2
This commit is contained in:
parent
ae22397b9e
commit
4095092cca
1
go.mod
1
go.mod
|
@ -18,7 +18,6 @@ require (
|
||||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.1 // 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/ugorji/go v1.2.6 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // 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 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
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.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 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM=
|
||||||
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
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=
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/MedzikUser/go-utils/common"
|
"github.com/MedzikUser/go-utils/common"
|
||||||
|
"github.com/MedzikUser/go-utils/stats"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/struCoder/pidusage"
|
|
||||||
"gitlab.com/gaming0skar123/go/pingbot/backend"
|
"gitlab.com/gaming0skar123/go/pingbot/backend"
|
||||||
"gitlab.com/gaming0skar123/go/pingbot/config"
|
"gitlab.com/gaming0skar123/go/pingbot/config"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +16,9 @@ func Status(c *gin.Context) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
|
|
||||||
pid := os.Getpid()
|
mem := stats.Memory()
|
||||||
|
cpu, err := stats.CPU()
|
||||||
|
common.CheckErr(err, "cpu stat")
|
||||||
|
|
||||||
var ping json
|
var ping json
|
||||||
|
|
||||||
|
@ -35,18 +35,18 @@ func Status(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, json{
|
c.JSON(http.StatusOK, json{
|
||||||
"ping": ping,
|
"ping": ping,
|
||||||
"sys": json{
|
"sys": json{
|
||||||
"pid": pid,
|
"pid": os.Getpid(),
|
||||||
"os": runtime.GOOS,
|
"os": runtime.GOOS,
|
||||||
"mem": json{
|
"mem": json{
|
||||||
"alloc": mb(m.Alloc),
|
"alloc": mem.Alloc,
|
||||||
"totalalloc": mb(m.TotalAlloc),
|
"totalalloc": mem.TotalAlloc,
|
||||||
"sys": mb(m.Sys),
|
"sys": mem.Sys,
|
||||||
"numgc": m.NumGC,
|
"numgc": mem.NumGC,
|
||||||
},
|
},
|
||||||
"cpu": json{
|
"cpu": json{
|
||||||
"usage": cpu(pid),
|
"usage": cpu.Usage,
|
||||||
"num": runtime.NumCPU(),
|
"num": cpu.Num,
|
||||||
"arch": runtime.GOARCH,
|
"arch": cpu.Usage,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"v": json{
|
"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 New Issue