Sharkey/src/client/app/admin/views/cpu-memory.vue

135 lines
2.3 KiB
Vue
Raw Normal View History

2018-08-17 21:52:06 +02:00
<template>
<div class="zyknedwtlthezamcjlolyusmipqmjgxz">
2018-11-02 18:06:34 +01:00
<div ref="cpu"></div>
<div ref="mem"></div>
2018-08-17 21:52:06 +02:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-11-02 18:06:34 +01:00
import * as ApexCharts from 'apexcharts';
2018-08-17 21:52:06 +02:00
export default Vue.extend({
props: ['connection'],
2018-11-02 18:06:34 +01:00
2018-08-17 21:52:06 +02:00
data() {
return {
stats: [],
2018-11-02 18:06:34 +01:00
cpuChart: null,
memChart: null,
2018-08-17 21:52:06 +02:00
cpuP: '',
memP: ''
};
},
2018-11-02 18:06:34 +01:00
watch: {
stats(stats) {
this.cpuChart.updateSeries([{
data: stats.map((x, i) => ({ x: i, y: x.cpu_usage }))
}]);
this.memChart.updateSeries([{
data: stats.map((x, i) => ({ x: i, y: (x.mem.used / x.mem.total) }))
}]);
}
},
2018-08-17 21:52:06 +02:00
mounted() {
this.connection.on('stats', this.onStats);
this.connection.on('statsLog', this.onStatsLog);
2018-10-09 08:08:31 +02:00
this.connection.send('requestLog', {
2018-10-13 12:25:59 +02:00
id: Math.random().toString().substr(2, 8),
length: 200
2018-08-17 21:52:06 +02:00
});
2018-11-02 18:06:34 +01:00
const chartOpts = {
chart: {
type: 'area',
height: 300,
animations: {
dynamicAnimation: {
enabled: false
}
},
toolbar: {
show: false
}
},
dataLabels: {
enabled: false
},
grid: {
clipMarkers: false,
},
stroke: {
curve: 'straight',
width: 2
},
series: [{
data: []
}],
xaxis: {
type: 'numeric',
labels: {
show: false
}
},
yaxis: {
show: false,
min: 0,
max: 1
}
};
this.cpuChart = new ApexCharts(this.$refs.cpu, Object.assign({}, chartOpts, {
title: {
text: 'CPU'
}
}));
this.memChart = new ApexCharts(this.$refs.mem, Object.assign({}, chartOpts, {
title: {
text: 'MEM'
}
}));
this.cpuChart.render();
this.memChart.render();
2018-08-17 21:52:06 +02:00
},
2018-11-02 18:06:34 +01:00
2018-08-17 21:52:06 +02:00
beforeDestroy() {
this.connection.off('stats', this.onStats);
this.connection.off('statsLog', this.onStatsLog);
},
2018-11-02 18:06:34 +01:00
2018-08-17 21:52:06 +02:00
methods: {
onStats(stats) {
this.stats.push(stats);
if (this.stats.length > 200) this.stats.shift();
2018-08-17 21:52:06 +02:00
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0);
},
2018-11-02 18:06:34 +01:00
2018-08-17 21:52:06 +02:00
onStatsLog(statsLog) {
statsLog.reverse().forEach(stats => this.onStats(stats));
2018-08-17 21:52:06 +02:00
}
}
});
</script>
<style lang="stylus" scoped>
2018-09-28 12:59:19 +02:00
.zyknedwtlthezamcjlolyusmipqmjgxz
2018-11-02 18:06:34 +01:00
display flex
> div
2018-08-17 21:52:06 +02:00
display block
2018-11-02 18:06:34 +01:00
flex 1
padding 32px
box-shadow 0 2px 4px rgba(0, 0, 0, 0.1)
background var(--face)
border-radius 8px
2018-08-17 21:52:06 +02:00
&:first-child
2018-11-02 18:06:34 +01:00
margin-right 16px
2018-08-17 21:52:06 +02:00
</style>