github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/components/allocation-stat.js (about) 1 import Component from '@ember/component'; 2 import { computed } from '@ember/object'; 3 import { alias } from '@ember/object/computed'; 4 import { formatBytes } from 'nomad-ui/helpers/format-bytes'; 5 import { tagName } from '@ember-decorators/component'; 6 import classic from 'ember-classic-decorator'; 7 8 @classic 9 @tagName('') 10 export default class AllocationStat extends Component { 11 allocation = null; 12 statsTracker = null; 13 isLoading = false; 14 error = null; 15 metric = 'memory'; // Either memory or cpu 16 17 @computed('metric') 18 get statClass() { 19 return this.metric === 'cpu' ? 'is-info' : 'is-danger'; 20 } 21 22 @alias('statsTracker.cpu.lastObject') cpu; 23 @alias('statsTracker.memory.lastObject') memory; 24 25 @computed('metric', 'cpu', 'memory') 26 get stat() { 27 const { metric } = this; 28 if (metric === 'cpu' || metric === 'memory') { 29 return this[this.metric]; 30 } 31 32 return undefined; 33 } 34 35 @computed('metric', 'stat.used') 36 get formattedStat() { 37 if (!this.stat) return undefined; 38 if (this.metric === 'memory') return formatBytes([this.stat.used]); 39 return this.stat.used; 40 } 41 42 @computed('metric', 'statsTracker.{reservedMemory,reservedCPU}') 43 get formattedReserved() { 44 if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`; 45 if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`; 46 return undefined; 47 } 48 }