-
Notifications
You must be signed in to change notification settings - Fork 0
/
traffic_metrics.html
87 lines (80 loc) · 2.65 KB
/
traffic_metrics.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
<!-- traffic_metrics.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Traffic Metrics</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<h1>Traffic Metrics</h1>
<div id="trafficHistogram"></div>
<div id="cpuPerformance"></div>
<script>
// Variables to hold the data
var traffic_history = [];
var cpu_history = [];
// Traffic Histogram
function updateTrafficHistogram() {
Plotly.newPlot('trafficHistogram', [{
x: traffic_history,
type: 'histogram',
marker: {
color: 'orange',
},
}], {
title: 'Traffic Histogram',
xaxis: {
title: 'Packet Count',
},
yaxis: {
title: 'Frequency',
},
});
}
// CPU Performance Bar Graph
function updateCpuPerformance() {
var index = Array.from({ length: cpu_history.length }, (_, i) => i);
Plotly.newPlot('cpuPerformance', [{
x: index,
y: cpu_history,
type: 'bar',
marker: {
color: 'purple',
},
}], {
title: 'CPU Performance Over Time',
xaxis: {
title: 'Time',
},
yaxis: {
title: 'CPU Performance (%)',
},
});
}
// Function to fetch data from the server
function fetchData() {
fetch('/update_graphs')
.then(response => response.json())
.then(data => {
// Assuming 'data' contains 'traffic_data' and 'cpu_data' arrays
// Replace with your actual data
traffic_history = data.traffic_data;
cpu_history = data.cpu_data;
// Update graphs
updateTrafficHistogram();
updateCpuPerformance();
})
.catch(error => {
console.error('Error:', error);
});
}
// Initial update
fetchData();
// Update every 5 seconds (adjust as needed)
setInterval(fetchData, 5000);
</script>
</body>
</html>