github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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, formatHertz } from 'nomad-ui/utils/units'; 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 if (this.metric === 'cpu') return formatHertz(this.stat.used, 'MHz'); 40 return undefined; 41 } 42 43 @computed('metric', 'statsTracker.{reservedMemory,reservedCPU}') 44 get formattedReserved() { 45 if (this.metric === 'memory') 46 return formatBytes(this.statsTracker.reservedMemory, 'MiB'); 47 if (this.metric === 'cpu') 48 return formatHertz(this.statsTracker.reservedCPU, 'MHz'); 49 return undefined; 50 } 51 }