2020-05-04 08:18:14 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { alias } from '@ember/object/computed';
|
2021-03-29 23:16:48 +00:00
|
|
|
import { formatBytes, formatHertz } from 'nomad-ui/utils/units';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { tagName } from '@ember-decorators/component';
|
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
|
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class AllocationStat extends Component {
|
|
|
|
allocation = null;
|
|
|
|
statsTracker = null;
|
|
|
|
isLoading = false;
|
|
|
|
error = null;
|
|
|
|
metric = 'memory'; // Either memory or cpu
|
|
|
|
|
|
|
|
@computed('metric')
|
|
|
|
get statClass() {
|
2020-05-04 08:18:14 +00:00
|
|
|
return this.metric === 'cpu' ? 'is-info' : 'is-danger';
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-04 08:18:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('statsTracker.cpu.lastObject') cpu;
|
|
|
|
@alias('statsTracker.memory.lastObject') memory;
|
2020-05-04 08:18:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('metric', 'cpu', 'memory')
|
|
|
|
get stat() {
|
2020-05-04 08:18:14 +00:00
|
|
|
const { metric } = this;
|
|
|
|
if (metric === 'cpu' || metric === 'memory') {
|
|
|
|
return this[this.metric];
|
|
|
|
}
|
2020-06-09 21:03:28 +00:00
|
|
|
|
2020-06-10 14:07:16 +00:00
|
|
|
return undefined;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-04 08:18:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('metric', 'stat.used')
|
|
|
|
get formattedStat() {
|
2020-06-10 14:07:16 +00:00
|
|
|
if (!this.stat) return undefined;
|
2021-03-27 00:02:54 +00:00
|
|
|
if (this.metric === 'memory') return formatBytes(this.stat.used);
|
2021-03-29 23:16:48 +00:00
|
|
|
if (this.metric === 'cpu') return formatHertz(this.stat.used, 'MHz');
|
|
|
|
return undefined;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-04 08:18:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('metric', 'statsTracker.{reservedMemory,reservedCPU}')
|
|
|
|
get formattedReserved() {
|
2021-03-27 00:02:54 +00:00
|
|
|
if (this.metric === 'memory') return formatBytes(this.statsTracker.reservedMemory, 'MiB');
|
2021-03-29 23:16:48 +00:00
|
|
|
if (this.metric === 'cpu') return formatHertz(this.statsTracker.reservedCPU, 'MHz');
|
2020-06-10 14:07:16 +00:00
|
|
|
return undefined;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|