Project

General

Profile

Download (4.98 KB) Statistics
| Branch: | Tag: | Revision:
1 d2c5fcc1 Scott Ullrich
/*   Most widgets update their backend data every 10 seconds.  11 seconds
2
 *   will ensure that we update the GUI right after the stats are updated.
3
 *   Seconds * 1000 = value
4
 */
5 e54d3461 Joecowboy
var Seconds = 11;
6
var update_interval = (Math.abs(Math.ceil(Seconds))-1)*1000 + 990;
7 92ab0566 Erik Kristensen
8 d2c5fcc1 Scott Ullrich
function updateMeters() {
9 b1678e2d Vinicius Coque
	url = '/getstats.php';
10 01da41cf Bill Marquette
11 b1678e2d Vinicius Coque
	jQuery.ajax(url, {
12
		type: 'get',
13
		success: function(data) {
14
			response = data || "";
15 bae568cc Bill Marquette
			if (response != "")
16 b1678e2d Vinicius Coque
				stats(data);
17 01da41cf Bill Marquette
		}
18
	});
19 e54d3461 Joecowboy
        setTimer();
20
}
21
22
function setTimer() { 
23
         timeout = window.setTimeout('updateMeters()', update_interval); 
24 92ab0566 Erik Kristensen
}
25
26
function stats(x) {
27
	var values = x.split("|");
28 c69c58e2 Vinicius Coque
	if (jQuery.each(values,function(key,value){
29 f8b14770 Bill Marquette
		if (value == 'undefined' || value == null)
30
			return true;
31
		else
32
			return false;
33
	}))
34 e54d3461 Joecowboy
35
        updateUptime(values[2]);
36
        updateDateTime(values[5]);
37
        updateCPU(values[0]);
38
        updateMemory(values[1]);
39
        updateState(values[3]);
40
        updateTemp(values[4]);
41
        updateInterfaceStats(values[6]);
42
        updateInterfaces(values[7]);
43
        updateGatewayStats(values[8]);
44 4dedd18a Cristian Feldman
        updateCpuFreq(values[9]);
45 25a46a3c Cristian Feldman
        updateLoadAverage(values[10]);
46 e4a0be9b jim-p
        updateMbuf(values[11]);
47 f8b00778 jim-p
        updateMbufMeter(values[12]);
48
        updateStateMeter(values[13]);
49 d772ac32 Erik Kristensen
}
50
51 d2c5fcc1 Scott Ullrich
function updateMemory(x) {
52 b1678e2d Vinicius Coque
	if(jQuery('#memusagemeter'))
53 3a94345c jim-p
		jQuery("#memusagemeter").html(x + '%');
54 b1678e2d Vinicius Coque
	if(jQuery('#memwidtha'))
55
		jQuery("#memwidtha").css('width',x + 'px');
56
	if(jQuery('#memwidthb'))
57
		jQuery("#memwidthb").css('width', (100 - x) + 'px');
58 d772ac32 Erik Kristensen
}
59
60 e4a0be9b jim-p
function updateMbuf(x) {
61 f8b00778 jim-p
	if(jQuery('#mbuf'))
62
		jQuery("#mbuf").html(x);
63
}
64
65
function updateMbufMeter(x) {
66 e4a0be9b jim-p
	if(jQuery('#mbufusagemeter'))
67
		jQuery("#mbufusagemeter").html(x + '%');
68
	if(jQuery('#mbufwidtha'))
69
		jQuery("#mbufwidtha").css('width',x + 'px');
70
	if(jQuery('#mbufwidthb'))
71
		jQuery("#mbufwidthb").css('width', (100 - x) + 'px');
72
}
73
74 d2c5fcc1 Scott Ullrich
function updateCPU(x) {
75 b1678e2d Vinicius Coque
	if(jQuery('#cpumeter'))
76 3a94345c jim-p
		jQuery("#cpumeter").html(x + '%');
77 b1678e2d Vinicius Coque
	if(jQuery('#cpuwidtha'))
78
		jQuery("#cpuwidtha").css('width',x + 'px');
79
	if(jQuery('#cpuwidthb'))
80
		jQuery("#cpuwidthb").css('width',(100 - x) + 'px');
81 15c5b5d6 jim-p
	/* Load CPU Graph widget if enabled */
82
	if(widgetActive('cpu_graphs')) {
83
		GraphValue(graph[0], x);
84
	}
85 d772ac32 Erik Kristensen
}
86
87 d2c5fcc1 Scott Ullrich
function updateTemp(x) {
88 e54d3461 Joecowboy
	if(jQuery("#tempmeter"))
89 3a94345c jim-p
		jQuery("#tempmeter").html(x + '\u00B0' + 'C');
90 e54d3461 Joecowboy
        if(jQuery('#tempwidtha'))
91 b1678e2d Vinicius Coque
		jQuery("#tempwidtha").css('width',x + 'px');
92 e54d3461 Joecowboy
        if(jQuery('#tempwidthb'))
93 b1678e2d Vinicius Coque
		jQuery("#tempwidthb").css('width',(100 - x) + 'px');
94 1804023d Bill Marquette
}
95
96 9c0fa9d5 Scott Dale
function updateDateTime(x) {
97 b1678e2d Vinicius Coque
	if(jQuery('#datetime'))
98
		jQuery("#datetime").html(x);
99 9c0fa9d5 Scott Dale
}
100
101 d2c5fcc1 Scott Ullrich
function updateUptime(x) {
102 b1678e2d Vinicius Coque
	if(jQuery('#uptime'))
103 3a94345c jim-p
		jQuery("#uptime").html(x);
104 d772ac32 Erik Kristensen
}
105
106 d2c5fcc1 Scott Ullrich
function updateState(x) {
107 b1678e2d Vinicius Coque
	if(jQuery('#pfstate'))
108 3a94345c jim-p
		jQuery("#pfstate").html(x);
109 d772ac32 Erik Kristensen
}
110
111 bdc3d5ca jim-p
function updateStateMeter(x) {
112
	if(jQuery('#pfstateusagemeter'))
113
		jQuery("#pfstateusagemeter").html(x + '%');
114
	if(jQuery('#pfstatewidtha'))
115
		jQuery("#pfstatewidtha").css('width',x + 'px');
116
	if(jQuery('#pfstatewidthb'))
117
		jQuery("#pfstatewidthb").css('width',(100 - x) + 'px');
118
}
119
120 3dfa6a52 Scott Ullrich
function updateGatewayStats(x){
121
	if (widgetActive("gateways")){
122
		gateways_split = x.split(",");
123 6a71611f jim-p
		for (var y=0; y<gateways_split.length; y++){
124 b1678e2d Vinicius Coque
			if(jQuery('#gateway' + (y + 1))) {
125
				jQuery('#gateway' + (y + 1)).html(gateways_split[y]);
126 98509219 Scott Ullrich
			}
127 3dfa6a52 Scott Ullrich
		}
128
	}
129
}
130
131 4dedd18a Cristian Feldman
function updateCpuFreq(x) {
132
	if(jQuery('#cpufreq'))
133
		jQuery("#cpufreq").html(x);
134
}
135
136 25a46a3c Cristian Feldman
function updateLoadAverage(x) {
137
	if(jQuery('#load_average'))
138
		jQuery("#load_average").html(x);
139
}
140
141 9c0fa9d5 Scott Dale
function updateInterfaceStats(x){
142 34eac803 Scott Dale
	if (widgetActive("interface_statistics")){
143 9c0fa9d5 Scott Dale
		statistics_split = x.split(",");
144
		var counter = 1;
145
		for (var y=0; y<statistics_split.length-1; y++){
146 b1678e2d Vinicius Coque
			if(jQuery('#stat' + counter)) {
147
				jQuery('#stat' + counter).html(statistics_split[y]);
148 98509219 Scott Ullrich
				counter++;	
149
			}
150 9c0fa9d5 Scott Dale
		}
151
	}
152
}
153
154
function updateInterfaces(x){
155 34eac803 Scott Dale
	if (widgetActive("interfaces")){
156 e54d3461 Joecowboy
		interfaces_split = x.split("~");
157
		interfaces_split.each(function(iface){
158 f8b14770 Bill Marquette
			details = iface.split(",");
159
			switch(details[1]) {
160
				case "up":
161 b1678e2d Vinicius Coque
					jQuery('#' + details[0] + '-up').css("display","inline");
162
					jQuery('#' + details[0] + '-down').css("display","none");
163
					jQuery('#' + details[0] + '-block').css("display","none");
164
					jQuery('#' + details[0] + '-ip').html(details[2]);
165
					jQuery('#' + details[0] + '-media').html(details[3]);
166 f8b14770 Bill Marquette
					break;
167
				case "down":
168 b1678e2d Vinicius Coque
					jQuery('#' + details[0] + '-down').css("display","inline");
169
					jQuery('#' + details[0] + '-up').css("display","none");
170
					jQuery('#' + details[0] + '-block').css("display","none");
171
					jQuery('#' + details[0] + '-ip').html(details[2]);
172
					jQuery('#' + details[0] + '-media').html(details[3]);
173 f8b14770 Bill Marquette
					break;
174
				case "block":
175 b1678e2d Vinicius Coque
						jQuery('#' + details[0] + '-block').css("display","inline");
176
						jQuery('#' + details[0] + '-down').css("display","none");
177
						jQuery('#' + details[0] + '-up').css("display","none");
178 f8b14770 Bill Marquette
					break;
179 34eac803 Scott Dale
			}
180 f8b14770 Bill Marquette
		});
181 9c0fa9d5 Scott Dale
	}
182
}
183 670fe849 Scott Ullrich
184 d2c5fcc1 Scott Ullrich
function widgetActive(x) {
185 b1678e2d Vinicius Coque
	var widget = jQuery('#' + x + '-container');
186
	if ((widget != null) && (widget.css('display') != "none"))
187 f9b7608e Scott Dale
		return true;
188 34eac803 Scott Dale
	else
189 f9b7608e Scott Dale
		return false;
190 34eac803 Scott Dale
}
191
192 01da41cf Bill Marquette
/* start updater */
193 b1678e2d Vinicius Coque
jQuery(document).ready(function(){
194 e54d3461 Joecowboy
	setTimer();
195
});