Merge pull request #44 from vmarmol/fix-root
Fix root resource percent display
This commit is contained in:
commit
a3264170d3
@ -37,7 +37,6 @@ var funcMap = template.FuncMap{
|
|||||||
"printMask": printMask,
|
"printMask": printMask,
|
||||||
"printCores": printCores,
|
"printCores": printCores,
|
||||||
"printMegabytes": printMegabytes,
|
"printMegabytes": printMegabytes,
|
||||||
"containerNameEquals": containerNameEquals,
|
|
||||||
"getMemoryUsage": getMemoryUsage,
|
"getMemoryUsage": getMemoryUsage,
|
||||||
"getMemoryUsagePercent": getMemoryUsagePercent,
|
"getMemoryUsagePercent": getMemoryUsagePercent,
|
||||||
"getHotMemoryPercent": getHotMemoryPercent,
|
"getHotMemoryPercent": getHotMemoryPercent,
|
||||||
@ -85,10 +84,6 @@ func containerLink(container info.ContainerReference, basenameOnly bool, cssClas
|
|||||||
return template.HTML(fmt.Sprintf("<a class=\"%s\" href=\"%s%s\">%s</a>", cssClasses, ContainersPage[:len(ContainersPage)-1], containerName, displayName))
|
return template.HTML(fmt.Sprintf("<a class=\"%s\" href=\"%s%s\">%s</a>", 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{} {
|
func printMask(mask *info.CpuSpecMask, numCores int) interface{} {
|
||||||
// TODO(vmarmol): Detect this correctly.
|
// TODO(vmarmol): Detect this correctly.
|
||||||
// TODO(vmarmol): Support more than 64 cores.
|
// TODO(vmarmol): Support more than 64 cores.
|
||||||
@ -130,25 +125,31 @@ func printMegabytes(bytes uint64) string {
|
|||||||
return strconv.FormatFloat(megabytes, 'f', 3, 64)
|
return strconv.FormatFloat(megabytes, 'f', 3, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toMemoryPercent(usage uint64, spec *info.ContainerSpec) int {
|
func toMemoryPercent(usage uint64, spec *info.ContainerSpec, machine *info.MachineInfo) int {
|
||||||
return int((usage * 100) / (spec.Memory.Limit))
|
// 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 {
|
func getMemoryUsage(stats []*info.ContainerStats) string {
|
||||||
return strconv.FormatFloat(toMegabytes((stats[len(stats)-1].Memory.Usage)), 'f', 2, 64)
|
return strconv.FormatFloat(toMegabytes((stats[len(stats)-1].Memory.Usage)), 'f', 2, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMemoryUsagePercent(spec *info.ContainerSpec, stats []*info.ContainerStats) int {
|
func getMemoryUsagePercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int {
|
||||||
return toMemoryPercent((stats[len(stats)-1].Memory.Usage), spec)
|
return toMemoryPercent((stats[len(stats)-1].Memory.Usage), spec, machine)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHotMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats) int {
|
func getHotMemoryPercent(spec *info.ContainerSpec, stats []*info.ContainerStats, machine *info.MachineInfo) int {
|
||||||
return toMemoryPercent((stats[len(stats)-1].Memory.WorkingSet), spec)
|
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
|
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 {
|
func ServerContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error {
|
||||||
|
@ -132,16 +132,16 @@ const containersHtmlTemplate = `
|
|||||||
<h4>Usage Breakdown</h4>
|
<h4>Usage Breakdown</h4>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<div class="progress">
|
<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>
|
<span class="sr-only">Hot Memory</span>
|
||||||
</div>
|
</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>
|
<span class="sr-only">Cold Memory</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
{{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats }}%)
|
{{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats .MachineInfo}}%)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h4>Page Faults</h4>
|
<h4>Page Faults</h4>
|
||||||
|
@ -154,7 +154,7 @@ function drawCpuUsageBreakdown(elementId, containerInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw the gauges for overall resource usage.
|
// 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 cur = containerInfo.stats[containerInfo.stats.length - 1];
|
||||||
|
|
||||||
var cpuUsage = 0;
|
var cpuUsage = 0;
|
||||||
@ -171,7 +171,13 @@ function drawOverallUsage(elementId, containerInfo) {
|
|||||||
|
|
||||||
var memoryUsage = 0;
|
var memoryUsage = 0;
|
||||||
if (containerInfo.spec.memory) {
|
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);
|
drawGauge(elementId, cpuUsage, memoryUsage);
|
||||||
@ -236,7 +242,7 @@ function drawCharts(machineInfo, containerInfo) {
|
|||||||
var steps = [];
|
var steps = [];
|
||||||
|
|
||||||
steps.push(function() {
|
steps.push(function() {
|
||||||
drawOverallUsage("usage-gauge", containerInfo)
|
drawOverallUsage("usage-gauge", machineInfo, containerInfo)
|
||||||
});
|
});
|
||||||
|
|
||||||
// CPU.
|
// CPU.
|
||||||
|
Loading…
Reference in New Issue
Block a user