Newer
Older
import {Component, OnInit} from '@angular/core';
import {BusinessService} from '../business.service';
selector: 'smart-effect-analysis',
templateUrl: './effect-analysis.component.html',
styles: [
.chart-div {
border: 1px solid #dadada;
margin-top: 20px;
padding: 10px;
}
.chart-left {
margin-left: 20px;
}
.chart-left p {
margin-left: 20px;
}
color = color;
colorArr = ['#f36969', '#02c8cf', '#eaaa00', '#61a600', '#4484d4'];
triggerList; //监测点列表
isLoading = false;
serviceId;
analyObj; //业务信息
obj = {
startTime: '',
endTime: ''
};
//图表
isSpinning = false;
constructor(private busineSer: BusinessService, private overAllSer: OverAllService,
private datePipe: DatePipe, private message: NzMessageService,
public location:Location
) {
changeService() {
this.isLoading = true;
this.getTriggerlist();
this.getInfo();
this.getWeblist();
}
//系统可用性, 监测点, 用户统计
getInfo() {
this.busineSer.serviceAnalysisCount(this.serviceId).subscribe(
(res) => {
if (res.errCode == 10000) {
this.analyObj = res.data;
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
setAnalyOption() {
let echartData = [{
value: this.analyObj.danger,
name: '严重'
}, {
value: this.analyObj.alarm,
name: '告警'
}, {
value: this.analyObj.normal,
name: '正常'
}, {
value: this.analyObj.unknown,
name: '未知'
}];
let rich = {
red: {
color: this.color.red,
padding: [5, 4],
align: 'center'
},
yellow: {
color: this.color.yellow,
align: 'center'
},
green: {
color: this.color.green,
align: 'center',
padding: [21, 0]
},
gray: {
color: this.color.gray,
align: 'center'
},
black: {
color: this.color.black,
padding: [5, 4],
align: 'center'
},
};
this.analyOption = {
title: {
text: '监测点',
left: 'center',
top: '45%',
textStyle: {
fontSiz: 6,
align: 'center'
}
},
legend: {
selectedMode: false,
formatter: (name) => {
let total = this.analyObj.total;
return '{black|' + total + '个}';
},
data: [echartData[0].name],
left: 'center',
top: '35%',
icon: 'none',
align: 'center',
textStyle: {
color: '#fff',
rich: rich
},
},
series: [{
name: '监测点',
type: 'pie',
radius: ['42%', '60%'],
hoverAnimation: false,
color: [this.color.red, this.color.yellow, this.color.green, this.color.gray],
label: {
normal: {
formatter: (params, ticket, callback) => {
let total = 0; //总数量
let percent; //占比
echartData.forEach((value, index, array) => {
total += value.value;
});
if (params.value == 0) {
percent = 0;
} else if (params.value > 0) {
percent = ((params.value / total) * 100).toFixed(1);
}
return '{black|' + params.name + ':}{black|' + params.value + '个}\n{black|' + percent + '%}';
},
rich: rich
},
},
data: echartData
}]
};
}
//业务列表
getServiceList() {
this.busineSer.findRoot().subscribe(
(res) => {
this.rootList = res.data;
this.serviceId = this.rootList[0].serviceid;
this.changeService();
}
//监测点列表
getTriggerlist() {
this.busineSer.triggerList(this.serviceId).subscribe(
(res) => {
if (res.errCode == 10000) {
this.triggerList = res.data;
}
}
);
}
//网站监测列表
getWeblist() {
this.busineSer.findHttptest(this.serviceId).subscribe(
startTime: this.obj.startTime,
endTime: this.obj.endTime,
serviceId: this.serviceId
};
return e.createTime;
}),
boundaryGap: false,
axisTick: {
show: false
},
},
yAxis: {
type: 'value',
axisTick: {
show: false
},
},
series: [
{
name: '在线用户数',
type: 'line',
smooth: true,
symbolSize: 6,
return e.onlineUser;
}),
itemStyle: {
normal: {
color: '#55cece'
}
},
lineStyle: {
normal: {
width: 3
}
}
},
{
name: '重要用户数',
type: 'line',
smooth: true,
symbolSize: 6,
return e.onlineImportantUser;
}),
itemStyle: {
normal: {
color: '#b7a4dc'
}
},
lineStyle: {
normal: {
width: 3
}
}
}]
};
this.userData = true;
this.httptestid = item.httptestid;
this.changeType();
}
//时间改变
changeType() {
this.isSpinning = true;
if(this.timeType =='99') return ;
this.obj.startTime = this.commonSer.getTimeByType(this.timeType).startTime;
this.obj.endTime = this.commonSer.getTimeByType(this.timeType).endTime;
}
//监测图表
findChart() {
const data = {
startTime: this.obj.startTime,
endTime: this.obj.endTime,
limit: '',
httptestid: this.httptestid
};
this.overAllSer.findChart(data).subscribe(
(res) => {
if (res.errCode == 10000) {
const speed = res.data.speed;
this.speed = res.data.speed;
const time = res.data.time;
this.time = res.data.time;
this.setOption(speed, time);
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
//绘制图表
setOption(speed, time) {
this.chartSpeed = {
title: {
text: '速度',
left: '40%',
},
tooltip: {
formatter: (params) => {
if (params.data) {
let res = params.seriesName;
res += '<br/>时间:' + params.name;
let Gbps = 1000 * 1000 * 1000;
let Mbps = 1000 * 1000;
let kbps = 1000;
let size = Math.abs(params.data);
if (size / Gbps > 1) {
res += '<br/>流量:' + (size / Gbps).toFixed(2) + 'Gbps';
} else if (size / Mbps > 1) {
res += '<br/>流量:' + (size / Mbps).toFixed(2) + 'Mbps';
} else if (size / kbps > 1) {
res += '<br/>流量:' + (size / kbps).toFixed(2) + 'kbps';
} else {
res += '<br/>流量:' + (size) + 'bps';
}
return res;
}
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {
show: false
}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: speed[0].data.map(res => {
return res.date;
}),
},
yAxis: {
type: 'value',
axisLabel: { //Y轴数据
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
return Math.abs(value) / 1000 + ' kbps';
},
textStyle: {
color: '#666'
}
},
},
series: speed.map((res1, index) => {
const number = res1.data.map(res2 => {
return res2.val;
});
const obj = {
name: res1.name,
type: 'line',
stack: '总量',
itemStyle: {
normal: {
lineStyle: {
color: this.colorArr[index]
}
}
},
data: number
};
return obj;
})
};
this.chartTime = {
title: {
text: '响应时间',
left: '40%',
},
tooltip: {
// trigger: 'axis',
formatter: (params) => {
if (params.data) {
let res = params.seriesName;
res += '<br/>时间:' + params.name;
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
return res;
}
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {
show: false
}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: time[0].data.map(res => {
return res.date;
})
},
yAxis: {
type: 'value',
axisLabel: { //Y轴数据
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
return value + ' s';
},
textStyle: {
color: '#666'
}
},
},
series: time.map((res1, index) => {
const number = res1.data.map(res2 => {
return res2.val;
});
const obj = {
name: res1.name,
type: 'line',
stack: '总量',
itemStyle: {
normal: {
lineStyle: {
color: this.colorArr[index]
}
}
},
data: number
};
return obj;
})
};
this.isSpinning = false;
}