2018-08-17 19:52:06 +00:00
|
|
|
<template>
|
|
|
|
<div class="zyknedwtlthezamcjlolyusmipqmjgxz">
|
2018-11-03 04:30:57 +00:00
|
|
|
<div>
|
|
|
|
<header>
|
2018-11-03 04:39:17 +00:00
|
|
|
<span>%fa:microchip% CPU <span>{{ cpuP }}%</span></span>
|
2018-11-03 04:30:57 +00:00
|
|
|
<span v-if="meta">{{ meta.cpu.model }}</span>
|
|
|
|
</header>
|
|
|
|
<div ref="cpu"></div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<header>
|
2018-11-03 04:39:17 +00:00
|
|
|
<span>%fa:memory% MEM <span>{{ memP }}%</span></span>
|
|
|
|
<span v-if="meta"></span>
|
2018-11-03 04:30:57 +00:00
|
|
|
</header>
|
|
|
|
<div ref="mem"></div>
|
|
|
|
</div>
|
2018-08-17 19:52:06 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-11-02 17:06:34 +00:00
|
|
|
import * as ApexCharts from 'apexcharts';
|
2018-08-17 19:52:06 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
props: ['connection'],
|
2018-11-02 17:06:34 +00:00
|
|
|
|
2018-08-17 19:52:06 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
stats: [],
|
2018-11-02 17:06:34 +00:00
|
|
|
cpuChart: null,
|
|
|
|
memChart: null,
|
2018-08-17 19:52:06 +00:00
|
|
|
cpuP: '',
|
2018-11-03 04:30:57 +00:00
|
|
|
memP: '',
|
|
|
|
meta: null
|
2018-08-17 19:52:06 +00:00
|
|
|
};
|
|
|
|
},
|
2018-11-02 17:06:34 +00: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 19:52:06 +00:00
|
|
|
mounted() {
|
2018-11-03 04:30:57 +00:00
|
|
|
(this as any).os.getMeta().then(meta => {
|
|
|
|
this.meta = meta;
|
|
|
|
});
|
|
|
|
|
2018-08-17 19:52:06 +00:00
|
|
|
this.connection.on('stats', this.onStats);
|
|
|
|
this.connection.on('statsLog', this.onStatsLog);
|
2018-10-09 06:08:31 +00:00
|
|
|
this.connection.send('requestLog', {
|
2018-10-13 10:25:59 +00:00
|
|
|
id: Math.random().toString().substr(2, 8),
|
2018-08-18 18:32:01 +00:00
|
|
|
length: 200
|
2018-08-17 19:52:06 +00:00
|
|
|
});
|
2018-11-02 17:06:34 +00:00
|
|
|
|
|
|
|
const chartOpts = {
|
|
|
|
chart: {
|
|
|
|
type: 'area',
|
2018-11-02 18:08:41 +00:00
|
|
|
height: 200,
|
2018-11-02 17:06:34 +00:00
|
|
|
animations: {
|
|
|
|
dynamicAnimation: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toolbar: {
|
|
|
|
show: false
|
2018-11-03 04:30:57 +00:00
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
enabled: false
|
2018-11-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
dataLabels: {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
clipMarkers: false,
|
2018-11-04 02:08:03 +00:00
|
|
|
borderColor: 'rgba(0, 0, 0, 0.1)'
|
2018-11-02 17:06:34 +00:00
|
|
|
},
|
|
|
|
stroke: {
|
|
|
|
curve: 'straight',
|
|
|
|
width: 2
|
|
|
|
},
|
2018-11-03 04:30:57 +00:00
|
|
|
tooltip: {
|
|
|
|
enabled: false
|
|
|
|
},
|
2018-11-02 17:06:34 +00:00
|
|
|
series: [{
|
|
|
|
data: []
|
|
|
|
}],
|
|
|
|
xaxis: {
|
|
|
|
type: 'numeric',
|
|
|
|
labels: {
|
|
|
|
show: false
|
2018-11-03 04:30:57 +00:00
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
enabled: false
|
2018-11-02 17:06:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxis: {
|
|
|
|
show: false,
|
|
|
|
min: 0,
|
|
|
|
max: 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-03 04:30:57 +00:00
|
|
|
this.cpuChart = new ApexCharts(this.$refs.cpu, chartOpts);
|
|
|
|
this.memChart = new ApexCharts(this.$refs.mem, chartOpts);
|
2018-11-02 17:06:34 +00:00
|
|
|
|
|
|
|
this.cpuChart.render();
|
|
|
|
this.memChart.render();
|
2018-08-17 19:52:06 +00:00
|
|
|
},
|
2018-11-02 17:06:34 +00:00
|
|
|
|
2018-08-17 19:52:06 +00:00
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('stats', this.onStats);
|
|
|
|
this.connection.off('statsLog', this.onStatsLog);
|
|
|
|
},
|
2018-11-02 17:06:34 +00:00
|
|
|
|
2018-08-17 19:52:06 +00:00
|
|
|
methods: {
|
|
|
|
onStats(stats) {
|
|
|
|
this.stats.push(stats);
|
2018-08-18 18:32:01 +00:00
|
|
|
if (this.stats.length > 200) this.stats.shift();
|
2018-08-17 19:52:06 +00:00
|
|
|
|
|
|
|
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
|
|
|
|
this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0);
|
|
|
|
},
|
2018-11-02 17:06:34 +00:00
|
|
|
|
2018-08-17 19:52:06 +00:00
|
|
|
onStatsLog(statsLog) {
|
2018-08-18 18:32:01 +00:00
|
|
|
statsLog.reverse().forEach(stats => this.onStats(stats));
|
2018-08-17 19:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-09-28 10:59:19 +00:00
|
|
|
.zyknedwtlthezamcjlolyusmipqmjgxz
|
2018-11-02 17:06:34 +00:00
|
|
|
display flex
|
|
|
|
|
|
|
|
> div
|
2018-08-17 19:52:06 +00:00
|
|
|
display block
|
2018-11-02 17:06:34 +00:00
|
|
|
flex 1
|
2018-11-03 11:10:55 +00:00
|
|
|
padding 20px 12px 0 12px
|
2018-11-02 17:06:34 +00:00
|
|
|
box-shadow 0 2px 4px rgba(0, 0, 0, 0.1)
|
|
|
|
background var(--face)
|
|
|
|
border-radius 8px
|
2018-08-17 19:52:06 +00:00
|
|
|
|
|
|
|
&:first-child
|
2018-11-02 17:06:34 +00:00
|
|
|
margin-right 16px
|
2018-08-17 19:52:06 +00:00
|
|
|
|
2018-11-03 04:30:57 +00:00
|
|
|
> header
|
|
|
|
display flex
|
2018-11-03 11:10:55 +00:00
|
|
|
padding 0 8px
|
|
|
|
margin-bottom -16px
|
2018-11-04 02:08:03 +00:00
|
|
|
color var(--adminDashboardCardFg)
|
2018-11-03 04:30:57 +00:00
|
|
|
font-size 14px
|
|
|
|
|
|
|
|
> span
|
|
|
|
&:last-child
|
|
|
|
margin-left auto
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
> span
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
> div
|
2018-11-03 11:10:55 +00:00
|
|
|
margin-bottom -10px
|
2018-11-03 04:30:57 +00:00
|
|
|
|
2018-11-04 06:16:05 +00:00
|
|
|
@media (max-width 1000px)
|
|
|
|
display block
|
|
|
|
margin-bottom 26px
|
|
|
|
|
|
|
|
> div
|
|
|
|
&:first-child
|
|
|
|
margin-right 0
|
|
|
|
margin-bottom 26px
|
|
|
|
|
2018-08-17 19:52:06 +00:00
|
|
|
</style>
|