2021-03-15 20:02:55 +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';
|
|
|
|
import { action, get } from '@ember/object';
|
2021-03-29 23:16:48 +00:00
|
|
|
import { formatScheduledBytes, formatScheduledHertz } from 'nomad-ui/utils/units';
|
2021-03-15 20:02:55 +00:00
|
|
|
|
|
|
|
export default class NodePrimaryMetric extends Component {
|
|
|
|
@service('stats-trackers-registry') statsTrackersRegistry;
|
|
|
|
|
|
|
|
/** Args
|
|
|
|
node = null;
|
|
|
|
metric null; (one of 'cpu' or 'memory')
|
|
|
|
*/
|
|
|
|
|
|
|
|
get metric() {
|
|
|
|
assert('metric is a required argument', this.args.metric);
|
|
|
|
return this.args.metric;
|
|
|
|
}
|
|
|
|
|
|
|
|
get tracker() {
|
|
|
|
return this.statsTrackersRegistry.getTracker(this.args.node);
|
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
if (!this.tracker) return [];
|
|
|
|
return get(this, `tracker.${this.metric}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-15 20:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get chartClass() {
|
|
|
|
if (this.metric === 'cpu') return 'is-info';
|
|
|
|
if (this.metric === 'memory') return 'is-danger';
|
|
|
|
return 'is-primary';
|
|
|
|
}
|
|
|
|
|
|
|
|
get reservedAnnotations() {
|
|
|
|
if (this.metric === 'cpu' && get(this.args.node, 'reserved.cpu')) {
|
|
|
|
const cpu = this.args.node.reserved.cpu;
|
2021-03-29 23:16:48 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: `${formatScheduledHertz(cpu, 'MHz')} reserved`,
|
|
|
|
percent: cpu / this.reservedAmount,
|
|
|
|
},
|
|
|
|
];
|
2021-03-15 20:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.metric === 'memory' && get(this.args.node, 'reserved.memory')) {
|
|
|
|
const memory = this.args.node.reserved.memory;
|
2021-03-29 23:16:48 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: `${formatScheduledBytes(memory, 'MiB')} reserved`,
|
|
|
|
percent: memory / this.reservedAmount,
|
|
|
|
},
|
|
|
|
];
|
2021-03-15 20:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@task(function* () {
|
2021-03-15 20:02:55 +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-15 20:02:55 +00:00
|
|
|
this.poller.cancelAll();
|
|
|
|
this.tracker.signalPause.perform();
|
|
|
|
}
|
|
|
|
}
|