dockersstatus.vue
5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<template>
<div class="innnerBox">
<div class="contentbox">
<el-col :span="12" v-for="(item,index) in containeslist" :key="index">
<el-col :span="4" hidden>
<div class="sylist">CPU</div>
<div class="sylist">内存</div>
<div class="sylist">GPU</div>
<!-- <div class="sylist">4</div> -->
</el-col>
<el-col :span="24">
<div :id="item.container" class="chartbox"></div>
</el-col>
</el-col>
</div>
</div>
</template>
<script>
export default {
data() {
return {
containeslist: [],
stautsclock:null,
};
},
methods: {
getcontainer() {
this.$api .device.containeslist().then(res => {
this.containeslist = res;
res.map(ele => {
this.gpuresource(ele);
});
this.stautsclock = setInterval(() => {
res.map(ele => {
this.gpuresource(ele);
});
}, 10000)
});
},
gpuresource(val){
let start= this.$moment().subtract(1, "h").format("YYYY-MM-DD HH:mm:ss"); //当前时间前一天
let end= this.$moment().format("YYYY-MM-DD HH:mm:ss");
let params ={
startDt:start,
endDt:end,
container:val.container
}
this.$api.device.gpuresource(params).then(res => {
this.setChart(res,val);
console.log("数据源",res)
});
},
refreshData(val) {
let start= this.$moment().subtract(6, "s").format("YYYY-MM-DD HH:mm:ss"); //当前时间前一天
let end= this.$moment().format("YYYY-MM-DD HH:mm:ss");
let params ={
startDt:start,
endDt:end,
container:val.container
}
this.$api.device.gpuresource(params).then(res => {
if(res.length> 0) {
this.gpuresource(val);
}
});
},
setChart(val,elid) {
var myChart = this.$echarts.init(
document.getElementById(elid.container)
);
var mdata = [];
var cdata = [];
var gdata = [];
var DAY = 3600 * 24 * 1000;
var HOUR = 3600 * 1000;
for (var i = 0; i < val.length; i++) {
mdata.push([new Date( val[i].recordTime.replace('-', '/')).getTime(),parseInt((val[i].memoryUsed/val[i].memoryLimit*100))]);
cdata.push([new Date( val[i].recordTime.replace('-', '/')).getTime(), val[i].cpuPercent]);
gdata.push([new Date( val[i].recordTime.replace('-', '/')).getTime(), parseInt((val[i].resourceMemoryUsed/val[i].resourceMemoryTotal*100))]);
}
console.log("测试数据源",mdata)
//把new Date出来的时间格式转换为data123中的日期格式
var option = {
legend: {
top: 10,
left: 'center',
data: ['内存','CPU','GPU']
},
title: {
left: '12',
text: elid.container,
textStyle:{
//文字颜色
color:'#699',
//字体大小
fontSize:14
}
},
grid:{
x:'4.6%',
y:'9%',
x2:'1%',
y2:'30%',
},
dataZoom: [
{
type: "slider"
},
{
type: "inside"
}
],
xAxis: {
type: "time",
// interval: DAY / 2,
axisLabel: {
// formatter: (value)=> {
// if (value % DAY === 0) {
// var month = this.$echarts.format.formatTime("M月", value);
// var dayOfM = this.$echarts.format.formatTime("d日", value);
// return "{strong|" + dayOfM + "}\n{lite|" + month + "}";
// } else {
// var formatted = this.$echarts.format.formatTime("h点", value);
// return formatted;
// }
// },
rich: {
strong: {
color: "#2784e8",
fontSize: 12,
fontWeight: 700
},
lite: {
color: "#999",
lineHeight: 25,
fontSize: 10
}
}
}
},
yAxis: {},
tooltip: {
trigger: "axis"
},
series: [
{
name:'内存',
type: "line",
showSymbol: false,
data: mdata
},
{
name:'CPU',
type: "line",
showSymbol: false,
data: cdata
},{
name:'GPU',
type: "line",
showSymbol: false,
data: gdata
}
]
};
myChart.setOption(option);
}
},
created() {
this.getcontainer();
},
beforeDestroy(){
clearInterval(this.stautsclock);
this.stautsclock = null;
},
mounted() {}
};
</script>
<style lang="stylus" scoped>
.contentbox {
overflow: hidden;
}
.sylist{
height 60px
margin-top 15px
width 90%
margin 15px auto 0;
border 1px solid #ccc
border-radius 2px
}
.chartbox {
height: 330px;
overflow hidden
}
</style>