github.com/hernad/nomad@v1.6.112/ui/app/components/allocation-stat.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Component from '@ember/component';
     7  import { computed } from '@ember/object';
     8  import { alias } from '@ember/object/computed';
     9  import { formatBytes, formatHertz } from 'nomad-ui/utils/units';
    10  import { tagName } from '@ember-decorators/component';
    11  import classic from 'ember-classic-decorator';
    12  
    13  @classic
    14  @tagName('')
    15  export default class AllocationStat extends Component {
    16    allocation = null;
    17    statsTracker = null;
    18    isLoading = false;
    19    error = null;
    20    metric = 'memory'; // Either memory or cpu
    21  
    22    @computed('metric')
    23    get statClass() {
    24      return this.metric === 'cpu' ? 'is-info' : 'is-danger';
    25    }
    26  
    27    @alias('statsTracker.cpu.lastObject') cpu;
    28    @alias('statsTracker.memory.lastObject') memory;
    29  
    30    @computed('metric', 'cpu', 'memory')
    31    get stat() {
    32      const { metric } = this;
    33      if (metric === 'cpu' || metric === 'memory') {
    34        return this[this.metric];
    35      }
    36  
    37      return undefined;
    38    }
    39  
    40    @computed('metric', 'stat.used')
    41    get formattedStat() {
    42      if (!this.stat) return undefined;
    43      if (this.metric === 'memory') return formatBytes(this.stat.used);
    44      if (this.metric === 'cpu') return formatHertz(this.stat.used, 'MHz');
    45      return undefined;
    46    }
    47  
    48    @computed('metric', 'statsTracker.{reservedMemory,reservedCPU}')
    49    get formattedReserved() {
    50      if (this.metric === 'memory')
    51        return formatBytes(this.statsTracker.reservedMemory, 'MiB');
    52      if (this.metric === 'cpu')
    53        return formatHertz(this.statsTracker.reservedCPU, 'MHz');
    54      return undefined;
    55    }
    56  }