open-nomad/ui/app/utils/classes/allocation-stats.js
Michael Lange 6bf139d094 Refactor the way allocation stats are fetched
No longer treat it as a property for relationship, just ephemeral
data that can be fetched on demand.
2018-03-22 14:34:13 -07:00

34 lines
1,016 B
JavaScript

import EmberObject, { computed } from '@ember/object';
import { alias, readOnly } from '@ember/object/computed';
export default EmberObject.extend({
allocation: null,
stats: null,
reservedMemory: alias('allocation.taskGroup.reservedMemory'),
reservedCPU: alias('allocation.taskGroup.reservedCPU'),
memoryUsed: readOnly('stats.ResourceUsage.MemoryStats.RSS'),
cpuUsed: computed('stats.ResourceUsage.CpuStats.TotalTicks', function() {
return Math.floor(this.get('stats.ResourceUsage.CpuStats.TotalTicks') || 0);
}),
percentMemory: computed('reservedMemory', 'memoryUsed', function() {
const used = this.get('memoryUsed') / 1024 / 1024;
const total = this.get('reservedMemory');
if (!total || !used) {
return 0;
}
return used / total;
}),
percentCPU: computed('reservedCPU', 'cpuUsed', function() {
const used = this.get('cpuUsed');
const total = this.get('reservedCPU');
if (!total || !used) {
return 0;
}
return used / total;
}),
});