details-gc.vue 3.45 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="Garbage Collection Pauses" 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 GC metrics failed.
                    </strong>
                </div>
            </div>
            <div class="level" v-if="current">
29 30 31 32 33 34 35 36 37
                <div class="level-item has-text-centered">
                    <div>
                        <p class="heading">Count</p>
                        <p v-text="current.count"></p>
                    </div>
                </div>
                <div class="level-item has-text-centered">
                    <div>
                        <p class="heading">Total time spent</p>
38 39 40 41 42 43 44
                        <p v-text="`${current.total_time.asSeconds()}s`"></p>
                    </div>
                </div>
                <div class="level-item has-text-centered">
                    <div>
                        <p class="heading">Max time spent</p>
                        <p v-text="`${current.max.asSeconds()}s`"></p>
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
                    </div>
                </div>
            </div>
        </div>
    </sba-panel>
</template>

<script>
  import subscribing from '@/mixins/subscribing';
  import {Observable} from '@/utils/rxjs';
  import moment from 'moment';

  export default {
    props: ['instance'],
    mixins: [subscribing],
    data: () => ({
61 62
      hasLoaded: false,
      error: null,
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
      current: null,
    }),
    watch: {
      instance() {
        this.subscribe()
      },
      dataSource() {
        this.current = null;
      }
    },
    methods: {
      async fetchMetrics() {
        const response = await this.instance.fetchMetric('jvm.gc.pause');
        const measurements = response.data.measurements.reduce(
          (current, measurement) => ({
            ...current,
79
            [measurement.statistic.toLowerCase()]: measurement.value
80 81
          }), {}
        );
82 83 84 85 86
        return {
          ...measurements,
          total_time: moment.duration(Math.round(measurements.total_time * 1000)),
          max: moment.duration(Math.round(measurements.max * 1000)),
        };
87 88 89 90 91 92 93 94
      },
      createSubscription() {
        const vm = this;
        if (this.instance) {
          return Observable.timer(0, 2500)
            .concatMap(this.fetchMetrics)
            .subscribe({
              next: data => {
95
                vm.hasLoaded = true;
96 97
                vm.current = data;
              },
98 99 100 101
              error: error => {
                vm.hasLoaded = true;
                console.warn('Fetching GC metrics failed:', error);
                vm.error = error;
102 103 104 105 106 107 108
              }
            });
        }
      }
    }
  }
</script>