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