2021-03-19 21:34:00 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import Component from '@glimmer/component';
|
2021-03-22 07:46:37 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2021-03-19 21:34:00 +00:00
|
|
|
import { task, timeout } from 'ember-concurrency';
|
|
|
|
import { assert } from '@ember/debug';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
|
|
|
export default class TaskPrimaryMetric extends Component {
|
|
|
|
@service('stats-trackers-registry') statsTrackersRegistry;
|
|
|
|
|
|
|
|
/** Args
|
|
|
|
taskState = null;
|
|
|
|
metric null; (one of 'cpu' or 'memory'
|
|
|
|
*/
|
|
|
|
|
2021-03-22 07:46:37 +00:00
|
|
|
@tracked tracker = null;
|
|
|
|
@tracked taskState = null;
|
|
|
|
|
2021-03-19 21:34:00 +00:00
|
|
|
get metric() {
|
|
|
|
assert('metric is a required argument', this.args.metric);
|
|
|
|
return this.args.metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
if (!this.tracker) return [];
|
2021-03-22 07:46:37 +00:00
|
|
|
const task = this.tracker.tasks.findBy('task', this.taskState.name);
|
2021-03-19 21:34:00 +00:00
|
|
|
return task && task[this.metric];
|
|
|
|
}
|
|
|
|
|
|
|
|
get reservedAmount() {
|
2021-03-22 07:46:37 +00:00
|
|
|
if (!this.tracker) return null;
|
|
|
|
const task = this.tracker.tasks.findBy('task', this.taskState.name);
|
2021-03-24 20:55:18 +00:00
|
|
|
if (this.metric === 'cpu') return task.reservedCPU;
|
|
|
|
if (this.metric === 'memory') return task.reservedMemory;
|
|
|
|
return null;
|
2021-03-19 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get chartClass() {
|
|
|
|
if (this.metric === 'cpu') return 'is-info';
|
|
|
|
if (this.metric === 'memory') return 'is-danger';
|
|
|
|
return 'is-primary';
|
|
|
|
}
|
|
|
|
|
|
|
|
@task(function*() {
|
|
|
|
do {
|
|
|
|
this.tracker.poll.perform();
|
|
|
|
yield timeout(100);
|
|
|
|
} while (!Ember.testing);
|
|
|
|
})
|
|
|
|
poller;
|
|
|
|
|
|
|
|
@action
|
|
|
|
start() {
|
2021-03-22 07:46:37 +00:00
|
|
|
this.taskState = this.args.taskState;
|
|
|
|
this.tracker = this.statsTrackersRegistry.getTracker(this.args.taskState.allocation);
|
|
|
|
this.poller.perform();
|
2021-03-19 21:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
this.poller.cancelAll();
|
|
|
|
this.tracker.signalPause.perform();
|
|
|
|
}
|
|
|
|
}
|