Skip to content

Commit

Permalink
feat: 增加go内存统计
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Dec 5, 2023
1 parent 394f9be commit 7c0c0fd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/workhub/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func detail(c *gin.Context) {
if id, err := send.Stat(); err == nil {
rq := workhub.WaitResponse(id, 30)
if rq.Success {
c.Set("Payload", gin.H{"Stat": rq.Payload})
c.Set("Payload", rq.Payload)
} else {
c.Set("Error", rq.Message)
}
Expand Down
10 changes: 7 additions & 3 deletions api/workhub/founder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package workhub

import (
"runtime"

"github.com/gin-gonic/gin"
"github.com/opentdp/go-helper/psutil"
)
Expand All @@ -16,9 +18,11 @@ func host(c *gin.Context) {
return
}

stat := psutil.Detail(rq.WithAddr)

c.Set("Payload", gin.H{"Stat": stat})
c.Set("Payload", gin.H{
"Stat": psutil.Detail(rq.WithAddr),
"MemStats": psutil.GoMemory(),
"NumGoroutine": runtime.NumGoroutine(),
})

}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/knadh/koanf/providers/file v0.1.0
github.com/knadh/koanf/v2 v2.0.1
// 辅助类库
github.com/opentdp/go-helper v0.4.6
github.com/opentdp/go-helper v0.4.7
// 计划任务
github.com/robfig/cron/v3 v3.0.1
// Go 官方模块
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/opentdp/go-helper v0.4.6 h1:rUcj0tx4dr6n7A2uqGJj4fsAPlkBMChou4/EMfhAQE4=
github.com/opentdp/go-helper v0.4.6/go.mod h1:H3qhSAcclbDAQd3XlR4k109vAdypJL3thcW8XkMLhoQ=
github.com/opentdp/go-helper v0.4.7 h1:3uMwfFXASgkSUo6uHCdGdmvlYBG62NFs4BhiGHkEtjo=
github.com/opentdp/go-helper v0.4.7/go.mod h1:H3qhSAcclbDAQd3XlR4k109vAdypJL3thcW8XkMLhoQ=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
8 changes: 7 additions & 1 deletion module/worker/recv_stat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package worker

import (
"runtime"

"github.com/opentdp/go-helper/logman"
"github.com/opentdp/go-helper/psutil"
"github.com/opentdp/go-helper/socket"
Expand All @@ -16,7 +18,11 @@ func (pod *RecvPod) Stat(rq *socket.PlainData) error {
Method: "Stat:resp",
TaskId: rq.TaskId,
Success: true,
Payload: psutil.Detail(true),
Payload: map[string]any{
"Stat": psutil.Detail(true),
"MemStats": psutil.GoMemory(),
"NumGoroutine": runtime.NumGoroutine(),
},
})

return err
Expand Down

0 comments on commit 7c0c0fd

Please sign in to comment.