Skip to content

Commit

Permalink
Merge pull request kubernetes#129 from vmarmol/reliable-ui
Browse files Browse the repository at this point in the history
Handle empty stats in the UI.
  • Loading branch information
monnand committed Jul 25, 2014
2 parents 02b06ea + 1921c1d commit c1fefb7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pages/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,30 @@ func toMemoryPercent(usage uint64, spec *info.ContainerSpec, machine *info.Machi
}

func getMemoryUsage(stats []*info.ContainerStats) string {
if len(stats) == 0 {
return "0.0"
}
return strconv.FormatFloat(toMegabytes((stats[len(stats)-1].Memory.Usage)), 'f', 2, 64)
}

func getMemoryUsagePercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int {
if len(stats) == 0 {
return 0
}
return toMemoryPercent((stats[len(stats)-1].Memory.Usage), spec, machine)
}

func getHotMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int {
if len(stats) == 0 {
return 0
}
return toMemoryPercent((stats[len(stats)-1].Memory.WorkingSet), spec, machine)
}

func getColdMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int {
if len(stats) == 0 {
return 0
}
latestStats := stats[len(stats)-1].Memory
return toMemoryPercent((latestStats.Usage)-(latestStats.WorkingSet), spec, machine)
}
Expand Down

0 comments on commit c1fefb7

Please sign in to comment.