Skip to content

Commit 4f821b2

Browse files
committed
number of cpus included
1 parent 43f0f12 commit 4f821b2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

swarmpit/task/stats.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type DiskStatus struct {
3737

3838
type CpuStatus struct {
3939
UsedPercentage float64 `json:"usedPercentage"`
40+
Cores int `json:"cores"`
4041
}
4142

4243
type MemoryStatus struct {
@@ -63,11 +64,6 @@ func getPath() string {
6364
return "/"
6465
}
6566

66-
func getNodeId(cli *client.Client) string {
67-
resp, _ := cli.Info(context.Background())
68-
return resp.Swarm.NodeID
69-
}
70-
7167
func DiskUsage() (ds DiskStatus) {
7268
diskStat, err := disk.Usage(getPath())
7369
if err != nil {
@@ -81,7 +77,7 @@ func DiskUsage() (ds DiskStatus) {
8177
return
8278
}
8379

84-
func CpuUsage() (cs CpuStatus) {
80+
func CpuUsage(cpuCores int) (cs CpuStatus) {
8581
percentage, err := cpu.Percent(0, true)
8682
if err != nil {
8783
return
@@ -94,6 +90,7 @@ func CpuUsage() (cs CpuStatus) {
9490

9591
cpuPercentage = cpuPercentAll / (float64(len(percentage)))
9692
cs.UsedPercentage = cpuPercentage
93+
cs.Cores = cpuCores
9794
return
9895
}
9996

@@ -180,12 +177,13 @@ func ContainerUsage(cli *client.Client, id string) (status ContainerStatus) {
180177
func HandleStats(cli *client.Client) {
181178
for {
182179
<-time.After(time.Duration(arg.StatsFrequency) * time.Second)
180+
resp, _ := cli.Info(context.Background())
183181

182+
var id = resp.Swarm.NodeID
184183
var memory = MemoryUsage()
185184
var disk = DiskUsage()
186-
var cpu = CpuUsage()
185+
var cpu = CpuUsage(resp.NCPU)
187186
var tasks = ContainersUsage(cli)
188-
var id = getNodeId(cli)
189187

190188
status := Status{Id: id, Disk: disk, Cpu: cpu, Memory: memory, Tasks: tasks}
191189
swarmpit.SendEvent(swarmpit.STATS, status)

0 commit comments

Comments
 (0)