Merge branch 'feature/graphing' into 'master'
Added Graphing See merge request fronk/thetool!753
This commit is contained in:
@@ -77,7 +77,7 @@ Vue.component('DeviceTable', {
|
||||
|
||||
<template v-if="row.zabbix_host_id !== '0' && row.zabbix_host_id !== null">
|
||||
<a :href="window['TT_CONFIG']['ZABBIX_URL'] + '/zabbix.php?action=latest.view&hostids%5B%5D=' + row.zabbix_host_id" target="_blank" class="text-info" title="Zabbix"><i class="fas fa-server"></i></a>
|
||||
<a :href="window['TT_CONFIG']['GRAFANA_URL'] + '/d/Ta3PtRWZk/mikrotik-dashboard?orgId=1&var-host=' + row.name" target="_blank" class="text-info" title="Grafana"><i class="fas fa-chart-line"></i></a>
|
||||
<a :href="window['TT_CONFIG']['BASE_URL'] + '/Graphing?id=' + row.zabbix_host_id + '&hostname=' + row.name" target="_blank" class="text-info" title="Graphen"><i class="fas fa-chart-line"></i></a>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
Vue.component('tt-graph', {
|
||||
template: `
|
||||
<!-- use chart js with datasets etc everything needed for chart.js here to be usable width and height aswell -->
|
||||
<tt-card>
|
||||
<template v-slot:header>
|
||||
<h3 style="text-align: center;user-select: none">{{ header }}</h3>
|
||||
</template>
|
||||
|
||||
<div ref="container">
|
||||
<canvas ref="chart" :style="{width: width + 'px', height: height + 'px'}"></canvas></div>
|
||||
</tt-card>
|
||||
`,
|
||||
props: ['data', 'labels', 'header'],
|
||||
data() {
|
||||
return {
|
||||
chart: null,
|
||||
width: 400,
|
||||
height: 220
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
const ctx = this.$refs.chart.getContext('2d');
|
||||
this.chart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: this.labels,
|
||||
datasets: this.data
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
},
|
||||
x: {
|
||||
type: 'time',
|
||||
time: {
|
||||
// time is epoch
|
||||
parser: 'X',
|
||||
// unit: 'hour',
|
||||
displayFormats: {
|
||||
minute: 'DD.M. HH:mm',
|
||||
}
|
||||
},
|
||||
// min: '00:00:00',
|
||||
// max: '24:00:00',
|
||||
ticks: {
|
||||
autoSkipPadding: 25,
|
||||
autoSkip: true,
|
||||
maxRotation: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
responsive: true,
|
||||
},
|
||||
});
|
||||
|
||||
// set width and height to the canvas element actual width and height
|
||||
this.width = this.$refs.container.width;
|
||||
this.height = this.$refs.container.height;
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
Vue.component('device-graphing', {
|
||||
template: `
|
||||
<div style="display: grid; grid-template-columns: 45vw 45vw; gap: 1rem;">
|
||||
<h3 style="text-align: center;user-select: none;grid-column: 1 / span 2;">{{ hostname }}</h3>
|
||||
|
||||
<tt-loader v-if="graphs.length === 0"></tt-loader>
|
||||
|
||||
<template v-for="graph in graphs">
|
||||
<tt-graph :data="graph.data" :labels="graph.labels" :header="graph.name"></tt-graph>
|
||||
</template>
|
||||
</div>
|
||||
`,
|
||||
data() {
|
||||
return {
|
||||
graphs: [],
|
||||
hostname: ''
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
// get hostname from url params
|
||||
this.hostname = new URLSearchParams(window.location.search).get('hostname');
|
||||
console.log(this.hostname);
|
||||
// get id from url params
|
||||
const id = new URLSearchParams(window.location.search).get('id');
|
||||
const response = await axios.get('/Graphing/data?id=' + id);
|
||||
const data = response.data;
|
||||
|
||||
const graphs = {};
|
||||
|
||||
for (const item in data) {
|
||||
// Create graphs.[item.name.split(':')[0]] if it doesn't exist
|
||||
if (!graphs[data[item].name.split(':')[0]]) {
|
||||
graphs[data[item].name.split(':')[0]] = {
|
||||
name: data[item].name.split(':')[0],
|
||||
data: [],
|
||||
labels: []
|
||||
}
|
||||
}
|
||||
|
||||
// Add the data to the graph but check if it's received or sent and already exists
|
||||
|
||||
if (data[item].name.split(':')[1].includes('received') && graphs[data[item].name.split(':')[0]].data.find(data => data.label.includes('received'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data[item].name.split(':')[1].includes('sent') && graphs[data[item].name.split(':')[0]].data.find(data => data.label.includes('sent'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
graphs[data[item].name.split(':')[0]].data.push({
|
||||
label: data[item].name.split(':')[1],
|
||||
data: data[item].values.map(value => value.value),
|
||||
fill: false,
|
||||
borderColor: data[item].name.includes('received') ? 'rgb(75, 192, 192)' : 'rgb(192, 75, 75)',
|
||||
tension: 0.1
|
||||
});
|
||||
}
|
||||
|
||||
// Add the labels to the this.graphs
|
||||
for (const graph in graphs) {
|
||||
graphs[graph].labels = data[Object.keys(data).find(key => data[key].name.includes(graph))].values.map(value => value.clock);
|
||||
this.graphs.push(graphs[graph]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user