2021-03-16 02:47:54 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { task, timeout } from 'ember-concurrency';
|
|
|
|
import { assert } from '@ember/debug';
|
|
|
|
import { inject as service } from '@ember/service';
|
2021-03-19 21:31:27 +00:00
|
|
|
import { action, get, computed } from '@ember/object';
|
2021-05-03 15:36:18 +00:00
|
|
|
import { dependentKeyCompat } from '@ember/object/compat';
|
2021-03-16 02:47:54 +00:00
|
|
|
|
2021-03-19 21:31:27 +00:00
|
|
|
export default class AllocationPrimaryMetric extends Component {
|
2021-03-16 02:47:54 +00:00
|
|
|
@service('stats-trackers-registry') statsTrackersRegistry;
|
|
|
|
|
|
|
|
/** Args
|
|
|
|
allocation = null;
|
|
|
|
metric null; (one of 'cpu' or 'memory'
|
|
|
|
*/
|
|
|
|
|
|
|
|
get metric() {
|
|
|
|
assert('metric is a required argument', this.args.metric);
|
|
|
|
return this.args.metric;
|
|
|
|
}
|
|
|
|
|
2021-05-03 15:36:18 +00:00
|
|
|
@dependentKeyCompat
|
2021-03-19 21:31:27 +00:00
|
|
|
get allocation() {
|
|
|
|
return this.args.allocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('allocation')
|
2021-03-16 02:47:54 +00:00
|
|
|
get tracker() {
|
2021-03-19 21:31:27 +00:00
|
|
|
return this.statsTrackersRegistry.getTracker(this.allocation);
|
2021-03-16 02:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
if (!this.tracker) return [];
|
|
|
|
return get(this, `tracker.${this.metric}`);
|
|
|
|
}
|
|
|
|
|
2021-03-19 21:31:27 +00:00
|
|
|
@computed('tracker.tasks.[]', 'metric')
|
2021-03-16 02:47:54 +00:00
|
|
|
get series() {
|
|
|
|
const ret = this.tracker.tasks
|
2021-12-28 14:45:20 +00:00
|
|
|
.map((task) => ({
|
2021-03-16 02:47:54 +00:00
|
|
|
name: task.task,
|
|
|
|
data: task[this.metric],
|
|
|
|
}))
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
get reservedAmount() {
|
2021-03-24 20:55:18 +00:00
|
|
|
if (this.metric === 'cpu') return this.tracker.reservedCPU;
|
|
|
|
if (this.metric === 'memory') return this.tracker.reservedMemory;
|
|
|
|
return null;
|
2021-03-16 02:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get chartClass() {
|
|
|
|
if (this.metric === 'cpu') return 'is-info';
|
|
|
|
if (this.metric === 'memory') return 'is-danger';
|
|
|
|
return 'is-primary';
|
|
|
|
}
|
|
|
|
|
|
|
|
get colorScale() {
|
|
|
|
if (this.metric === 'cpu') return 'blues';
|
|
|
|
if (this.metric === 'memory') return 'reds';
|
|
|
|
return 'ordinal';
|
|
|
|
}
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@task(function* () {
|
2021-03-16 02:47:54 +00:00
|
|
|
do {
|
|
|
|
this.tracker.poll.perform();
|
|
|
|
yield timeout(100);
|
|
|
|
} while (!Ember.testing);
|
|
|
|
})
|
|
|
|
poller;
|
|
|
|
|
|
|
|
@action
|
|
|
|
start() {
|
|
|
|
if (this.tracker) this.poller.perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
willDestroy() {
|
2021-12-28 14:45:20 +00:00
|
|
|
super.willDestroy(...arguments);
|
2021-03-16 02:47:54 +00:00
|
|
|
this.poller.cancelAll();
|
|
|
|
this.tracker.signalPause.perform();
|
|
|
|
}
|
|
|
|
}
|