From 48c81727ddc9fd24befb00b9556b285d101d8c34 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Fri, 13 Jun 2014 14:27:52 -0700 Subject: [PATCH 1/2] Remove unused function --- pages/containers.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pages/containers.go b/pages/containers.go index 60034cec..96a463ea 100644 --- a/pages/containers.go +++ b/pages/containers.go @@ -37,7 +37,6 @@ var funcMap = template.FuncMap{ "printMask": printMask, "printCores": printCores, "printMegabytes": printMegabytes, - "containerNameEquals": containerNameEquals, "getMemoryUsage": getMemoryUsage, "getMemoryUsagePercent": getMemoryUsagePercent, "getHotMemoryPercent": getHotMemoryPercent, @@ -85,10 +84,6 @@ func containerLink(container info.ContainerReference, basenameOnly bool, cssClas return template.HTML(fmt.Sprintf("%s", cssClasses, ContainersPage[:len(ContainersPage)-1], containerName, displayName)) } -func containerNameEquals(c1 string, c2 string) bool { - return c1 == c2 -} - func printMask(mask *info.CpuSpecMask, numCores int) interface{} { // TODO(vmarmol): Detect this correctly. // TODO(vmarmol): Support more than 64 cores. From 406a15c9547b1f53d3cf4b8265654e93f6e0f200 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Fri, 13 Jun 2014 14:56:41 -0700 Subject: [PATCH 2/2] Saturate resource limit to machine limit --- pages/containers.go | 22 ++++++++++++++-------- pages/containers_html.go | 6 +++--- pages/static/containers_js.go | 12 +++++++++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pages/containers.go b/pages/containers.go index 96a463ea..fc4ed5ea 100644 --- a/pages/containers.go +++ b/pages/containers.go @@ -125,25 +125,31 @@ func printMegabytes(bytes uint64) string { return strconv.FormatFloat(megabytes, 'f', 3, 64) } -func toMemoryPercent(usage uint64, spec *info.ContainerSpec) int { - return int((usage * 100) / (spec.Memory.Limit)) +func toMemoryPercent(usage uint64, spec *info.ContainerSpec, machine *info.MachineInfo) int { + // Saturate limit to the machine size. + limit := uint64(spec.Memory.Limit) + if limit > uint64(machine.MemoryCapacity) { + limit = uint64(machine.MemoryCapacity) + } + + return int((usage * 100) / limit) } func getMemoryUsage(stats []*info.ContainerStats) string { return strconv.FormatFloat(toMegabytes((stats[len(stats)-1].Memory.Usage)), 'f', 2, 64) } -func getMemoryUsagePercent(spec *info.ContainerSpec, stats []*info.ContainerStats) int { - return toMemoryPercent((stats[len(stats)-1].Memory.Usage), spec) +func getMemoryUsagePercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int { + return toMemoryPercent((stats[len(stats)-1].Memory.Usage), spec, machine) } -func getHotMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats) int { - return toMemoryPercent((stats[len(stats)-1].Memory.WorkingSet), spec) +func getHotMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int { + return toMemoryPercent((stats[len(stats)-1].Memory.WorkingSet), spec, machine) } -func getColdMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats) int { +func getColdMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int { latestStats := stats[len(stats)-1].Memory - return toMemoryPercent((latestStats.Usage)-(latestStats.WorkingSet), spec) + return toMemoryPercent((latestStats.Usage)-(latestStats.WorkingSet), spec, machine) } func ServerContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error { diff --git a/pages/containers_html.go b/pages/containers_html.go index 7e140e50..037aa3f4 100644 --- a/pages/containers_html.go +++ b/pages/containers_html.go @@ -132,16 +132,16 @@ const containersHtmlTemplate = `

Usage Breakdown

-
+
Hot Memory
-
+
Cold Memory
- {{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats }}%) + {{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats .MachineInfo}}%)

Page Faults

diff --git a/pages/static/containers_js.go b/pages/static/containers_js.go index 6bbc6e2e..b907b344 100644 --- a/pages/static/containers_js.go +++ b/pages/static/containers_js.go @@ -154,7 +154,7 @@ function drawCpuUsageBreakdown(elementId, containerInfo) { } // Draw the gauges for overall resource usage. -function drawOverallUsage(elementId, containerInfo) { +function drawOverallUsage(elementId, machineInfo, containerInfo) { var cur = containerInfo.stats[containerInfo.stats.length - 1]; var cpuUsage = 0; @@ -171,7 +171,13 @@ function drawOverallUsage(elementId, containerInfo) { var memoryUsage = 0; if (containerInfo.spec.memory) { - memoryUsage = Math.round((cur.memory.usage / containerInfo.spec.memory.limit) * 100); + // Saturate to the machine size. + var limit = containerInfo.spec.memory.limit; + if (limit > machineInfo.memory_capacity) { + limit = machineInfo.memory_capacity; + } + + memoryUsage = Math.round((cur.memory.usage / limit) * 100); } drawGauge(elementId, cpuUsage, memoryUsage); @@ -236,7 +242,7 @@ function drawCharts(machineInfo, containerInfo) { var steps = []; steps.push(function() { - drawOverallUsage("usage-gauge", containerInfo) + drawOverallUsage("usage-gauge", machineInfo, containerInfo) }); // CPU.