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
| <template>
| <div>
| <div ref="statsChart" style="height: 240px; margin: 20px 0 40px 0"></div>
| </div>
| </template>
|
| <script>
| import { getNettyMqttStats } from '@/api/iot/netty';
| export default {
| data() {
| return {
| timer: null,
| // emqx状态数据
| stats: {},
| mqtt: this.$store.state.user.mqtt,
| };
| },
| created() {
| this.getMqttStats();
| },
| beforeDestroy() {
| this.clearData();
| },
| methods: {
| /** 查询mqtt状态数据*/
| getMqttStats() {
| if (this.mqtt) {
| getNettyMqttStats().then((response) => {
| this.stats = response.data;
| this.drawStats();
| // 轮询
| this.switper();
| });
| } else {
| this.$nextTick(() => {
| // 初始值
| this.stats = {
| 'connections.count': 800,
| 'connections.max': 8000,
| 'sessions.count': 700,
| 'sessions.max': 7000,
| 'topics.count': 600,
| 'topics.max': 6000,
| 'subscribers.count': 500,
| 'subscribers.max': 5000,
| 'routes.count': 400,
| 'routes.max': 4000,
| 'retained.count': 300,
| 'retained.max': 3000,
| };
| this.drawStats();
| // 轮询
| this.switper();
| });
| }
| },
| /** EMQX状态统计 */
| drawStats() {
| // 基于准备好的dom,初始化echarts实例
| let myChart = this.$echarts.init(this.$refs.statsChart);
| var option;
| option = {
| animationDuration: 3000,
| tooltip: {
| trigger: 'axis',
| axisPointer: {
| type: 'shadow',
| },
| backgroundColor: 'rgba(58,73,116,0.7)',
| textStyle: {
| color: 'rgba(65,235,246,1)',
| },
| },
| legend: {
| textStyle: {
| color: 'rgba(65,235,246,1)',
| },
| },
| grid: {
| left: '3%',
| right: '4%',
| bottom: '3%',
| containLabel: true,
| },
| xAxis: {
| type: 'value',
| boundaryGap: [0, 0.01],
| axisLabel: {
| fontSize: 12,
| color: '#fff',
| },
| splitLine: {
| //网格线
| lineStyle: {
| type: 'dashed', //设置网格线类型 dotted:虚线 solid:实线
| color: 'rgba(65,235,246,1)', //网格线颜色
| width: 0.5,
| },
| },
| },
| yAxis: {
| type: 'category',
| axisLabel: {
| fontSize: 12,
| color: '#fff',
| },
| data: this.mqtt ? ['连接数量', '会话数量', '订阅数量', '路由数量', '保留消息'] : ['连接数量', '会话数量', '主题数量', '订阅数量', '路由数量', '保留消息'],
| },
| series: [
| {
| name: '当前数量',
| type: 'bar',
| data: this.mqtt
| ? [this.stats['connection_count'], this.stats['session_count'], this.stats['subscription_count'], this.stats['retain_count'], this.stats['retain_count']]
| : [this.stats['connections.count'], this.stats['sessions.count'], this.stats['topics.count'], this.stats['subscribers.count'], this.stats['routes.count'], this.stats['retained.count']],
| itemStyle: {
| color: '#67e0e3',
| },
| },
| {
| name: this.mqtt ? '累计总数' : '历史最大数',
| type: 'bar',
| data: this.mqtt
| ? [this.stats['connection_total'], this.stats['session_total'], this.stats['subscription_total'], this.stats['retain_total'], this.stats['retain_total']]
| : [this.stats['connections.max'], this.stats['sessions.max'], this.stats['topics.max'], this.stats['subscribers.max'], this.stats['routes.max'], this.stats['retained.max']],
| itemStyle: {
| color: '#ffdb5c',
| },
| },
| ],
| };
| option && myChart.setOption(option);
| },
| clearData() {
| if (this.timer) {
| clearInterval(this.timer);
| this.timer = null;
| }
| },
| //轮询
| switper() {
| if (this.timer) {
| return;
| }
| let looper = (a) => {
| this.getMqttStats();
| };
| this.timer = setInterval(looper, 60000);
| },
| },
| };
| </script>
|
|