diff --git a/ui/app/components/allocation-stat.js b/ui/app/components/allocation-stat.js new file mode 100644 index 000000000..c8f16a7a4 --- /dev/null +++ b/ui/app/components/allocation-stat.js @@ -0,0 +1,44 @@ +import Component from '@ember/component'; +import { computed } from '@ember/object'; +import { alias } from '@ember/object/computed'; +import { formatBytes } from 'nomad-ui/helpers/format-bytes'; + +export default Component.extend({ + tagName: '', + + allocation: null, + statsTracker: null, + isLoading: false, + error: null, + metric: 'memory', // Either memory or cpu + + statClass: computed('metric', function() { + return this.metric === 'cpu' ? 'is-info' : 'is-danger'; + }), + + cpu: alias('statsTracker.cpu.lastObject'), + memory: alias('statsTracker.memory.lastObject'), + + stat: computed('metric', 'cpu', 'memory', function() { + const { metric } = this; + if (metric === 'cpu' || metric === 'memory') { + return this[this.metric]; + } + }), + + formattedStat: computed('metric', 'stat.used', function() { + if (!this.stat) return; + if (this.metric === 'memory') return formatBytes([this.stat.used]); + return this.stat.used; + }), + + formattedReserved: computed( + 'metric', + 'statsTracker.reservedMemory', + 'statsTracker.reservedCPU', + function() { + if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`; + if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`; + } + ), +}); diff --git a/ui/app/templates/components/allocation-stat.hbs b/ui/app/templates/components/allocation-stat.hbs new file mode 100644 index 000000000..8dabc3422 --- /dev/null +++ b/ui/app/templates/components/allocation-stat.hbs @@ -0,0 +1,18 @@ +{{#if allocation.isRunning}} + {{#if (and (not stat) isLoading)}} + … + {{else if error}} + + {{x-icon "warning" class="is-warning"}} + + {{else}} +