Newer
Older
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {TopologyService} from '../topology.service';
import {OverAllService} from '../../overAll/overAll.service';
import {NzMessageService} from 'ng-zorro-antd';
import {pageSize} from '../../app.constants';
import {DatePipe} from '@angular/common';
import {setInterval, clearInterval} from 'timers';
import { NgxEchartsModule } from 'ngx-echarts';
selector: 'smart-flow-trend',
templateUrl: './flow-trend.component.html',
styles: []
//实时图表
nowChartOption;
inNowEchartData = [];
outNowEchartData = [];
constructor(private topologySer: TopologyService, private overAllSer: OverAllService,
this.obj.startTime = this.datePipe.transform(today, 'yyyy-MM-dd') + ' 00:00:00';
this.obj.endTime = this.datePipe.transform(today, 'yyyy-MM-dd') + ' 23:59:59';
this.time_ = setInterval(()=>{
if(this.obj.hostid){
this.findByTime();
}
//获取流量
getList() {
this.outNowEchartData = [];
this.inNowEchartData = [];
this.obj.hostid = null;
this.onchange();
}
getListIO() {
this.outNowEchartData = [];
this.inNowEchartData = [];
this.getInList();
this.getOutList();
}
(res) => {
if (res.errCode == 10000) {
this.groupList = res.data;
//切换图表类型
changeEchartType(type){
this.echartType = type;
}
'hostExtend': {
'superiorHostid': null
}
};
this.overAllSer.findDetail(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.hostList = res.data;
if (this.hostList) {
this.obj.hostid = this.hostList[0].hostid + '';
setNowEchart(){
let itemStyle = {
normal: {},
emphasis: {
barBorderWidth: 1,
shadowBlur: 10,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(0,0,0,0.5)'
}
};
this.nowChartOption = {
title: {
left: 'center',
},
backgroundColor: '#eee',
tooltip: {
formatter: (params) => {
if(params.data){
let res = params.seriesName;
res += '<br/>时间:' + params.name;
let Mbps = 1000 * 1000;
let kbps = 1000;
let size = Math.abs(params.data);
if (size / Mbps > 1) {
res += '<br/>流量:' + (size / Mbps).toFixed(2) + 'Mbps';
} else if (size / kbps > 1) {
res += '<br/>流量:' + (size / kbps).toFixed(2) + 'kbps';
} else {
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
}
return res;
}
}
},
xAxis: {
data: this.inNowEchartData.map(e => {
let date = this.datePipe.transform(e.clock, 'yyyy-MM-dd HH:mm');
return date;
}),
name: '时间',
},
dataZoom: [{
startValue: this.obj.startTime
}, {
type: 'inside'
}],
yAxis: {
inverse: true,
splitArea: {show: false},
type: 'value',
axisLabel: { //Y轴数据
formatter: function(value) {
return Math.abs(value) / 10000 + ' kbps'; //负数取绝对值变正数
},
textStyle: {
color: '#666'
}
},
},
grid: {
left: 100
},
series: [
{
name: '进口流量',
type: 'line',
stack: 'one',
itemStyle: itemStyle,
data: this.inNowEchartData.map(e => {
})
},
{
name: '出口流量',
type: 'line',
stack: 'one',
itemStyle: itemStyle,
data: this.outNowEchartData.map(e => {
this.inNowEchartData=res.data.in;
this.outNowEchartData=res.data.out;
if(this.inNowEchartData.length == 0 && this.outNowEchartData.length == 0){
this.data.now = true;
this.message.warning("实时流量数据暂无");
}else{
this.data.now = false;
this.flashEcharts();
}
);
}
//实时刷新图表
flashEcharts() {
let itemStyle = {
normal: {},
emphasis: {
barBorderWidth: 1,
shadowBlur: 10,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(0,0,0,0.5)'
}
};
legend: {
data: ['进口流量', '出口流量'],
align: 'left',
left: 10
},
backgroundColor: '#eee',
tooltip: {
formatter: (params) => {
if(params.data){
let res = params.seriesName;
res += '<br/>时间:' + params.name;
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 {
}),
name: '时间',
},
dataZoom: [{
startValue: this.obj.startTime
}, {
type: 'inside'
}],
yAxis: {
inverse: true,
splitArea: {show: false},
type: 'value',
axisLabel: { //Y轴数据
formatter: function(value) {
return Math.abs(value) / 10000 + ' kbps'; //负数取绝对值变正数
},
textStyle: {
color: '#666'
}
},
},
grid: {
left: 100
},
series: [
{
name: '进口流量',
type: 'line',
stack: 'one',
itemStyle: itemStyle,
data: this.inNowEchartData.map(e => {
})
},
{
name: '出口流量',
type: 'line',
stack: 'one',
itemStyle: itemStyle,
data: this.outNowEchartData.map(e => {
hostid: this.obj.hostid,
groupid: this.obj.groupid,
type: 'in',
limit: '1000'
};
this.topologySer.findTrendData(data).subscribe(
(res) => {
this.inEchartData = res.data.map(e=>{
const a = {
clock:this.datePipe.transform( e.clock,"yyyy-MM-dd HH:mm" ),
avg:e.avg
}
return a;
});
this.outEchartData = res.data.map(e=>{
const d = {
clock:this.datePipe.transform( e.clock,"yyyy-MM-dd HH:mm" ),
avg:e.avg
}
return d;
});
if( this.inEchartData.length == 0 && this.outEchartData.length == 0){
this.data.history = true;
}else{
this.data.history = false;
}
emphasis: {
barBorderWidth: 1,
shadowBlur: 10,
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowColor: 'rgba(0,0,0,0.5)'
}
};
legend: {
data: ['进口流量', '出口流量'],
align: 'left',
left: 10
},
if (size / Mbps > 1) {
res += '<br/>流量:' + (size / Mbps).toFixed(2) + 'Mbps';
} else if (size / kbps > 1) {
res += '<br/>流量:' + (size / kbps).toFixed(2) + 'kbps';
} else {
data: this.inEchartData.map(e => {
let date = this.datePipe.transform(e.clock, 'yyyy-MM-dd HH:mm');
dataZoom: [{
startValue: this.obj.startTime
}, {
type: 'inside'
}],
type: 'value',
axisLabel: { //Y轴数据
formatter: function(value) {
return Math.abs(value) / 10000 + ' kbps'; //负数取绝对值变正数
type: 'in',
hostid: this.obj.hostid,
startTime: this.obj.startTime,
endTime: this.obj.endTime,
};
this.topologySer.findTrend(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.inList = res.data.data;
this.inTotalNum = res.data.totalNum;
hostid: this.obj.hostid,
startTime: this.obj.startTime,
endTime: this.obj.endTime,
this.topologySer.findTrend(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.outList = res.data.data;
this.outTotalNum = res.data.totalNum;
let day1, day2;
switch (this.timeType) {
case'1': {
this.obj.startTime = this.datePipe.transform(nowDate, 'yyyy-MM-dd') + ' 00:00:00';
this.obj.endTime = this.datePipe.transform(nowDate, 'yyyy-MM-dd') + ' 23:59:59';
case'2': {
day1 = nowDate - 1 * 24 * 60 * 60 * 1000;
this.obj.startTime = this.datePipe.transform(day1, 'yyyy-MM-dd') + ' 00:00:00';
this.obj.endTime = this.datePipe.transform(day1, 'yyyy-MM-dd') + ' 23:59:59';
this.obj.startTime = this.datePipe.transform(day1, 'yyyy-MM-dd') + ' 00:00:00';
this.obj.endTime = this.datePipe.transform(day2, 'yyyy-MM-dd') + ' 23:59:59';
this.obj.startTime = this.datePipe.transform(day1, 'yyyy-MM-dd') + ' 00:00:00';
this.obj.endTime = this.datePipe.transform(day2, 'yyyy-MM-dd') + ' 23:59:59';
search() {
if (this.timeType == '5') {
this.obj.startTime = this.datePipe.transform(this.timeBegin, 'yyyy-MM-dd HH:mm:ss');
this.obj.endTime = this.datePipe.transform(this.timeEnd, 'yyyy-MM-dd HH:mm:ss');
}
this.getEcharts(null);
this.getInList();
this.getOutList();