-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·220 lines (195 loc) · 6.16 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
<html>
<head>
<!--
Ensure no data are getting cached
!-->
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="CACHE-CONTROL" content="NO-STORE, NO-CACHE, MUST-REVALIDATE, POST-CHECK=0, PRE-CHECK=0" />
<meta http-equiv="EXPIRES" content="01 Jan 1970 00:00:00 GMT" />
<meta http-equiv="Last-Modified" content="01 Jan 1970 00:00:00 GMT" />
<meta http-equiv="If-Modified-Since" content="01 Jan 1970 00:00:00 GMT" />
<title>Lightweight SNMP traffic monitor</title>
<script language="javascript">
//Define main variables
var bandwidth=8388608; // Maximum bandwidth (this will represent 100% in the graph)
var total_bandwidth=0; // The total bandwidth used since page opening
var starting_bandwidth=0; // The initial bandwidth at page opening
var millis=3000; // Refresh interval for Ajax request and Canvas redraw
var divider=millis/1000; // Divider to calculate the speed per second, this allow to change millis without affect bandwidth speed calculation
var inoctet=0; // Storing incoming bandwidth octets
var outoctet=0; // Storing outgoing bandwidth octets
var last_inoctet=0; // Store previous inoctet value to calculate difference with inoctet var
var last_outoctet=0; // Store previous outoctet value to calculate difference with outoctet var
var download_bars=[]; // Array to store download bars drawn in canvas
download_bars.length=40; // Define number of download bars in the graph
var upload_bars=[]; // Array to store upload bars drawn in canvas
upload_bars.length=40; // Define number of upload bars in the graph, must be equal to download_bars.length
var draw_now=false; // This variable is set to false until first bandwidth calculation is available
function loadXMLDoc()
{
var xmlhttp=null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
json_output=xmlhttp.responseText;
snmp_data=JSON.parse(json_output);
last_inoctet=inoctet;
last_outoctet=outoctet;
inoctet=snmp_data.inoctet;
outoctet=snmp_data.outoctet;
time=snmp_data.time;
download=(((inoctet-last_inoctet)/divider)*8);
upload=(((outoctet-last_outoctet)/divider)*8);
if(draw_now){
if(starting_bandwidth==0){
document.getElementById("start_time").innerHTML=time;
starting_bandwidth=parseInt(inoctet)+parseInt(outoctet);
}
draw(download, upload, time);
//document.getElementById("myDiv").innerHTML="<br>"+time+"<hr>Download speed: "+download+"<br>Upload speed: "+upload;
} else {
document.getElementById("myDiv").innerHTML="LOADING";
draw_now=true;
}
}
}
xmlhttp.open("GET","snmp.php",true);
xmlhttp.send(null);
}
function getSNMP(){
loadXMLDoc();
var xmlhttp=null;
}
function draw(download, upload, time){
//Evaluate download display scale (byte/Kbit/KB/Mbit)
download_label=download;
var scale="bit";
//byte
if(download_label>128){
download_label=download_label*0.125;
scale="byte";
}
//Kbit
if(download_label>128){
download_label=download_label*0.0078125;
scale="Kbit";
}
//KB
if(download_label>128){
download_label=download_label*0.125;
scale="KB";
}
//Mbit
if(download_label>128){
download_label=download_label*0.0078125
scale="Mbit";
}
//Format download_label to 2 decimals
download_label=download_label.toFixed(2);
//Calculate download bandwidth % usage
download=download*100/bandwidth;
//Evaluate upload display scale (byte/Kbit/KB/Mbit)
upload_label=upload;
var upload_scale="bit";
//byte
if(upload_label>128){
upload_label=upload_label*0.125;
upload_scale="byte";
}
//Kbit
if(upload_label>128){
upload_label=upload_label*0.0078125;
upload_scale="Kbit";
}
//KB
if(upload_label>128){
upload_label=upload_label*0.125;
upload_scale="KB";
}
//Mbit
if(upload_label>128){
upload_label=upload_label*0.0078125
upload_scale="Mbit";
}
//Format upload_label to 2 decimals
upload_label=upload_label.toFixed(2);
//Calculate download bandwidth % usage
upload=upload*100/bandwidth;
//Calculate total bandwidth
total_bandwidth=total_bandwidth+((parseInt(inoctet)+parseInt(outoctet))-parseInt(starting_bandwidth));
total_bandwidth_label=total_bandwidth.toFixed(2)*0.125+" KB";
document.getElementById("myDiv").innerHTML="DWL: "+download_label+" "+scale+"/s<br>UPL: "+upload_label+" "+upload_scale+"/s";
document.getElementById("time_display").innerHTML=time;
document.getElementById("total_bandwidth").innerHTML=total_bandwidth_label;
for(var i=0; i<download_bars.length; i++){
download_bars[i]=download_bars[i+1];
}
for(var i=0; i<upload_bars.length; i++){
upload_bars[i]=upload_bars[i+1];
}
download_bars[39]=download;
upload_bars[39]=upload;
var to_draw="";
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.clearRect(0, 0, 500, 500);
for(x=0; x<download_bars.length; x++){
ctx.fillStyle="#555555";
if(x==39){
ctx.fillStyle="#00FF00";
}
ctx.fillRect(x*12,200-download_bars[x]*2,11,download_bars[x]*2);
ctx.fillStyle="#888888";
if(x==39){
ctx.fillStyle="#FF0000";
}
ctx.fillRect(x*12,200-((upload_bars[x]*2)+(download_bars[x]*2)),11,upload_bars[x]*2);
}
}
</script>
<style>
html, td {
font-family:arial;
font-size:8px;
}
body {
background-color:white;
color:gray;
}
h1 {
color:gray;
}
_myCanvas {
background-color:black;
}
</style>
</head>
<body>
<h1>Lightweight SNMP traffic monitor</h1>
<div id="myDiv"></div>
<canvas id="myCanvas" width="480" height="200" style="border:1px solid #CCCCCC;background-color:lightyellow;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<table style="width:480">
<tr>
<td width="160px">| 2 minutes</td>
<td width="160px" align="center">| 1 minutes</td>
<td id="time_display" width="160px" align="right">now |</td>
</tr>
</table>
Total bandwidth usage since: <span id="start_time"></span>
<div id="total_bandwidth"></div>
</body>
<script language="javascript">
var int=self.setInterval(function(){getSNMP()}, millis);
</script>
</html>