Skip to content

Commit

Permalink
Merge pull request #1538 from nak3/output-host-disk-utilization2
Browse files Browse the repository at this point in the history
node-status outputs volumename instead of 0B utilization when non-physical volume is used
  • Loading branch information
diptanu committed Aug 10, 2016
2 parents f948205 + 5cbe16b commit d8dd52c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,22 +544,36 @@ func getHostResources(hostStats *api.HostStats, node *api.Node) ([]string, error
// calculate disk usage
storageDevice := node.Attributes["unique.storage.volume"]
var diskUsed, diskSize uint64
var physical bool
for _, disk := range hostStats.DiskStats {
if disk.Device == storageDevice {
diskUsed = disk.Used
diskSize = disk.Size
physical = true
}
}

resources = make([]string, 2)
resources[0] = "CPU|Memory|Disk"
resources[1] = fmt.Sprintf("%v/%v MHz|%v/%v|%v/%v",
math.Floor(hostStats.CPUTicksConsumed),
node.Resources.CPU,
humanize.IBytes(hostStats.Memory.Used),
humanize.IBytes(hostStats.Memory.Total),
humanize.IBytes(diskUsed),
humanize.IBytes(diskSize),
)
if physical {
resources[1] = fmt.Sprintf("%v/%v MHz|%v/%v|%v/%v",
math.Floor(hostStats.CPUTicksConsumed),
node.Resources.CPU,
humanize.IBytes(hostStats.Memory.Used),
humanize.IBytes(hostStats.Memory.Total),
humanize.IBytes(diskUsed),
humanize.IBytes(diskSize),
)
} else {
// If non-physical device are used, output device name only,
// since nomad doesn't collect the stats data.
resources[1] = fmt.Sprintf("%v/%v MHz|%v/%v|(%s)",
math.Floor(hostStats.CPUTicksConsumed),
node.Resources.CPU,
humanize.IBytes(hostStats.Memory.Used),
humanize.IBytes(hostStats.Memory.Total),
storageDevice,
)
}
return resources, nil
}

0 comments on commit d8dd52c

Please sign in to comment.