Implement worker status
This commit is contained in:
parent
cf000931e4
commit
0be5af70c3
5 changed files with 62 additions and 1 deletions
31
worker/status.go
Normal file
31
worker/status.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mackerelio/go-osstat/cpu"
|
||||
"github.com/mackerelio/go-osstat/memory"
|
||||
|
||||
"git.lastassault.de/speatzle/morffix/rpc"
|
||||
"git.lastassault.de/speatzle/morffix/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rpcServer.RegisterMethod("status", status)
|
||||
}
|
||||
|
||||
func status(ctx context.Context, req rpc.Request) (any, error) {
|
||||
s := types.WorkerStatus{}
|
||||
cStats, _ := cpu.Get()
|
||||
if cStats != nil {
|
||||
s.CPUUsage = cStats.Total
|
||||
s.CPUCount = uint64(cStats.CPUCount)
|
||||
}
|
||||
mStats, _ := memory.Get()
|
||||
if mStats != nil {
|
||||
s.MemoryUsage = mStats.Used
|
||||
s.MemoryTotal = mStats.Total
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue