2019-10-12 21:52:04 +05:30
|
|
|
<script>
|
|
|
|
import { mapActions, mapState } from 'vuex';
|
|
|
|
import { getParameterValues, removeParams } from '~/lib/utils/url_utility';
|
|
|
|
import GraphGroup from './graph_group.vue';
|
2019-12-04 20:38:33 +05:30
|
|
|
import MonitorTimeSeriesChart from './charts/time_series.vue';
|
2019-10-12 21:52:04 +05:30
|
|
|
import { sidebarAnimationDuration } from '../constants';
|
|
|
|
import { getTimeDiff } from '../utils';
|
|
|
|
|
|
|
|
let sidebarMutationObserver;
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GraphGroup,
|
2019-12-04 20:38:33 +05:30
|
|
|
MonitorTimeSeriesChart,
|
2019-10-12 21:52:04 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
dashboardUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
const defaultRange = getTimeDiff();
|
|
|
|
const start = getParameterValues('start', this.dashboardUrl)[0] || defaultRange.start;
|
|
|
|
const end = getParameterValues('end', this.dashboardUrl)[0] || defaultRange.end;
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
start,
|
|
|
|
end,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
params,
|
|
|
|
elWidth: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState('monitoringDashboard', ['groups', 'metricsWithData']),
|
|
|
|
charts() {
|
|
|
|
const groupWithMetrics = this.groups.find(group =>
|
|
|
|
group.metrics.find(chart => this.chartHasData(chart)),
|
|
|
|
) || { metrics: [] };
|
|
|
|
|
|
|
|
return groupWithMetrics.metrics.filter(chart => this.chartHasData(chart));
|
|
|
|
},
|
|
|
|
isSingleChart() {
|
|
|
|
return this.charts.length === 1;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.setInitialState();
|
|
|
|
this.fetchMetricsData(this.params);
|
|
|
|
sidebarMutationObserver = new MutationObserver(this.onSidebarMutation);
|
|
|
|
sidebarMutationObserver.observe(document.querySelector('.layout-page'), {
|
|
|
|
attributes: true,
|
|
|
|
childList: false,
|
|
|
|
subtree: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (sidebarMutationObserver) {
|
|
|
|
sidebarMutationObserver.disconnect();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('monitoringDashboard', [
|
|
|
|
'fetchMetricsData',
|
|
|
|
'setEndpoints',
|
|
|
|
'setFeatureFlags',
|
|
|
|
'setShowErrorBanner',
|
|
|
|
]),
|
|
|
|
chartHasData(chart) {
|
|
|
|
return chart.metrics.some(metric => this.metricsWithData.includes(metric.metric_id));
|
|
|
|
},
|
|
|
|
onSidebarMutation() {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.elWidth = this.$el.clientWidth;
|
|
|
|
}, sidebarAnimationDuration);
|
|
|
|
},
|
|
|
|
setInitialState() {
|
|
|
|
this.setFeatureFlags({
|
|
|
|
prometheusEndpointEnabled: true,
|
|
|
|
});
|
|
|
|
this.setEndpoints({
|
|
|
|
dashboardEndpoint: removeParams(['start', 'end'], this.dashboardUrl),
|
|
|
|
});
|
|
|
|
this.setShowErrorBanner(false);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div class="metrics-embed" :class="{ 'd-inline-flex col-lg-6 p-0': isSingleChart }">
|
|
|
|
<div v-if="charts.length" class="row w-100 m-n2 pb-4">
|
2019-12-04 20:38:33 +05:30
|
|
|
<monitor-time-series-chart
|
2019-10-12 21:52:04 +05:30
|
|
|
v-for="graphData in charts"
|
|
|
|
:key="graphData.title"
|
2019-12-04 20:38:33 +05:30
|
|
|
class="w-100"
|
2019-10-12 21:52:04 +05:30
|
|
|
:graph-data="graphData"
|
|
|
|
:container-width="elWidth"
|
2019-12-21 20:55:43 +05:30
|
|
|
:group-id="dashboardUrl"
|
2019-10-12 21:52:04 +05:30
|
|
|
:project-path="null"
|
|
|
|
:show-border="true"
|
|
|
|
:single-embed="isSingleChart"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|