Skip to content

Commit

Permalink
Merge pull request #202 from skruger/memory_usage_stats
Browse files Browse the repository at this point in the history
Report memory usage and correct CPU percentage in heartbeat messages
  • Loading branch information
myzhan authored May 11, 2024
2 parents edd5204 + ce46146 commit 07b7994
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,11 @@ func (r *slaveRunner) run() {
}
// send client heartbeat message
CPUUsage := GetCurrentCPUUsage()
MemUsage := GetCurrentMemUsage()
data := map[string]interface{}{
"state": r.state,
"current_cpu_usage": CPUUsage,
"state": r.state,
"current_cpu_usage": CPUUsage,
"current_memory_usage": MemUsage,
}
r.client.sendChannel() <- newGenericMessage("heartbeat", data, r.nodeID)
case <-r.shutdownChan:
Expand Down
6 changes: 6 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,9 @@ func GetCurrentCPUUsage() float64 {
}
return percent / float64(runtime.NumCPU())
}

func GetCurrentMemUsage() uint64 {
var m runtime.MemStats
runtime.ReadMemStats(&m)
return m.Alloc
}

0 comments on commit 07b7994

Please sign in to comment.