Saturate resource limit to machine limit

This commit is contained in:
Victor Marmol 2014-06-13 14:56:41 -07:00
parent 48c81727dd
commit 406a15c954
3 changed files with 26 additions and 14 deletions

View File

@ -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 {

View File

@ -132,16 +132,16 @@ const containersHtmlTemplate = `
<h4>Usage Breakdown</h4>
<div class="col-sm-9">
<div class="progress">
<div class="progress-bar progress-bar-danger" style="width: {{getHotMemoryPercent .Spec .Stats}}%">
<div class="progress-bar progress-bar-danger" style="width: {{getHotMemoryPercent .Spec .Stats .MachineInfo}}%">
<span class="sr-only">Hot Memory</span>
</div>
<div class="progress-bar progress-bar-info" style="width: {{getColdMemoryPercent .Spec .Stats}}%">
<div class="progress-bar progress-bar-info" style="width: {{getColdMemoryPercent .Spec .Stats .MachineInfo}}%">
<span class="sr-only">Cold Memory</span>
</div>
</div>
</div>
<div class="col-sm-3">
{{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats }}%)
{{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats .MachineInfo}}%)
</div>
</div>
<h4>Page Faults</h4>

View File

@ -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.