github.com/aminovpavel/nomad@v0.11.8/ui/app/components/allocation-stat.js (about)

     1  import Component from '@ember/component';
     2  import { computed } from '@ember/object';
     3  import { alias } from '@ember/object/computed';
     4  import { formatBytes } from 'nomad-ui/helpers/format-bytes';
     5  
     6  export default Component.extend({
     7    tagName: '',
     8  
     9    allocation: null,
    10    statsTracker: null,
    11    isLoading: false,
    12    error: null,
    13    metric: 'memory', // Either memory or cpu
    14  
    15    statClass: computed('metric', function() {
    16      return this.metric === 'cpu' ? 'is-info' : 'is-danger';
    17    }),
    18  
    19    cpu: alias('statsTracker.cpu.lastObject'),
    20    memory: alias('statsTracker.memory.lastObject'),
    21  
    22    stat: computed('metric', 'cpu', 'memory', function() {
    23      const { metric } = this;
    24      if (metric === 'cpu' || metric === 'memory') {
    25        return this[this.metric];
    26      }
    27    }),
    28  
    29    formattedStat: computed('metric', 'stat.used', function() {
    30      if (!this.stat) return;
    31      if (this.metric === 'memory') return formatBytes([this.stat.used]);
    32      return this.stat.used;
    33    }),
    34  
    35    formattedReserved: computed(
    36      'metric',
    37      'statsTracker.reservedMemory',
    38      'statsTracker.reservedCPU',
    39      function() {
    40        if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`;
    41        if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`;
    42      }
    43    ),
    44  });