132 lines
3.9 KiB
TypeScript
132 lines
3.9 KiB
TypeScript
import { type Ref, defineComponent, inject, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { useDateFormat } from '@/shared/composables';
|
|
|
|
import JhiMetricsModal from './metrics-modal.vue';
|
|
import MetricsService from './metrics.service';
|
|
|
|
export default defineComponent({
|
|
name: 'JhiMetrics',
|
|
components: {
|
|
'metrics-modal': JhiMetricsModal,
|
|
},
|
|
setup() {
|
|
const { formatDate } = useDateFormat();
|
|
const metricsService = inject('metricsService', () => new MetricsService(), true);
|
|
|
|
const metrics: Ref = ref({});
|
|
const threadData: Ref = ref(null);
|
|
const threadStats: Ref = ref({});
|
|
const updatingMetrics = ref(true);
|
|
|
|
return {
|
|
metricsService,
|
|
metrics,
|
|
threadData,
|
|
threadStats,
|
|
updatingMetrics,
|
|
formatDate,
|
|
t$: useI18n().t,
|
|
};
|
|
},
|
|
mounted(): void {
|
|
this.refresh();
|
|
},
|
|
methods: {
|
|
refresh() {
|
|
return this.metricsService
|
|
.getMetrics()
|
|
.then(resultsMetrics => {
|
|
this.metrics = resultsMetrics.data;
|
|
this.metricsService
|
|
.retrieveThreadDump()
|
|
.then(res => {
|
|
this.updatingMetrics = true;
|
|
this.threadData = res.data.threads;
|
|
|
|
this.threadStats = {
|
|
threadDumpRunnable: 0,
|
|
threadDumpWaiting: 0,
|
|
threadDumpTimedWaiting: 0,
|
|
threadDumpBlocked: 0,
|
|
threadDumpAll: 0,
|
|
};
|
|
|
|
this.threadData.forEach(value => {
|
|
if (value.threadState === 'RUNNABLE') {
|
|
this.threadStats.threadDumpRunnable += 1;
|
|
} else if (value.threadState === 'WAITING') {
|
|
this.threadStats.threadDumpWaiting += 1;
|
|
} else if (value.threadState === 'TIMED_WAITING') {
|
|
this.threadStats.threadDumpTimedWaiting += 1;
|
|
} else if (value.threadState === 'BLOCKED') {
|
|
this.threadStats.threadDumpBlocked += 1;
|
|
}
|
|
});
|
|
|
|
this.threadStats.threadDumpAll =
|
|
this.threadStats.threadDumpRunnable +
|
|
this.threadStats.threadDumpWaiting +
|
|
this.threadStats.threadDumpTimedWaiting +
|
|
this.threadStats.threadDumpBlocked;
|
|
|
|
this.updatingMetrics = false;
|
|
})
|
|
.catch(() => {
|
|
this.updatingMetrics = true;
|
|
});
|
|
})
|
|
.catch(() => {
|
|
this.updatingMetrics = true;
|
|
});
|
|
},
|
|
openModal(): void {
|
|
if ((this.$refs.metricsModal as any).show) {
|
|
(this.$refs.metricsModal as any).show();
|
|
}
|
|
},
|
|
filterNaN(input: any): any {
|
|
if (isNaN(input)) {
|
|
return 0;
|
|
}
|
|
return input;
|
|
},
|
|
formatNumber1(value: any): any {
|
|
return new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format(value);
|
|
},
|
|
formatNumber2(value: any): any {
|
|
return new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(value);
|
|
},
|
|
convertMillisecondsToDuration(ms) {
|
|
const times = {
|
|
year: 31557600000,
|
|
month: 2629746000,
|
|
day: 86400000,
|
|
hour: 3600000,
|
|
minute: 60000,
|
|
second: 1000,
|
|
};
|
|
let time_string = '';
|
|
const plural = '';
|
|
for (const key in times) {
|
|
if (Math.floor(ms / times[key]) > 0) {
|
|
let plural = '';
|
|
if (Math.floor(ms / times[key]) > 1) {
|
|
plural = 's';
|
|
}
|
|
time_string += `${Math.floor(ms / times[key])} ${key}${plural} `;
|
|
ms = ms - times[key] * Math.floor(ms / times[key]);
|
|
}
|
|
}
|
|
return time_string;
|
|
},
|
|
isObjectExisting(metrics: any, key: string): boolean {
|
|
return metrics?.[key];
|
|
},
|
|
isObjectExistingAndNotEmpty(metrics: any, key: string): boolean {
|
|
return this.isObjectExisting(metrics, key) && JSON.stringify(metrics[key]) !== '{}';
|
|
},
|
|
},
|
|
});
|