Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
fix: adjust resources html template
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <christian.kotzbauer@gmail.com>
  • Loading branch information
ckotzbauer committed Oct 3, 2021
1 parent 8b56301 commit 74651cc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 18 deletions.
78 changes: 67 additions & 11 deletions pkg/resources/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,78 @@ var HtmlPage = `
<tr>
<th>Namespace</th>
<th>Pod</th>
<th>Memory Requests</th>
<th>Memory Limits</th>
<th>CPU Requests</th>
<th>CPU Limits</th>
<th>Container</th>
<th> </th>
<th>Current value</th>
<th>Min value</th>
<th>Average value</th>
<th>Max value</th>
</tr>
</thead>
<tbody>
{{range .Items}}
{{range $pod := .Items}}
{{range $container := $pod.Containers}}
<tr>
<td>{{.Namespace}}</td>
<td>{{.Pod}}</td>
<td>{{.MemoryRequests.Min.FormatMemory}}<br>{{.MemoryRequests.Avg.FormatMemory}}<br>{{.MemoryRequests.Max.FormatMemory}}</td>
<td>{{.MemoryLimits.Min.FormatMemory}}<br>{{.MemoryLimits.Avg.FormatMemory}}<br>{{.MemoryLimits.Max.FormatMemory}}</td>
<td>{{.CPURequests.Min.FormatCPU}}<br>{{.CPURequests.Avg.FormatCPU}}<br>{{.CPURequests.Max.FormatCPU}}</td>
<td>{{.CPULimits.Min.FormatCPU}}<br>{{.CPULimits.Avg.FormatCPU}}<br>{{.CPULimits.Max.FormatCPU}}</td>
<td>{{$pod.Namespace}}</td>
<td>{{$pod.Pod}}</td>
<td>{{$container.Name}}</td>
{{if $container.MemoryRequests.HasValue}}
<td>Memory Requests</td>
<td>{{$container.MemoryRequests.Current.FormatMemory}}</td>
{{else}}
<td>Memory</td>
<td> </td>
{{end}}
<td>{{$container.MemoryRequests.Min.FormatMemory}}</td>
<td>{{$container.MemoryRequests.Avg.FormatMemory}}</td>
<td>{{$container.MemoryRequests.Max.FormatMemory}}</td>
</tr>
<tr>
<td>{{$pod.Namespace}}</td>
<td>{{$pod.Pod}}</td>
<td>{{$container.Name}}</td>
{{if $container.MemoryLimits.HasValue}}
<td>Memory Limits</td>
<td>{{$container.MemoryLimits.Current.FormatMemory}}</td>
{{else}}
<td>Memory</td>
<td> </td>
{{end}}
<td>{{$container.MemoryLimits.Min.FormatMemory}}</td>
<td>{{$container.MemoryLimits.Avg.FormatMemory}}</td>
<td>{{$container.MemoryLimits.Max.FormatMemory}}</td>
</tr>
<tr>
<td>{{$pod.Namespace}}</td>
<td>{{$pod.Pod}}</td>
<td>{{$container.Name}}</td>
{{if $container.CPURequests.HasValue}}
<td>CPU Requests</td>
<td>{{$container.CPURequests.Current.FormatCPU}}</td>
{{else}}
<td>CPUs</td>
<td> </td>
{{end}}
<td>{{$container.CPURequests.Min.FormatCPU}}</td>
<td>{{$container.CPURequests.Avg.FormatCPU}}</td>
<td>{{$container.CPURequests.Max.FormatCPU}}</td>
</tr>
<tr>
<td>{{$pod.Namespace}}</td>
<td>{{$pod.Pod}}</td>
<td>{{$container.Name}}</td>
{{if $container.CPULimits.HasValue}}
<td>CPU Limits</td>
<td>{{$container.CPULimits.Current.FormatCPU}}</td>
{{else}}
<td>CPUs</td>
<td> </td>
{{end}}
<td>{{$container.CPULimits.Min.FormatCPU}}</td>
<td>{{$container.CPULimits.Avg.FormatCPU}}</td>
<td>{{$container.CPULimits.Max.FormatCPU}}</td>
</tr>
{{end}}
{{end}}
</tbody>
</table>`
4 changes: 2 additions & 2 deletions pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func calculate(usageMetric *model.SampleStream, requests, limits *resource.Quant
analyzedRequests.Min.Percentage = analyzedRequests.Min.Value / requests.AsApproximateFloat64()
analyzedRequests.Max.Percentage = analyzedRequests.Max.Value / requests.AsApproximateFloat64()
analyzedRequests.Avg.Percentage = analyzedRequests.Avg.Value / requests.AsApproximateFloat64()
analyzedRequests.Current = requests.AsApproximateFloat64()
analyzedRequests.Current = util.ComputedValue{Value: requests.AsApproximateFloat64(), Percentage: 0}
analyzedRequests.HasValue = true
}

Expand All @@ -161,7 +161,7 @@ func calculate(usageMetric *model.SampleStream, requests, limits *resource.Quant
analyzedLimits.Min.Percentage = analyzedLimits.Min.Value / limits.AsApproximateFloat64()
analyzedLimits.Max.Percentage = analyzedLimits.Max.Value / limits.AsApproximateFloat64()
analyzedLimits.Avg.Percentage = analyzedLimits.Avg.Value / limits.AsApproximateFloat64()
analyzedLimits.Current = limits.AsApproximateFloat64()
analyzedLimits.Current = util.ComputedValue{Value: limits.AsApproximateFloat64(), Percentage: 0}
analyzedLimits.HasValue = true
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/resources/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type AnalyzedValues struct {
Min util.ComputedValue
Max util.ComputedValue
Avg util.ComputedValue
Current float64
Current util.ComputedValue
HasValue bool
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func (p PodValuesList) ToTable() string {
v.Pod,
c.Name,
"Memory Requests",
util.ByteCountIEC(c.MemoryRequests.Current),
c.MemoryRequests.Current.FormatMemory(),
c.MemoryRequests.Min.FormatMemory(),
c.MemoryRequests.Avg.FormatMemory(),
c.MemoryRequests.Max.FormatMemory(),
Expand All @@ -109,7 +109,7 @@ func (p PodValuesList) ToTable() string {
v.Pod,
c.Name,
"Memory Limits",
util.ByteCountIEC(c.MemoryLimits.Current),
c.MemoryLimits.Current.FormatMemory(),
c.MemoryLimits.Min.FormatMemory(),
c.MemoryLimits.Avg.FormatMemory(),
c.MemoryLimits.Max.FormatMemory(),
Expand All @@ -133,7 +133,7 @@ func (p PodValuesList) ToTable() string {
v.Pod,
c.Name,
"CPU Requests",
util.Cores(c.CPURequests.Current),
c.CPURequests.Current.FormatCPU(),
c.CPURequests.Min.FormatCPU(),
c.CPURequests.Avg.FormatCPU(),
c.CPURequests.Max.FormatCPU(),
Expand All @@ -157,7 +157,7 @@ func (p PodValuesList) ToTable() string {
v.Pod,
c.Name,
"CPU Limits",
util.Cores(c.CPULimits.Current),
c.CPULimits.Current.FormatCPU(),
c.CPULimits.Min.FormatCPU(),
c.CPULimits.Avg.FormatCPU(),
c.CPULimits.Max.FormatCPU(),
Expand Down

0 comments on commit 74651cc

Please sign in to comment.