2018-08-18 04:52:06 +09:00
|
|
|
<template>
|
|
|
|
<div class="zyknedwtlthezamcjlolyusmipqmjgxz">
|
2018-11-03 02:06:34 +09:00
|
|
|
<div ref="cpu"></div>
|
|
|
|
<div ref="mem"></div>
|
2018-08-18 04:52:06 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-03 02:06:34 +09:00
|
|
|
import * as ApexCharts from 'apexcharts';
|
2018-08-18 04:52:06 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
props: ['connection'],
|
2018-11-03 02:06:34 +09:00
|
|
|
|
2018-08-18 04:52:06 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
stats: [],
|
2018-11-03 02:06:34 +09:00
|
|
|
cpuChart: null,
|
|
|
|
memChart: null,
|
2018-08-18 04:52:06 +09:00
|
|
|
cpuP: '',
|
|
|
|
memP: ''
|
|
|
|
};
|
|
|
|
},
|
2018-11-03 02:06:34 +09: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-18 04:52:06 +09:00
|
|
|
mounted() {
|
|
|
|
this.connection.on('stats', this.onStats);
|
|
|
|
this.connection.on('statsLog', this.onStatsLog);
|
2018-10-09 15:08:31 +09:00
|
|
|
this.connection.send('requestLog', {
|
2018-10-13 19:25:59 +09:00
|
|
|
id: Math.random().toString().substr(2, 8),
|
2018-08-19 03:32:01 +09:00
|
|
|
length: 200
|
2018-08-18 04:52:06 +09:00
|
|
|
});
|
2018-11-03 02:06:34 +09: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-18 04:52:06 +09:00
|
|
|
},
|
2018-11-03 02:06:34 +09:00
|
|
|
|
2018-08-18 04:52:06 +09:00
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('stats', this.onStats);
|
|
|
|
this.connection.off('statsLog', this.onStatsLog);
|
|
|
|
},
|
2018-11-03 02:06:34 +09:00
|
|
|
|
2018-08-18 04:52:06 +09:00
|
|
|
methods: {
|
|
|
|
onStats(stats) {
|
|
|
|
this.stats.push(stats);
|
2018-08-19 03:32:01 +09:00
|
|
|
if (this.stats.length > 200) this.stats.shift();
|
2018-08-18 04:52:06 +09:00
|
|
|
|
|
|
|
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
|
|
|
|
this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0);
|
|
|
|
},
|
2018-11-03 02:06:34 +09:00
|
|
|
|
2018-08-18 04:52:06 +09:00
|
|
|
onStatsLog(statsLog) {
|
2018-08-19 03:32:01 +09:00
|
|
|
statsLog.reverse().forEach(stats => this.onStats(stats));
|
2018-08-18 04:52:06 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-28 19:59:19 +09:00
|
|
|
.zyknedwtlthezamcjlolyusmipqmjgxz
|
2018-11-03 02:06:34 +09:00
|
|
|
display flex
|
|
|
|
|
|
|
|
> div
|
2018-08-18 04:52:06 +09:00
|
|
|
display block
|
2018-11-03 02:06:34 +09:00
|
|
|
flex 1
|
|
|
|
padding 32px
|
|
|
|
box-shadow 0 2px 4px rgba(0, 0, 0, 0.1)
|
|
|
|
background var(--face)
|
|
|
|
border-radius 8px
|
2018-08-18 04:52:06 +09:00
|
|
|
|
|
|
|
&:first-child
|
2018-11-03 02:06:34 +09:00
|
|
|
margin-right 16px
|
2018-08-18 04:52:06 +09:00
|
|
|
|
|
|
|
</style>
|