2018-08-17 21:52:06 +02:00
|
|
|
<template>
|
|
|
|
<div class="zyknedwtlthezamcjlolyusmipqmjgxz">
|
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
|
|
|
<defs>
|
|
|
|
<linearGradient :id="cpuGradientId" x1="0" x2="0" y1="1" y2="0">
|
|
|
|
<stop offset="0%" stop-color="hsl(180, 80%, 70%)"></stop>
|
|
|
|
<stop offset="100%" stop-color="hsl(0, 80%, 70%)"></stop>
|
|
|
|
</linearGradient>
|
|
|
|
<mask :id="cpuMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
|
|
|
|
<polygon
|
|
|
|
:points="cpuPolygonPoints"
|
|
|
|
fill="#fff"
|
|
|
|
fill-opacity="0.5"/>
|
|
|
|
<polyline
|
|
|
|
:points="cpuPolylinePoints"
|
|
|
|
fill="none"
|
|
|
|
stroke="#fff"
|
2018-08-18 20:32:01 +02:00
|
|
|
stroke-width="1"/>
|
2018-08-17 21:52:06 +02:00
|
|
|
</mask>
|
|
|
|
</defs>
|
|
|
|
<rect
|
|
|
|
x="0" y="0"
|
|
|
|
:width="viewBoxX" :height="viewBoxY"
|
|
|
|
:style="`stroke: none; fill: url(#${ cpuGradientId }); mask: url(#${ cpuMaskId })`"/>
|
2018-08-18 20:32:01 +02:00
|
|
|
<text x="1" y="12">CPU <tspan>{{ cpuP }}%</tspan></text>
|
2018-08-17 21:52:06 +02:00
|
|
|
</svg>
|
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
|
|
|
<defs>
|
|
|
|
<linearGradient :id="memGradientId" x1="0" x2="0" y1="1" y2="0">
|
|
|
|
<stop offset="0%" stop-color="hsl(180, 80%, 70%)"></stop>
|
|
|
|
<stop offset="100%" stop-color="hsl(0, 80%, 70%)"></stop>
|
|
|
|
</linearGradient>
|
|
|
|
<mask :id="memMaskId" x="0" y="0" :width="viewBoxX" :height="viewBoxY">
|
|
|
|
<polygon
|
|
|
|
:points="memPolygonPoints"
|
|
|
|
fill="#fff"
|
|
|
|
fill-opacity="0.5"/>
|
|
|
|
<polyline
|
|
|
|
:points="memPolylinePoints"
|
|
|
|
fill="none"
|
|
|
|
stroke="#fff"
|
2018-08-18 20:32:01 +02:00
|
|
|
stroke-width="1"/>
|
2018-08-17 21:52:06 +02:00
|
|
|
</mask>
|
|
|
|
</defs>
|
|
|
|
<rect
|
|
|
|
x="0" y="0"
|
|
|
|
:width="viewBoxX" :height="viewBoxY"
|
|
|
|
:style="`stroke: none; fill: url(#${ memGradientId }); mask: url(#${ memMaskId })`"/>
|
2018-08-18 20:32:01 +02:00
|
|
|
<text x="1" y="12">MEM <tspan>{{ memP }}%</tspan></text>
|
2018-08-17 21:52:06 +02:00
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import * as uuid from 'uuid';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
props: ['connection'],
|
|
|
|
data() {
|
|
|
|
return {
|
2018-08-18 20:32:01 +02:00
|
|
|
viewBoxX: 200,
|
|
|
|
viewBoxY: 70,
|
2018-08-17 21:52:06 +02:00
|
|
|
stats: [],
|
|
|
|
cpuGradientId: uuid(),
|
|
|
|
cpuMaskId: uuid(),
|
|
|
|
memGradientId: uuid(),
|
|
|
|
memMaskId: uuid(),
|
|
|
|
cpuPolylinePoints: '',
|
|
|
|
memPolylinePoints: '',
|
|
|
|
cpuPolygonPoints: '',
|
|
|
|
memPolygonPoints: '',
|
|
|
|
cpuP: '',
|
|
|
|
memP: ''
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.connection.on('stats', this.onStats);
|
|
|
|
this.connection.on('statsLog', this.onStatsLog);
|
|
|
|
this.connection.send({
|
|
|
|
type: 'requestLog',
|
2018-08-18 20:32:01 +02:00
|
|
|
id: Math.random().toString(),
|
|
|
|
length: 200
|
2018-08-17 21:52:06 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('stats', this.onStats);
|
|
|
|
this.connection.off('statsLog', this.onStatsLog);
|
|
|
|
},
|
|
|
|
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
|
|
|
|
|
|
|
const cpuPolylinePoints = this.stats.map((s, i) => [this.viewBoxX - ((this.stats.length - 1) - i), (1 - s.cpu_usage) * this.viewBoxY]);
|
|
|
|
const memPolylinePoints = this.stats.map((s, i) => [this.viewBoxX - ((this.stats.length - 1) - i), (1 - (s.mem.used / s.mem.total)) * this.viewBoxY]);
|
|
|
|
this.cpuPolylinePoints = cpuPolylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
|
|
|
this.memPolylinePoints = memPolylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
|
|
|
|
|
|
|
this.cpuPolygonPoints = `${this.viewBoxX - (this.stats.length - 1)},${this.viewBoxY} ${this.cpuPolylinePoints} ${this.viewBoxX},${this.viewBoxY}`;
|
|
|
|
this.memPolygonPoints = `${this.viewBoxX - (this.stats.length - 1)},${this.viewBoxY} ${this.memPolylinePoints} ${this.viewBoxX},${this.viewBoxY}`;
|
|
|
|
|
|
|
|
this.cpuP = (stats.cpu_usage * 100).toFixed(0);
|
|
|
|
this.memP = (stats.mem.used / stats.mem.total * 100).toFixed(0);
|
|
|
|
},
|
|
|
|
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>
|
|
|
|
root(isDark)
|
|
|
|
> svg
|
|
|
|
display block
|
|
|
|
width 50%
|
|
|
|
float left
|
|
|
|
|
|
|
|
&:first-child
|
|
|
|
padding-right 5px
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
padding-left 5px
|
|
|
|
|
|
|
|
> text
|
2018-08-18 20:32:01 +02:00
|
|
|
font-size 10px
|
2018-09-28 04:18:56 +02:00
|
|
|
fill var(--chartCaption)
|
2018-08-17 21:52:06 +02:00
|
|
|
|
|
|
|
> tspan
|
|
|
|
opacity 0.5
|
|
|
|
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
.zyknedwtlthezamcjlolyusmipqmjgxz[data-darkmode]
|
|
|
|
root(true)
|
|
|
|
|
|
|
|
.zyknedwtlthezamcjlolyusmipqmjgxz:not([data-darkmode])
|
|
|
|
root(false)
|
|
|
|
|
|
|
|
</style>
|