2018-08-17 21:52:06 +02:00
|
|
|
<template>
|
|
|
|
<div class="zyknedwtlthezamcjlolyusmipqmjgxz">
|
2018-11-03 05:30:57 +01:00
|
|
|
<div>
|
|
|
|
<header>
|
|
|
|
<span>CPU <span>{{ cpuP }}%</span></span>
|
|
|
|
<span v-if="meta">{{ meta.cpu.model }}</span>
|
|
|
|
</header>
|
|
|
|
<div ref="cpu"></div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<header>
|
|
|
|
<span>MEM <span>{{ memP }}%</span></span>
|
|
|
|
</header>
|
|
|
|
<div ref="mem"></div>
|
|
|
|
</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: '',
|
2018-11-03 05:30:57 +01:00
|
|
|
memP: '',
|
|
|
|
meta: null
|
2018-08-17 21:52:06 +02:00
|
|
|
};
|
|
|
|
},
|
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() {
|
2018-11-03 05:30:57 +01:00
|
|
|
(this as any).os.getMeta().then(meta => {
|
|
|
|
this.meta = meta;
|
|
|
|
});
|
|
|
|
|
2018-08-17 21:52:06 +02:00
|
|
|
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),
|
2018-08-18 20:32:01 +02:00
|
|
|
length: 200
|
2018-08-17 21:52:06 +02:00
|
|
|
});
|
2018-11-02 18:06:34 +01:00
|
|
|
|
|
|
|
const chartOpts = {
|
|
|
|
chart: {
|
|
|
|
type: 'area',
|
2018-11-02 19:08:41 +01:00
|
|
|
height: 200,
|
2018-11-02 18:06:34 +01:00
|
|
|
animations: {
|
|
|
|
dynamicAnimation: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toolbar: {
|
|
|
|
show: false
|
2018-11-03 05:30:57 +01:00
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
enabled: false
|
2018-11-02 18:06:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
dataLabels: {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
clipMarkers: false,
|
|
|
|
},
|
|
|
|
stroke: {
|
|
|
|
curve: 'straight',
|
|
|
|
width: 2
|
|
|
|
},
|
2018-11-03 05:30:57 +01:00
|
|
|
tooltip: {
|
|
|
|
enabled: false
|
|
|
|
},
|
2018-11-02 18:06:34 +01:00
|
|
|
series: [{
|
|
|
|
data: []
|
|
|
|
}],
|
|
|
|
xaxis: {
|
|
|
|
type: 'numeric',
|
|
|
|
labels: {
|
|
|
|
show: false
|
2018-11-03 05:30:57 +01:00
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
enabled: false
|
2018-11-02 18:06:34 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxis: {
|
|
|
|
show: false,
|
|
|
|
min: 0,
|
|
|
|
max: 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-03 05:30:57 +01:00
|
|
|
this.cpuChart = new ApexCharts(this.$refs.cpu, chartOpts);
|
|
|
|
this.memChart = new ApexCharts(this.$refs.mem, chartOpts);
|
2018-11-02 18:06:34 +01:00
|
|
|
|
|
|
|
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);
|
2018-08-18 20:32:01 +02:00
|
|
|
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) {
|
2018-08-18 20:32:01 +02:00
|
|
|
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
|
2018-11-03 05:30:57 +01:00
|
|
|
padding 20px 16px 0 16px
|
2018-11-02 18:06:34 +01:00
|
|
|
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
|
|
|
|
2018-11-03 05:30:57 +01:00
|
|
|
> header
|
|
|
|
display flex
|
|
|
|
padding 0 4px
|
|
|
|
margin-bottom -8px
|
|
|
|
color #555
|
|
|
|
font-size 14px
|
|
|
|
|
|
|
|
> span
|
|
|
|
&:last-child
|
|
|
|
margin-left auto
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
> span
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
> div
|
|
|
|
margin-bottom -8px
|
|
|
|
|
2018-08-17 21:52:06 +02:00
|
|
|
</style>
|