Skip to content

Commit

Permalink
Aggregate the BANs in the cluster details panel
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Mar 30, 2021
1 parent 23fff74 commit a02adc6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions ui/app/controllers/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import classic from 'ember-classic-decorator';
import { reduceBytes } from 'nomad-ui/utils/units';
import { reduceBytes, reduceHertz } from 'nomad-ui/utils/units';

const sumAggregator = (sum, value) => sum + (value || 0);
const formatter = new Intl.NumberFormat(window.navigator.locale || 'en', {
maximumFractionDigits: 2,
});

@classic
export default class TopologyControllers extends Controller {
Expand Down Expand Up @@ -39,14 +42,25 @@ export default class TopologyControllers extends Controller {

@computed('totalMemory')
get totalMemoryFormatted() {
return reduceBytes(this.totalMemory)[0].toFixed(2);
return formatter.format(reduceBytes(this.totalMemory)[0]);
}

@computed('totalMemory')
get totalMemoryUnits() {
return reduceBytes(this.totalMemory)[1];
}

@computed('totalCPU')
get totalCPUFormatted() {
console.log('wat?', this.totalCPU);
return formatter.format(reduceHertz(this.totalCPU, null, 'MHz')[0]);
}

@computed('totalCPU')
get totalCPUUnits() {
return reduceHertz(this.totalCPU, null, 'MHz')[1];
}

@computed('scheduledAllocations.@each.allocatedResources')
get totalReservedMemory() {
const mibs = this.scheduledAllocations
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/topology.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
</div>
</div>
<div class="dashboard-metric">
<p class="metric">{{this.totalCPU}} <span class="metric-units">MHz</span> <span class="metric-label">of CPU</span></p>
<p class="metric">{{this.totalCPUFormatted}} <span class="metric-units">{{this.totalCPUUnits}}</span> <span class="metric-label">of CPU</span></p>
<div class="columns graphic">
<div class="column">
<div class="inline-chart" data-test-percentage-bar>
Expand Down
2 changes: 1 addition & 1 deletion ui/app/utils/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function reduceBytes(bytes = 0, maxUnitSize, startingUnitSize) {
return unitReducer(bytes, 1024, BYTES_UNITS, maxUnitSize, startingUnitSize);
}

export function reduceHertz(hertz, maxUnitSize, startingUnitSize) {
export function reduceHertz(hertz = 0, maxUnitSize, startingUnitSize) {
return unitReducer(hertz, 1000, HERTZ_UNITS, maxUnitSize, startingUnitSize);
}

Expand Down

0 comments on commit a02adc6

Please sign in to comment.