-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
254 lines (227 loc) · 7.17 KB
/
index.html
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MQTT Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.prod.css" rel="stylesheet" type="text/css">
<style>
.card {
height: 100px;
min-width: 200px;
display: flex;
flex-direction: column;
justify-content: end;
position: relative;
}
.chart {
width: 100%;
height: 100px;
position: absolute;
bottom: 0;
}
@property --num {
syntax: '<number>';
initial-value: 0;
inherits: false;
}
@property --temp {
syntax: "<number>";
initial-value: 0;
inherits: false;
}
@property --v1 {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
@property --v2 {
syntax: "<integer>";
initial-value: 0;
inherits: false;
}
.anim2 {
transition: --num 10s;
--temp: var(--num);
--v1: max(var(--temp) - 0.5, 0);
--v2: max((var(--temp) - var(--v1)) * 100 - 0.5, 0);
counter-reset: v1 var(--v1) v2 var(--v2);
}
.anim2::after {
content: "." counter(v2);
font-size: 12pt;
}
.anim2::before {
content: counter(v1);
}
.anim {
transition: --num 1s;
counter-reset: num var(--num);
}
.anim::after {
content: counter(num);
}
</style>
</head>
<body class="dark">
<div id="q-app" class="q-pa-lg">
<div class="q-gutter-sm row">
<metric :ref="(el) => (metricsRef[t] = el)" v-for="t in topics" :topic="t"></metric>
</div>
</div>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.umd.prod.js"></script>
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
<script>
const { ref, useTemplateRef, defineComponent, computed, onMounted } = Vue
// Parse URL parameters
const urlParams = new URLSearchParams(window.location.search);
const broker = urlParams.get('broker') || 'mqtt.bein.tech'; // Default broker if not provided
const port = urlParams.get('port') || '443'; // Default WebSocket port
const username = urlParams.get('username');
const password = urlParams.get('password');
// Construct MQTT connection options
const options = {
protocol: 'wss', // WebSocket protocol
hostname: broker,
port: parseInt(port, 10),
};
// Add authentication if username and password are provided
if (username && password) {
options.username = username;
options.password = password;
}
const client = mqtt.connect(options)
client.setMaxListeners(10)
// Define a reusable component for each dashboard card
const metric = defineComponent({
props: ['topic'],
setup(props) {
const value = ref(0)
const dataPoints = ref([])
const timestamps = ref([])
const label = computed(() => {
return props.topic.split('/').splice(2).join(' ');
})
// Plotly chart renderer for the background
function renderChart() {
const chartElement = document.getElementById(`${label.value}-chart`)
const trace = {
x: timestamps.value,
y: dataPoints.value,
type: 'scatter',
mode: 'lines',
fill: 'tozeroy', // Fills the area below the line
fillcolor: 'rgba(0, 123, 255, 0.1)', // Semi-transparent blue fill color
line: { color: 'rgba(0, 123, 255, 0.8)',shape: 'spline', smoothing: 1.3 }
}
const layout = {
margin: { l: 0, r: 0, t: 0, b: 0 }, // Remove margins
showlegend: false, // Hide legend
plot_bgcolor: 'rgba(0,0,0,0)', // Transparent plot background
paper_bgcolor: 'rgba(0,0,0,0)',
xaxis: { tickformat: '%H:%M:%S', "visible": false,
showgrid: false,
zeroline: false,
showline: false, // Hide axis line
showticklabels: false // Hide tick labels
},
yaxis: { fixedrange: true,showgrid: false,zeroline: false, visible: false, showline: false, // Hide axis line
showticklabels: false // Hide tick labels
},
}
Plotly.newPlot(chartElement, [trace], layout, { staticPlot: true })
}
function add(message) {
const metricValue = parseFloat(message)||message;
value.value = metricValue;
const timestamp = new Date().toLocaleTimeString()
dataPoints.value.push(metricValue)
timestamps.value.push(timestamp)
if (dataPoints.value.length > 20) {
dataPoints.value.shift()
timestamps.value.shift()
}
renderChart()
}
function isDecimalClass(v,c1,c2){
return Number.isSafeInteger(v)?c1:c2
}
return { value, label, isDecimalClass, add }
},
template: `
<q-card class="card">
<div :id="label + '-chart'" class="chart"></div>
<q-card-section class="q-py-sm">
<div class="text" v-html="label"></div>
<div class="text-h5" :class="{[isDecimalClass(value,'anim','anim2')]:true}" :style="{'--num':value}"></div>
</q-card-section>
</q-card>
`
})
const app = Vue.createApp({
components: { metric },
setup(){
const metricsRef = ref({});
Quasar.Dark.set(true);
const topics = `$SYS/broker/bytes/received
$SYS/broker/bytes/sent
$SYS/broker/clients/connected
$SYS/broker/subscriptions/count
$SYS/broker/clients/expired
$SYS/broker/clients/disconnected
$SYS/broker/clients/maximum
$SYS/broker/clients/total
$SYS/broker/heap/current size
$SYS/broker/heap/maximum size
$SYS/broker/messages/inflight
$SYS/broker/messages/received
$SYS/broker/messages/sent
$SYS/broker/publish/messages/dropped
$SYS/broker/publish/messages/received
$SYS/broker/publish/messages/sent
$SYS/broker/retained messages/count
$SYS/broker/store/messages/count
$SYS/broker/load/messages/received/5min
$SYS/broker/load/messages/received/15min
$SYS/broker/load/messages/sent/1min
$SYS/broker/load/messages/sent/5min
$SYS/broker/load/messages/sent/15min
$SYS/broker/load/publish/received/1min
$SYS/broker/load/publish/received/5min
$SYS/broker/load/publish/received/15min
$SYS/broker/load/publish/sent/1min
$SYS/broker/load/publish/sent/5min
$SYS/broker/load/publish/sent/15min
$SYS/broker/load/bytes/received/1min
$SYS/broker/load/bytes/received/5min
$SYS/broker/load/bytes/received/15min
$SYS/broker/load/bytes/sent/1min
$SYS/broker/load/bytes/sent/5min
$SYS/broker/load/bytes/sent/15min
$SYS/broker/load/sockets/1min
$SYS/broker/load/sockets/5min
$SYS/broker/load/sockets/15min
$SYS/broker/load/connections/1min
$SYS/broker/load/connections/5min
$SYS/broker/load/connections/15min
$SYS/broker/store/messages/bytes
$SYS/broker/version
$SYS/broker/uptime`.split('\n');
client.on('connect', () => {
client.subscribe("$SYS/broker/#")
client.subscribe("$SYS/broker/clients/connected")
})
client.on('message', (topic, message) => {
message = message.toString();
if(metricsRef.value[topic]) metricsRef.value[topic].add(message);
})
return {topics,metricsRef};
},
})
app.use(Quasar)
app.mount('#q-app');
</script>
</body>
</html>