2017-06-20 04:50:31 -04:00
|
|
|
<script>
|
|
|
|
/* global Flash */
|
|
|
|
import _ from 'underscore';
|
|
|
|
import statusCodes from '../../lib/utils/http_status';
|
|
|
|
import MonitoringService from '../services/monitoring_service';
|
2017-08-30 01:16:23 -04:00
|
|
|
import GraphGroup from './graph_group.vue';
|
2017-09-06 03:42:47 -04:00
|
|
|
import Graph from './graph.vue';
|
2017-08-30 00:49:29 -04:00
|
|
|
import EmptyState from './empty_state.vue';
|
2017-06-20 04:50:31 -04:00
|
|
|
import MonitoringStore from '../stores/monitoring_store';
|
|
|
|
import eventHub from '../event_hub';
|
2017-09-06 04:01:01 -04:00
|
|
|
import { backOff } from '../../lib/utils/common_utils';
|
2017-06-20 04:50:31 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
|
|
data() {
|
|
|
|
const metricsData = document.querySelector('#prometheus-graphs').dataset;
|
|
|
|
const store = new MonitoringStore();
|
|
|
|
|
|
|
|
return {
|
|
|
|
store,
|
|
|
|
state: 'gettingStarted',
|
|
|
|
hasMetrics: gl.utils.convertPermissionToBoolean(metricsData.hasMetrics),
|
|
|
|
documentationPath: metricsData.documentationPath,
|
|
|
|
settingsPath: metricsData.settingsPath,
|
|
|
|
endpoint: metricsData.additionalMetrics,
|
|
|
|
deploymentEndpoint: metricsData.deploymentEndpoint,
|
|
|
|
showEmptyState: true,
|
|
|
|
backOffRequestCounter: 0,
|
|
|
|
updateAspectRatio: false,
|
|
|
|
updatedAspectRatios: 0,
|
|
|
|
resizeThrottled: {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
2017-09-06 03:42:47 -04:00
|
|
|
Graph,
|
2017-08-30 01:16:23 -04:00
|
|
|
GraphGroup,
|
2017-08-30 00:49:29 -04:00
|
|
|
EmptyState,
|
2017-06-20 04:50:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getGraphsData() {
|
|
|
|
const maxNumberOfRequests = 3;
|
|
|
|
this.state = 'loading';
|
2017-09-06 04:01:01 -04:00
|
|
|
backOff((next, stop) => {
|
2017-06-20 04:50:31 -04:00
|
|
|
this.service.get().then((resp) => {
|
|
|
|
if (resp.status === statusCodes.NO_CONTENT) {
|
|
|
|
this.backOffRequestCounter = this.backOffRequestCounter += 1;
|
|
|
|
if (this.backOffRequestCounter < maxNumberOfRequests) {
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
stop(new Error('Failed to connect to the prometheus server'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stop(resp);
|
|
|
|
}
|
|
|
|
}).catch(stop);
|
|
|
|
})
|
|
|
|
.then((resp) => {
|
|
|
|
if (resp.status === statusCodes.NO_CONTENT) {
|
|
|
|
this.state = 'unableToConnect';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return resp.json();
|
|
|
|
})
|
|
|
|
.then((metricGroupsData) => {
|
|
|
|
if (!metricGroupsData) return false;
|
|
|
|
this.store.storeMetrics(metricGroupsData.data);
|
|
|
|
return this.getDeploymentData();
|
|
|
|
})
|
|
|
|
.then((deploymentData) => {
|
|
|
|
if (deploymentData !== false) {
|
|
|
|
this.store.storeDeploymentData(deploymentData.deployments);
|
|
|
|
this.showEmptyState = false;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.state = 'unableToConnect';
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getDeploymentData() {
|
|
|
|
return this.service.getDeploymentData(this.deploymentEndpoint)
|
|
|
|
.then(resp => resp.json())
|
|
|
|
.catch(() => new Flash('Error getting deployment information.'));
|
|
|
|
},
|
|
|
|
|
|
|
|
resize() {
|
|
|
|
this.updateAspectRatio = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleAspectRatio() {
|
|
|
|
this.updatedAspectRatios = this.updatedAspectRatios += 1;
|
|
|
|
if (this.store.getMetricsCount() === this.updatedAspectRatios) {
|
|
|
|
this.updateAspectRatio = !this.updateAspectRatio;
|
|
|
|
this.updatedAspectRatios = 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.service = new MonitoringService(this.endpoint);
|
|
|
|
eventHub.$on('toggleAspectRatio', this.toggleAspectRatio);
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('toggleAspectRatio', this.toggleAspectRatio);
|
|
|
|
window.removeEventListener('resize', this.resizeThrottled, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.resizeThrottled = _.throttle(this.resize, 600);
|
|
|
|
if (!this.hasMetrics) {
|
|
|
|
this.state = 'gettingStarted';
|
|
|
|
} else {
|
|
|
|
this.getGraphsData();
|
|
|
|
window.addEventListener('resize', this.resizeThrottled, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2017-08-29 23:45:07 -04:00
|
|
|
|
2017-06-20 04:50:31 -04:00
|
|
|
<template>
|
2017-08-29 23:45:07 -04:00
|
|
|
<div v-if="!showEmptyState" class="prometheus-graphs">
|
2017-08-30 01:16:23 -04:00
|
|
|
<graph-group
|
2017-06-20 04:50:31 -04:00
|
|
|
v-for="(groupData, index) in store.groups"
|
2017-08-29 23:45:07 -04:00
|
|
|
:key="index"
|
2017-08-30 01:16:23 -04:00
|
|
|
:name="groupData.group"
|
2017-08-29 23:45:07 -04:00
|
|
|
>
|
2017-09-06 03:42:47 -04:00
|
|
|
<graph
|
|
|
|
v-for="(graphData, index) in groupData.metrics"
|
2017-08-30 01:16:23 -04:00
|
|
|
:key="index"
|
2017-09-06 03:42:47 -04:00
|
|
|
:graph-data="graphData"
|
2017-08-30 01:16:23 -04:00
|
|
|
:update-aspect-ratio="updateAspectRatio"
|
|
|
|
:deployment-data="store.deploymentData"
|
|
|
|
/>
|
|
|
|
</graph-group>
|
2017-06-20 04:50:31 -04:00
|
|
|
</div>
|
2017-08-30 00:49:29 -04:00
|
|
|
<empty-state
|
2017-08-30 01:16:23 -04:00
|
|
|
v-else
|
2017-06-20 04:50:31 -04:00
|
|
|
:selected-state="state"
|
|
|
|
:documentation-path="documentationPath"
|
|
|
|
:settings-path="settingsPath"
|
|
|
|
/>
|
|
|
|
</template>
|