details-memory.vue 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!--
  - Copyright 2014-2018 the original author or authors.
  -
  - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License.
  - You may obtain a copy of the License at
  -
  -     http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
  -->

<template>
18
    <sba-panel :title="`Memory: ${name}`" v-if="hasLoaded">
Johannes Edmeier committed
19
        <div>
20 21 22 23 24 25 26 27 28
            <div v-if="error" class="message is-danger">
                <div class="message-body">
                    <strong>
                        <font-awesome-icon class="has-text-danger" icon="exclamation-triangle"></font-awesome-icon>
                        Fetching memory metrics failed.
                    </strong>
                </div>
            </div>
            <div class="level memory-current" v-if="current">
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
                <div class="level-item has-text-centered" v-if="current.metaspace">
                    <div>
                        <p class="heading has-bullet has-bullet-primary">Metaspace</p>
                        <p v-text="prettyBytes(current.metaspace)"></p>
                    </div>
                </div>
                <div class="level-item has-text-centered">
                    <div>
                        <p class="heading has-bullet has-bullet-info">Used</p>
                        <p v-text="prettyBytes(current.used)"></p>
                    </div>
                </div>
                <div class="level-item has-text-centered">
                    <div>
                        <p class="heading has-bullet has-bullet-warning">Size</p>
                        <p v-text="prettyBytes(current.committed)"></p>
                    </div>
                </div>
                <div class="level-item has-text-centered" v-if="current.max >= 0">
                    <div>
                        <p class="heading">Max</p>
                        <p v-text="prettyBytes(current.max)"></p>
                    </div>
                </div>
            </div>
54
            <mem-chart v-if="chartData.length > 0" :data="chartData"></mem-chart>
55 56 57 58 59 60 61 62 63 64 65 66 67 68
        </div>
    </sba-panel>
</template>

<script>
  import subscribing from '@/mixins/subscribing';
  import {Observable} from '@/utils/rxjs';
  import moment from 'moment';
  import prettyBytes from 'pretty-bytes';
  import memChart from './mem-chart';

  export default {
    props: ['instance', 'type'],
    mixins: [subscribing],
69
    components: {memChart},
70
    data: () => ({
71 72
      hasLoaded: false,
      error: null,
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
      current: null,
      chartData: [],
    }),
    computed: {
      name() {
        switch (this.type) {
          case 'heap':
            return 'Heap';
          case 'nonheap':
            return 'Non heap';
          default:
            return this.type;
        }
      }
    },
    watch: {
      instance() {
        this.subscribe();
      }
    },
    methods: {
      prettyBytes,
      async fetchMetrics() {
        if (this.instance) {
          const responseMax = this.instance.fetchMetric('jvm.memory.max', {area: this.type});
          const responseUsed = this.instance.fetchMetric('jvm.memory.used', {area: this.type});
          const responeMetaspace = this.type === 'nonheap'
            ? this.instance.fetchMetric('jvm.memory.used', {area: this.type, id: 'Metaspace'})
            : null;
          const responseCommitted = this.instance.fetchMetric('jvm.memory.committed', {area: this.type});
          return {
            max: (await responseMax).data.measurements[0].value,
            used: (await responseUsed).data.measurements[0].value,
            metaspace: responeMetaspace ? (await responeMetaspace).data.measurements[0].value : null,
            committed: (await responseCommitted).data.measurements[0].value
          };
        }
      },
      createSubscription() {
        const vm = this;
        if (this.instance) {
          return Observable.timer(0, 2500)
            .concatMap(this.fetchMetrics)
            .subscribe({
              next: data => {
118
                vm.hasLoaded = true;
119 120 121
                vm.current = data;
                vm.chartData.push({...data, timestamp: moment.now().valueOf()});
              },
122 123 124 125
              error: error => {
                vm.hasLoaded = true;
                console.warn('Fetching memory metrics failed:', error);
                vm.error = error;
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
              }
            });
        }
      }
    }
  }
</script>

<style lang="scss">
    @import "~@/assets/css/utilities";

    .memory-current {
        margin-bottom: 0 !important;
    }
</style>